about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/.eslintrc0
-rw-r--r--src/app.ts126
-rw-r--r--src/http.ts24
-rw-r--r--src/reader.ts397
-rw-r--r--src/worker.ts218
5 files changed, 460 insertions, 305 deletions
diff --git a/src/.eslintrc b/src/.eslintrc
deleted file mode 100644
index e69de29..0000000
--- a/src/.eslintrc
+++ /dev/null
diff --git a/src/app.ts b/src/app.ts
index 03aefd1..e56db0b 100644
--- a/src/app.ts
+++ b/src/app.ts
@@ -9,7 +9,7 @@ class Cookie {
      * @param {string | number | boolean} value
      * @param {number} lifetime
      */
-    static set(name, value, lifetime) {
+    static set(name: any, value: any, lifetime: any) {
         const d = new Date();
         d.setTime(d.getTime() + lifetime * 1000);
         const expires = "expires=" + d.toUTCString();
@@ -19,7 +19,7 @@ class Cookie {
     /**
      * @param {string} name
      */
-    static get(name) {
+    static get(name: any) {
         name = name + "=";
         const ca = document.cookie.split(';');
         for (let i=0; i < ca.length; i++) {
@@ -33,7 +33,7 @@ class Cookie {
     /**
      * @param {string} name
      */
-    static delete(name) {
+    static delete(name: any) {
         const expires = "expires=Thu, 01-Jan-1970 00:00:01 GMT";
         document.cookie = name + "=; " + expires;
     }
@@ -43,7 +43,7 @@ class AppCommon {
     /**
      * @param {string} name
      */
-    urlParam(name){
+    urlParam(name: any){
         try {
             const results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href);
             if (!results) return "";
@@ -69,7 +69,7 @@ class AppCommon {
 
         return new Promise((resolve, reject) => {
             const channel = new MessageChannel();
-            let timeoutId = null;
+            let timeoutId: any = null;
 
             channel.port1.onmessage = (event) => {
                 clearTimeout(timeoutId); // Clean up the timeout
@@ -97,7 +97,7 @@ class AppCommon {
 
         return new Promise((resolve, reject) => {
             const channel = new MessageChannel();
-            let timeoutId = null;
+            let timeoutId: any = null;
 
             channel.port1.onmessage = (event) => {
                 clearTimeout(timeoutId); // Clean up the timeout
@@ -134,9 +134,10 @@ class AppCommon {
     }
 
     /** @param {boolean} is_night */
-    applyNightMode(is_night) {
+    applyNightMode(is_night: any) {
         console.log("night mode changed to", is_night);
 
+        // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
         $("#theme_css").attr("href",
             "lib/bootstrap/v3/css/" + (is_night ? "theme-dark.min.css" : "bootstrap-theme.min.css"));
     }
@@ -146,7 +147,7 @@ class AppCommon {
       *
       * @return {string}
       */
-    escapeHtml(p) {
+    escapeHtml(p: any) {
         if (p === null || p === undefined) {
             return '';
         }
@@ -164,6 +165,7 @@ class AppCommon {
                 '`': '&#x60;'
             };
 
+            // @ts-expect-error TS(7053): Element implicitly has an 'any' type because expre... Remove this comment to see the full error message
             return p.replace(/[&<>"'`/]/g, function(m) { return map[m]; });
         }
     }
@@ -171,7 +173,7 @@ class AppCommon {
 
 /* eslint-disable-next-line no-unused-vars */
 class AppClass extends AppCommon {
-    _dl_progress_timeout;
+    _dl_progress_timeout: any;
 
     /** @type{string} */
     index_mode = "";
@@ -204,25 +206,32 @@ class AppClass extends AppCommon {
 
         // Update navbar active states
         if (this.index_mode === "favorites") {
+            // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
             $(".index_favorites").addClass("active");
+            // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
             $(".download_all_link").show();
+            // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
             $(".logout_link").hide();
         } else {
+            // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
             $(".index_all").addClass("active");
+            // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
             $(".download_all_link").hide();
         }
 
+        // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
         $(".search_query").val(this.index_query);
 
         // Auth check: call backend with a minimal request; 401 means unauthorized
         try {
             const checkParams = new URLSearchParams({op: "list", limit: "1"});
+            // @ts-expect-error TS(2554): Expected 2 arguments, but got 1.
             await Http.get("backend.php?" + checkParams.toString());
             // If we get here without error, we're authenticated
         } catch (e) {
             const err = /** @type {HttpError} */(e);
             // 401 Unauthorized — redirect to login
-            if (err.status === 401) {
+            if ((err as any).status === 401) {
                 window.location.href = "login.php";
                 return;
             }
@@ -234,9 +243,13 @@ class AppClass extends AppCommon {
         Http.setCsrfToken(this.csrf_token);
 
         if (typeof EpubeApp != "undefined") {
+            // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
             $(".navbar").hide();
+            // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
             $(".epube-app-filler").show();
+            // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
             $(".separate-search").show();
+            // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
             $("body").addClass("is-epube-app");
 
             if (this.index_mode == "favorites")
@@ -254,6 +267,7 @@ class AppClass extends AppCommon {
             this.showCovers();
             this.updateOfflinePrompts();
         } else {
+            // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
             $(".container-main")
                 .addClass("alert alert-danger")
                 .html("Service worker support missing in browser (are you using plain HTTP?).");
@@ -261,24 +275,29 @@ class AppClass extends AppCommon {
     }
 
     initCommonEventHandlers() {
+        // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
         $(".remove_all_downloads").on('click', () => {
             this.removeAll();
         });
 
+        // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
         $(".logout_link").on('click', () => {
             this.logout();
         });
 
-        $(".download_all_link").on('click', (e) => {
+        // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
+        $(".download_all_link").on('click', (e: any) => {
             e.preventDefault();
             this.getAll();
         });
 
-        $(".update_link").on('click', (e) => {
+        // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
+        $(".update_link").on('click', (e: any) => {
             e.preventDefault();
             window.location.reload();
         });
 
+        // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
         $(".cosmetic_version").attr('title', this.cosmeticVersion);
 
     }
@@ -295,7 +314,7 @@ class AppClass extends AppCommon {
     /**
      * @param {HTMLElement} elem
      */
-    async showSummary(elem) {
+    async showSummary(elem: any) {
         const bookId = elem.getAttribute("data-book-id");
 
         if (!bookId)
@@ -311,18 +330,24 @@ class AppClass extends AppCommon {
 
             const comment = data.comment ? data.comment : 'No description available';
 
+            // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
             $("#summary-modal .modal-title").text(data.title);
+            // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
             $("#summary-modal .book-summary").html(comment);
 
+            // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
             $("#summary-modal").modal();
 
         } else {
             const data = await localforage.getItem("epube-book." + bookId);
             const comment = data.comment ? data.comment : 'No description available';
 
+            // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
             $("#summary-modal .modal-title").text(data.title);
+            // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
             $("#summary-modal .book-summary").html(comment);
 
+            // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
             $("#summary-modal").modal();
         }
 
@@ -330,10 +355,13 @@ class AppClass extends AppCommon {
     }
 
     showCovers() {
-        $("img[data-book-id]").each((i, elem) => {
+        // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
+        $("img[data-book-id]").each((i: any, elem: any) => {
+            // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
             const e = $(elem);
 
             if (e.attr('data-cover-link')) {
+                // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
                 const img = $("<img>")
                     .on("load", () => {
                         e.css("background-image", "url(" + e.attr('data-cover-link') + ")")
@@ -350,7 +378,8 @@ class AppClass extends AppCommon {
      * @param {HTMLElement} elem
      * @param {boolean} is_fav
      */
-    updateFavoritePrompt(elem, is_fav) {
+    updateFavoritePrompt(elem: any, is_fav: any) {
+        // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
         $(elem)
             .text(is_fav ? "Remove from favorites" : "Add to favorites")
             .attr('data-is-fav', is_fav ? 1 : 0);
@@ -359,7 +388,7 @@ class AppClass extends AppCommon {
     /**
      * @param {HTMLElement} elem
      */
-    async toggleFavorite(elem) {
+    async toggleFavorite(elem: any) {
         const bookId = elem.getAttribute("data-book-id");
 
         if (!bookId)
@@ -373,6 +402,7 @@ class AppClass extends AppCommon {
                     this.updateFavoritePrompt(elem, resp.data.status == "1");
 
                     if (this.index_mode == "favorites" && resp.data.status == 0) {
+                        // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
                         $("#cell-" + bookId).remove();
                     }
                 }
@@ -385,9 +415,11 @@ class AppClass extends AppCommon {
     }
 
     updateOfflinePrompts() {
+        // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
         const elems = $(".offline_dropitem");
 
-        $.each(elems, (i, elem) => {
+        // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
+        $.each(elems, (i: any, elem: any) => {
             this.updateOfflinePrompt(elem);
         });
     }
@@ -395,7 +427,7 @@ class AppClass extends AppCommon {
     /**
      * @param {HTMLElement} elem
      */
-    async updateOfflinePrompt(elem) {
+    async updateOfflinePrompt(elem: any) {
         const bookId = elem.getAttribute("data-book-id");
 
         if (!bookId)
@@ -432,8 +464,11 @@ class AppClass extends AppCommon {
         console.log('cache version, current:', this.cacheVersion, 'worker:', await this.getActiveCacheVersion());
 
         if (typeof EpubeApp != "undefined") {
+            // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
             $(".navbar").hide();
+            // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
             $(".epube-app-filler").show();
+            // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
             $("body").addClass("is-epube-app");
 
             EpubeApp.setPage("PAGE_OFFLINE");
@@ -442,6 +477,7 @@ class AppClass extends AppCommon {
         this.initNightMode();
         this.initCommonEventHandlers();
 
+        // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
         $(".search_query").val(this.urlParam("query"));
 
         this.populateOfflineList();
@@ -451,7 +487,7 @@ class AppClass extends AppCommon {
      * @param {string} bookId
      * @param {Function} callback
      */
-    async get(bookId, callback) {
+    async get(bookId: any, callback: any) {
         console.log("offline cache: " + bookId);
 
         /** @type {HttpResponse} */
@@ -468,22 +504,26 @@ class AppClass extends AppCommon {
 
             const promises = [];
 
+            // @ts-expect-error TS(2554): Expected 2 arguments, but got 1.
             promises.push(Http.blob('backend.php?op=download&id=' + data.epub_id).then((resp) => {
                 console.log(cacheId + ' got book');
                 return localforage.setItem(cacheId + '.book', resp.blob);
             }).catch((e) => console.warn('failed to download book', e)));
 
+            // @ts-expect-error TS(2554): Expected 2 arguments, but got 1.
             promises.push(Http.text("backend.php?op=getpagination&id=" + data.epub_id).then((resp) => {
                 console.log(cacheId + ' got pagination');
                 return localforage.setItem(cacheId + '.locations', JSON.parse(resp.text));
             }).catch((e) => console.warn('failed to download pagination', e)));
 
+            // @ts-expect-error TS(2554): Expected 2 arguments, but got 1.
             promises.push(Http.text("backend.php?op=getlastread&id=" + data.epub_id).then((resp) => {
                 console.log(cacheId + ' got lastread');
                 return localforage.setItem(cacheId + '.lastread', JSON.parse(resp.text));
             }).catch((e) => console.warn('failed to download lastread', e)));
 
             if (data.has_cover) {
+                // @ts-expect-error TS(2554): Expected 2 arguments, but got 1.
                 promises.push(Http.blob("backend.php?op=cover&id=" + bookId).then((resp) => {
                     console.log(cacheId + ' got cover');
                     return localforage.setItem(cacheId + '.cover', resp.blob);
@@ -495,6 +535,7 @@ class AppClass extends AppCommon {
 
             callback();
 
+            // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
             $(".dl-progress")
                 .show()
                 .html("Finished downloading <b>" + this.escapeHtml(data.title) + "</b>");
@@ -502,6 +543,7 @@ class AppClass extends AppCommon {
             window.clearTimeout(this._dl_progress_timeout);
 
             this._dl_progress_timeout = window.setTimeout(() => {
+                // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
                 $(".dl-progress").fadeOut();
             }, 5*1000);
         }
@@ -510,14 +552,17 @@ class AppClass extends AppCommon {
     getAll() {
         if (confirm("Download all books on this page?")) {
 
-            $(".row > div").each((i, row) => {
+            // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
+            $(".row > div").each((i: any, row: any) => {
+                // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
                 const bookId = ($(row).attr("id") ?? "").replace("cell-", "");
+                // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
                 const dropitem = $(row).find(".offline_dropitem")[0] ?? null;
 
                 if (bookId) {
                     const cacheId = 'epube-book.' + bookId;
 
-                    localforage.getItem(cacheId).then((book) => {
+                    localforage.getItem(cacheId).then((book: any) => {
                         if (!book) {
                             this.get(bookId, () => {
                                 this.updateOfflinePrompt(dropitem);
@@ -532,23 +577,24 @@ class AppClass extends AppCommon {
     /**
      * @param {HTMLElement} elem
      */
-    removeFromList(elem) {
+    removeFromList(elem: any) {
         const bookId = elem.getAttribute("data-book-id");
 
         this.remove(bookId, () => {
+            // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
             $("#cell-" + bookId).remove();
         });
     }
 
-    remove(id, callback) {
+    remove(id: any, callback: any) {
         if (confirm("Remove download?")) {
 
             const cacheId = "epube-book." + id;
-            const promises = [];
+            const promises: any = [];
 
             console.log("offline remove: " + id);
 
-            localforage.iterate(function(value, key /*, i */) {
+            localforage.iterate(function(value: any, key: any /*, i */) {
                 if (key.match(cacheId)) {
                     promises.push(localforage.removeItem(key));
                 }
@@ -577,10 +623,11 @@ class AppClass extends AppCommon {
         /** @type {HttpResponse} */
         let resp;
         try {
+            // @ts-expect-error TS(2554): Expected 2 arguments, but got 1.
             resp = await Http.get("backend.php?" + params.toString());
         } catch (e) {
             const err = /** @type {HttpError} */(e);
-            if (err.status === 401) {
+            if ((err as any).status === 401) {
                 window.location.href = "login.php";
             }
             return;
@@ -588,13 +635,14 @@ class AppClass extends AppCommon {
 
         /** @type{BookList} */
         const data = resp.data;
+        // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
         const books = $("#books_container");
         books.html("");
 
         if (data) {
-            data.books.forEach((book) => {
+            data.books.forEach((book: any) => {
                 const download_html = book.download_formats
-                    .map((fmt) => {
+                    .map((fmt: any) => {
                         const label_class = fmt.format === "EPUB" ? "label-success" : "label-primary";
                         return `<li><a target="_blank" href="backend.php?op=download&id=${fmt.id}">Download: <span class="label ${label_class}">${fmt.format}</span></a></li>`;
                     })
@@ -630,9 +678,12 @@ class AppClass extends AppCommon {
     /**
      * @param {BookList} data
      */
-    updateIndexPagination(data) {
+    updateIndexPagination(data: any) {
+        // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
         const prevLi = $(".pager .previous");
+        // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
         const nextLi = $(".pager .next");
+        // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
         const pagerInfo = $(".pager .pager-info");
 
         const prevParams = new URLSearchParams({
@@ -679,7 +730,7 @@ class AppClass extends AppCommon {
      * @param {String} [opts.authorUrl] - Search by author override
      * @returns {JQuery<HTMLElement>} The created cell element.
      */
-    renderBookCell(book, opts) {
+    renderBookCell(book: any, opts: any) {
         //console.log('renderBookCell', book, opts);
 
         const cellThumbClass = book.is_read ? "read" : "";
@@ -705,6 +756,7 @@ class AppClass extends AppCommon {
                 ${this.escapeHtml(book.series_name) + " [" + book.series_index + "]"}
             </a></div>` : '';
 
+        // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
         const cell = $(`<div class="col-xxs-6 col-xs-3 col-sm-3 col-md-2" id="cell-${book.id}">
             ${isOpenable ?
                 `<a class="thumbnail ${cellThumbClass}" href="${readUrl}">` :
@@ -726,18 +778,18 @@ class AppClass extends AppCommon {
             </div>
         </div>`);
 
-        cell.find('.summary_link').on('click', (evt) => {
+        cell.find('.summary_link').on('click', (evt: any) => {
             evt.preventDefault();
             this.showSummary(evt.currentTarget);
         });
 
-        cell.find('.fav_item').on('click', (evt) => {
+        cell.find('.fav_item').on('click', (evt: any) => {
             evt.preventDefault();
             this.toggleFavorite(evt.currentTarget);
         });
 
         // specific to offline index
-        cell.find('.remove_offline_data').on('click', (evt) => {
+        cell.find('.remove_offline_data').on('click', (evt: any) => {
             evt.preventDefault();
             this.removeFromList(evt.currentTarget);
         });
@@ -746,6 +798,7 @@ class AppClass extends AppCommon {
     }
 
     async search() {
+        // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
         const query = $(".search_query").val();
 
         await localforage.setItem("epube.search-query", query);
@@ -758,9 +811,9 @@ class AppClass extends AppCommon {
     async removeAll() {
         if (confirm("Remove all downloaded books?")) {
 
-            const promises = [];
+            const promises: any = [];
 
-            localforage.iterate(function(value, key/*, i*/) {
+            localforage.iterate(function(value: any, key: any/*, i*/) {
                 if (key.match("epube-book")) {
                     promises.push(localforage.removeItem(key));
                 }
@@ -776,10 +829,11 @@ class AppClass extends AppCommon {
         let query = this.urlParam("query");
         if (query) query = String(query).toLowerCase();
 
+        // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
         const books = $("#books_container");
         books.html("");
 
-        localforage.iterate((value, key) => {
+        localforage.iterate((value: any, key: any) => {
             if (key.match(/epube-book\.\d{1,}$/)) {
 
                 Promise.all([
diff --git a/src/http.ts b/src/http.ts
index e66888c..2474eb5 100644
--- a/src/http.ts
+++ b/src/http.ts
@@ -23,7 +23,7 @@ class Http {
      * Set the CSRF token for subsequent requests.
      * @param {string} token
      */
-    static setCsrfToken(token) {
+    static setCsrfToken(token: any) {
         Http._csrfToken = token;
     }
 
@@ -34,7 +34,7 @@ class Http {
      * @param {Record<string, string> | null | undefined} params
      * @returns {string}
      */
-    static _appendParams(url, params) {
+    static _appendParams(url: any, params: any) {
         if (!params || Object.keys(params).length === 0) return url;
         const separator = url.includes('?') ? '&' : '?';
         const query = new URLSearchParams(params).toString();
@@ -47,15 +47,15 @@ class Http {
      * @param {Response} resp
      * @returns {never}
      */
-    static _throwHttpError(resp) {
+    static _throwHttpError(resp: any) {
         /** @type {HttpError} */
         const err = new Error(`HTTP ${resp.status}: ${resp.statusText}`);
-        err.status = resp.status;
-        err.responseText = '';
+        (err as any).status = resp.status;
+        (err as any).responseText = '';
         // Read error body asynchronously — don't block the throw
-        resp.text().then((t) => { err.responseText = t; }).catch(() => {
-            /* ignore */
-        });
+resp.text().then((t: any) => { (err as any).responseText = t; }).catch(() => {
+    /* ignore */
+});
         throw err;
     }
 
@@ -65,7 +65,7 @@ class Http {
      * @param {Record<string, string> | null} [params] - optional query parameters
      * @returns {Promise<HttpResponse>}
      */
-    static async get(url, params) {
+    static async get(url: any, params: any) {
         const urlWithParams = Http._appendParams(url, params);
         const resp = await fetch(urlWithParams, {
             method: 'GET',
@@ -86,7 +86,7 @@ class Http {
      * @param {Record<string, string>} body
      * @returns {Promise<HttpResponse>}
      */
-    static async post(url, body) {
+    static async post(url: any, body: any) {
         const params = new URLSearchParams(body);
         if (Http._csrfToken) {
             params.append('csrf_token', Http._csrfToken);
@@ -112,7 +112,7 @@ class Http {
      * @param {Record<string, string> | null} [params] - optional query parameters
      * @returns {Promise<HttpBlobResponse>}
      */
-    static async blob(url, params) {
+    static async blob(url: any, params: any) {
         const urlWithParams = Http._appendParams(url, params);
         const resp = await fetch(urlWithParams, {
             method: 'GET',
@@ -133,7 +133,7 @@ class Http {
      * @param {Record<string, string> | null} [params] - optional query parameters
      * @returns {Promise<HttpTextResponse>}
      */
-    static async text(url, params) {
+    static async text(url: any, params: any) {
         const urlWithParams = Http._appendParams(url, params);
         const resp = await fetch(urlWithParams, {
             method: 'GET',
diff --git a/src/reader.ts b/src/reader.ts
index a3b81b7..8b7cdb3 100644
--- a/src/reader.ts
+++ b/src/reader.ts
@@ -12,6 +12,8 @@ const PAGE_RESET_PROGRESS = -1;
 
 /* eslint-disable-next-line no-unused-vars */
 class ReaderClass extends AppCommon {
+    _flattened_toc: any;
+    loader: any;
     csrf_token = "";
 
     last_stored_cfi = "";
@@ -22,9 +24,9 @@ class ReaderClass extends AppCommon {
 
     hyphenate = {};
 
-    _prevent_lastread_timeout;
+    _prevent_lastread_timeout: any;
 
-    _prevent_lastread;
+    _prevent_lastread: any;
 
     cacheVersion = BUILD_CACHE_VERSION;
 
@@ -54,11 +56,12 @@ class ReaderClass extends AppCommon {
     constructor() {
         super();
 
+        // @ts-expect-error TS(2304): Cannot find name 'ePub'.
         this.book = new ePub.Book();
         this.loader = new ReaderLoader();
     }
 
-    onTouchStart(evt) {
+    onTouchStart(evt: any) {
         const touch = evt.touches[0] || evt.changedTouches[0];
 
         this._swipeState = {
@@ -66,11 +69,12 @@ class ReaderClass extends AppCommon {
             startX: touch.clientX,
             startY: touch.clientY,
             startTime: Date.now(),
+            // @ts-expect-error TS(2322): Type 'string' is not assignable to type 'null'.
             direction: evt.target.id == "right" ? 'left' : 'right',
         };
     }
 
-    onTouchEnd(evt) {
+    onTouchEnd(evt: any) {
         if (!this._swipeState.active) return;
 
         const touch = evt.changedTouches[0] || evt.changedTouches[evt.changedTouches.length - 1];
@@ -96,7 +100,7 @@ class ReaderClass extends AppCommon {
         }
     }
 
-    onTouchMove(evt) {
+    onTouchMove(evt: any) {
         if (!this._swipeState.active) return;
 
         const touch = evt.touches[0] || evt.changedTouches[0];
@@ -116,39 +120,48 @@ class ReaderClass extends AppCommon {
 
         Http.setCsrfToken(this.csrf_token);
 
-        $(document).on("keyup", (e) => {
+        // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
+        $(document).on("keyup", (e: any) => {
             this.hotkeyHandler(e);
         });
 
+        // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
         $(".close_book").on("click", () => {
             this.close();
         });
 
+        // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
         $("#left").on("mouseup", () => {
             this.prevPage();
         });
 
+        // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
         $(".search_input").on("change", () => {
             this.search();
         });
 
-        $(".prev_location_btn").on("click", (evt) => {
+        // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
+        $(".prev_location_btn").on("click", (evt: any) => {
             this.openPrevious(evt.target);
         });
 
+        // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
         $("#right").on("mouseup", () => {
             this.nextPage();
         });
 
-        $("#left, #right").on("touchstart", (evt) => {
+        // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
+        $("#left, #right").on("touchstart", (evt: any) => {
             this.onTouchStart(evt);
         });
 
-        $("#left, #right").on("touchmove", (evt) => {
+        // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
+        $("#left, #right").on("touchmove", (evt: any) => {
             this.onTouchMove(evt);
         });
 
-        $("#left, #right").on("touchend", (evt) => {
+        // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
+        $("#left, #right").on("touchend", (evt: any) => {
             this.onTouchEnd(evt);
         });
 
@@ -161,6 +174,7 @@ class ReaderClass extends AppCommon {
         } else {
             this.applyTheme();
 
+            // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
             $(".loading-message").text('Resource loader failed to initialize.');
         }
     }
@@ -174,7 +188,7 @@ class ReaderClass extends AppCommon {
     /**
      * @param {boolean} offline
      */
-    async onOfflineModeChanged(offline) {
+    async onOfflineModeChanged(offline: any) {
         console.log('onOfflineModeChanged', offline);
 
         if (!offline && this.book) {
@@ -188,7 +202,7 @@ class ReaderClass extends AppCommon {
                     cfi: currentCfi, timestamp: String(new Date().getTime()) });
             } catch (e) {
                 const err = /** @type {HttpError} */(e);
-                if (err.status == 401) {
+                if ((err as any).status == 401) {
                     window.location.href = "index.html";
                 }
             }
@@ -200,10 +214,12 @@ class ReaderClass extends AppCommon {
         if (typeof EpubeApp != "undefined") {
             EpubeApp.setPage("PAGE_READER");
         } else {
+            // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
             $(window).on('online', () => {
                 this.onOfflineModeChanged(false);
             });
 
+            // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
             $(window).on('offline', () => {
                 this.onOfflineModeChanged(true);
             });
@@ -211,6 +227,7 @@ class ReaderClass extends AppCommon {
 
         this.applyTheme();
 
+        // @ts-expect-error TS(2554): Expected 1 arguments, but got 0.
         const bookinfo = await localforage.getItem(this.cacheId());
 
         if (!bookinfo) {
@@ -232,6 +249,7 @@ class ReaderClass extends AppCommon {
                     await localforage.setItem(this.cacheId('cover'), cover.blob);
                 }
 
+                // @ts-expect-error TS(2554): Expected 1 arguments, but got 0.
                 await localforage.setItem(this.cacheId(), info);
 
                 console.log('bookinfo saved');
@@ -242,7 +260,8 @@ class ReaderClass extends AppCommon {
 
                 console.error(err);
 
-                $(".loading-message").html(`Unable to load book info.<br/><small>${this.escapeHtml((String)(err.responseText))}</small>`);
+                // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
+                $(".loading-message").html(`Unable to load book info.<br/><small>${this.escapeHtml((String)((err as any).responseText))}</small>`);
                 return;
             }
         }
@@ -254,6 +273,7 @@ class ReaderClass extends AppCommon {
         if (!book_data) {
             console.log("local data not found, loading from network...");
 
+            // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
             $(".loading-message").html("Downloading book…");
 
             /** @type {HttpBlobResponse} */
@@ -266,6 +286,7 @@ class ReaderClass extends AppCommon {
                 console.log('saved local data for book');
 
             } else {
+                // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
                 $(".loading-message").html(`Unable to download book: ${book_resp.status}`);
                 return;
             }
@@ -279,25 +300,28 @@ class ReaderClass extends AppCommon {
                 _reader.openBookData(this.result);
             } catch (e) {
                 console.error(e);
+                // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
                 $(".loading-message").html("Unable to load book blob: " + e);
             }
         };
 
         fileReader.onerror = (e) => {
             console.log('filereader error', e);
+            // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
             $(".loading-message").html("Unable to open book.<br/><small>" + this.escapeHtml(String(e)) + "</small>");
         };
 
         fileReader.readAsArrayBuffer(book_data);
     }
 
-    async openBookData(book_data) {
+    async openBookData(book_data: any) {
         //this.book = new ePub.Book();
 
         try {
             await this.book.open(book_data);
         } catch (e) {
             console.error(e);
+            // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
             $(".loading-message").html(`Unable to open book.<br/><small>${this.escapeHtml(e instanceof Error ? e.message : String(e))}</small>`);
             return;
         }
@@ -316,6 +340,7 @@ class ReaderClass extends AppCommon {
             minSpreadWidth: 961
         });
 
+        // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
         $(".location").on('click', async () => {
             const current = Math.floor(rendition.currentLocation().start.location / LOCATION_DIVISOR);
             const total = Math.floor(this.book.locations.length() / LOCATION_DIVISOR);
@@ -330,8 +355,10 @@ class ReaderClass extends AppCommon {
 
         if (enable_hyphens) {
             /* global hyphenationPatternsEnUs, hyphenationPatternsRu, createHyphenator */
-            this.hyphenate.en = createHyphenator(hyphenationPatternsEnUs, { html: true });
-            this.hyphenate.ru = createHyphenator(hyphenationPatternsRu, { html: true });
+// @ts-expect-error TS(2304): Cannot find name 'createHyphenator'.
+(this.hyphenate as any).en = createHyphenator(hyphenationPatternsEnUs, { html: true });
+            // @ts-expect-error TS(2304): Cannot find name 'createHyphenator'.
+            (this.hyphenate as any).ru = createHyphenator(hyphenationPatternsRu, { html: true });
         }
 
         this.initRenditionHooks(this.book, rendition);
@@ -349,7 +376,8 @@ class ReaderClass extends AppCommon {
     /**
      * @param {ePub.Book} book
      */
-    async showBookInfo(book) {
+    async showBookInfo(book: any) {
+        // @ts-expect-error TS(2554): Expected 1 arguments, but got 0.
         const bookinfo = await localforage.getItem(this.cacheId());
 
         let title;
@@ -367,6 +395,7 @@ class ReaderClass extends AppCommon {
 
         document.title = title + " – " + author + " – The Epube";
 
+        // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
         $(".title")
             .text(title)
             .attr("title", title + " – " + author);
@@ -380,7 +409,7 @@ class ReaderClass extends AppCommon {
     /**
      * @param {ePub.Book} book
      */
-    async loadLocations(book) {
+    async loadLocations(book: any) {
         let locations = await localforage.getItem(this.cacheId("locations"));
 
         // legacy format is array of objects {cfi: ..., page: ...}
@@ -397,6 +426,7 @@ class ReaderClass extends AppCommon {
         if (this.isOnline()) {
             console.log("downloading locations...");
 
+            // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
             $(".loading-message").html("Downloading locations…");
 
             try {
@@ -429,11 +459,12 @@ class ReaderClass extends AppCommon {
             }
         }
 
+        // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
         $(".loading-message").html("Preparing locations…");
 
         let generate_queue_max = 0;
 
-        locations = await book.locations.generate(100, (queue) => {
+        locations = await book.locations.generate(100, (queue: any) => {
             if (!generate_queue_max)
                 generate_queue_max = queue.length();
 
@@ -441,6 +472,7 @@ class ReaderClass extends AppCommon {
             if (generate_queue_max > 0) {
                 const queue_pct = Math.round((1 - queue.length() / generate_queue_max) * 100); // TODO un-wtf
 
+                // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
                 $(".loading-message").html(`Preparing locations (${queue_pct}%)…`);
             }
         });
@@ -459,21 +491,22 @@ class ReaderClass extends AppCommon {
      * @param {ePub.Book} book
      * @param {ePub.Rendition} rendition
      */
-    initRenditionHooks(book, rendition) {
+    initRenditionHooks(book: any, rendition: any) {
         console.log('initRenditionHooks');
 
-        book.spine.hooks.content.register((doc/*, section */) => {
+        book.spine.hooks.content.register((doc: any/*, section */) => {
             this.cleanupEmbeddedStyles(doc);
         });
 
-        rendition.hooks.content.register(async (contents) => {
+        rendition.hooks.content.register(async (contents: any) => {
 
-            contents.on("linkClicked", (href) => {
+            contents.on("linkClicked", (href: any) => {
                 console.log('linkClicked', href);
 
                 this.blockLastReadUpdate();
 
                 if (href.indexOf("://") == -1) {
+                    // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
                     $(".prev_location_btn")
                         .attr("data-location-cfi", rendition.currentLocation().start.cfi)
                         .show();
@@ -484,7 +517,7 @@ class ReaderClass extends AppCommon {
                 }
             });
 
-            contents.on("selected", async (cfiRange) => {
+            contents.on("selected", async (cfiRange: any) => {
                 if (this.isOnline()) {
                     const range = await book.getRange(cfiRange);
 
@@ -493,6 +526,7 @@ class ReaderClass extends AppCommon {
                     console.log('selected', cfiRange, selection);
 
                     if (selection.match(/^[\w­]+$/)) {
+                        // @ts-expect-error TS(2554): Expected 3 arguments, but got 2.
                         this.lookupWord(selection, () => {
                             if (typeof EpubeApp != "undefined")
                                 EpubeApp.showActionBar(false);
@@ -510,24 +544,31 @@ class ReaderClass extends AppCommon {
             const match = window.location.href.match(/^.*\//);
             const base_url = match ? match[0] : window.location.href;
 
+            // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
             $(contents.document.head)
+                // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
                 .append($("<style type='text/css'>")
                     .text(this.generateFontsCss(base_url)));
 
+            // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
             $(contents.document.head)
+                // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
                 .append($("<style type='text/css'>")
                     .text(this.loader._res_data[base_url + 'dist/reader_iframe.min.css']));
 
-            const theme = await localforage.getItem("epube.theme") || 'default';
+            const theme = (await localforage.getItem("epube.theme")) || 'default';
 
+            // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
             $(contents.document).find("body")
                 .attr("class", typeof EpubeApp != "undefined" ? "is-epube-app" : "")
                 .addClass("theme-" + theme);
 
             console.log('contents', contents);
 
-            $(contents.window).on("click tap", (evt) => {
+            // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
+            $(contents.window).on("click tap", (evt: any) => {
                 if (evt.button == 0) {
+                    // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
                     if ($(".modal").is(":visible"))
                         return;
 
@@ -538,7 +579,8 @@ class ReaderClass extends AppCommon {
                 }
             });
 
-            $(contents.window).on("wheel", async (evt) => {
+            // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
+            $(contents.window).on("wheel", async (evt: any) => {
                 if (await localforage.getItem("epube.enable-wheel")) {
                     if ((evt.originalEvent?.deltaY ?? 0) > 0) {
                         this.nextPage();
@@ -549,7 +591,7 @@ class ReaderClass extends AppCommon {
             });
         });
 
-        rendition.on("keyup", (e) => {
+        rendition.on("keyup", (e: any) => {
             this.hotkeyHandler(e);
         });
 
@@ -560,81 +602,80 @@ class ReaderClass extends AppCommon {
             this.open_last_read_when_displayed = true;
         });
 
-        rendition.on('rendered', async (/* section */) => {
-            console.log('rendition rendered');
-
-            this.applyTheme();
-            this.resizeSideColumns();
-
-            try {
-                const location = rendition.currentLocation();
-
-                if (location.start) {
-                    const cur_href = book.canonical(location.start.href);
-                    let toc_entry = {};
-
-                    $.each(this.flattenToc(book), function(i, r) {
-
-                        if (book.spine.get(r.href).canonical == cur_href) {
-                            toc_entry = r;
-                            return;
-                        }
-                    });
-
-                    if (toc_entry && toc_entry.label)
-                        $(".chapter_title").text(this.escapeHtml(toc_entry.label.trim()) + " | ");
-
-                    this.generateTocBar(book, this.flattenToc(book));
+        rendition.on('rendered', async ( /* section */) => {
+    console.log('rendition rendered');
+    this.applyTheme();
+    this.resizeSideColumns();
+    try {
+        const location = rendition.currentLocation();
+        if (location.start) {
+            const cur_href = book.canonical(location.start.href);
+            let toc_entry = {};
+            // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
+            $.each(this.flattenToc(book), function (i: any, r: any) {
+                if (book.spine.get(r.href).canonical == cur_href) {
+                    toc_entry = r;
+                    return;
                 }
-
-            } catch (e) {
-                console.warn(e);
-            }
-
-            if (this.open_last_read_when_displayed) {
-                this.open_last_read_when_displayed = false;
-
-                await this.openLastRead();
-            }
-        });
+            });
+            if (toc_entry && (toc_entry as any).label)
+                // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
+                $(".chapter_title").text(this.escapeHtml((toc_entry as any).label.trim()) + " | ");
+            this.generateTocBar(book, this.flattenToc(book));
+        }
+    }
+    catch (e) {
+        console.warn(e);
+    }
+    if (this.open_last_read_when_displayed) {
+        this.open_last_read_when_displayed = false;
+        await this.openLastRead();
+    }
+});
 
         // this seems to be called a lot more than rendered
         rendition.on('displayed', function(/*chapter*/) {
             console.log('rendition displayed');
         });
 
-        rendition.on('relocated', (/** @type {ePub.Location} */ location) => this.onRelocated(book, location));
+        rendition.on('relocated', (/** @type {ePub.Location} */ location: any) => this.onRelocated(book, location));
     }
 
     initModals() {
+        // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
         $('#settings-modal').on('shown.bs.modal', async () => {
 
             const last_read = await localforage.getItem(this.cacheId("lastread"));
 
             if (last_read && last_read.cfi) {
+                // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
                 $(".lastread_input")
                     .val(last_read.page + '%')
                     .attr('title', `[local] ${last_read.cfi}`);
             }
 
+            // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
             $(".clear_last_read")
                 .off("click")
                 .on("click", () => {
                     this.clearLastRead();
                 });
 
+            // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
             $(".open_last_read")
                 .off("click")
                 .on("click", () => {
                     this.openLastRead();
                 });
 
+            // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
             $(".mark_as_read")
                 .off("click")
                 .on("click", () => {
                     this.markAsRead();
                 });
 
+            // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
             $(".reset_locations")
                 .off("click")
                 .on("click", () => {
@@ -645,6 +686,7 @@ class ReaderClass extends AppCommon {
                 try {
                     /** @type {HttpResponse} */
                     const lrResp = await Http.get("backend.php", { op: "getlastread", id: this.urlParam("id") });
+                    // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
                     $(".lastread_input")
                         .val(lrResp.data.page + '%')
                         .attr('title', `[remote] ${lrResp.data.cfi}`);
@@ -653,34 +695,39 @@ class ReaderClass extends AppCommon {
                 }
             }
 
+            // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
             $(".font_family")
                 .off("change")
-                .on("change", (evt) => {
+                .on("change", (evt: any) => {
                     this.onFontChanged(evt.target);
                 });
 
+            // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
             $(".font_size")
                 .off("change")
-                .on("change", (evt) => {
+                .on("change", (evt: any) => {
                     this.onTextSizeChanged(evt.target);
                 });
 
+            // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
             $(".line_height")
                 .off("change")
-                .on("change", (evt) => {
+                .on("change", (evt: any) => {
                     this.onLineHeightChanged(evt.target);
                 });
 
+            // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
             $(".theme_name")
                 .off("change")
-                .on("change", (evt) => {
+                .on("change", (evt: any) => {
                     this.onThemeChanged(evt.target);
                 });
 
+            // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
             $(".enable_hyphens_checkbox")
                 .attr("checked", await localforage.getItem("epube.enable-hyphens"))
                 .off("click")
-                .on("click", (evt) => {
+                .on("click", (evt: any) => {
                     localforage.setItem("epube.enable-hyphens", evt.target.checked);
 
                     if (confirm("Toggling hyphens requires page reload. Reload now?")) {
@@ -688,67 +735,83 @@ class ReaderClass extends AppCommon {
                     }
                 });
 
+            // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
             $(".enable_wheel_checkbox")
                 .attr("checked", await localforage.getItem("epube.enable-wheel"))
                 .off("click")
-                .on("click", (evt) => {
+                .on("click", (evt: any) => {
                     localforage.setItem("epube.enable-wheel", evt.target.checked);
                 });
 
             if (typeof EpubeApp != "undefined") {
+                // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
                 $(".keep_ui_checkbox").parent().parent().hide();
             } else {
+                // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
                 $(".keep_ui_checkbox")
                 .attr("checked", await localforage.getItem("epube.keep-ui-visible"))
                 .off("click")
-                .on("click", (evt) => {
+                .on("click", (evt: any) => {
                     localforage.setItem("epube.keep-ui-visible", evt.target.checked);
                 });
             }
 
+            // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
             $(".last-mod-timestamp").html(`${this.cosmeticVersion} &mdash; ${this.cacheVersion}
                 (${this.isOnline() ? `<span class='text-success'>Online</span>` : `<span class='text-danger'>Offline</span>`})
                 `);
 
-            $(".font_family").val(await localforage.getItem("epube.fontFamily") || DEFAULT_FONT_FAMILY);
-            $(".theme_name").val(await localforage.getItem("epube.theme") || 'default');
+            // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
+            $(".font_family").val((await localforage.getItem("epube.fontFamily")) || DEFAULT_FONT_FAMILY);
+            // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
+            $(".theme_name").val((await localforage.getItem("epube.theme")) || 'default');
 
+            // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
             const zoom = $(".font_size").html("");
 
             for (let i = 10; i <= 32; i++) {
+                // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
                 const opt = $("<option>").val(i).html(i + " px");
                 zoom.append(opt);
             }
 
-            zoom.val(await localforage.getItem("epube.fontSize") || DEFAULT_FONT_SIZE);
+            zoom.val((await localforage.getItem("epube.fontSize")) || DEFAULT_FONT_SIZE);
 
+            // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
             const line_height = $(".line_height").html("");
 
             for (let i = 100; i <= 220; i += 10) {
+                // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
                 const opt = $("<option>").val(i).html(i + "%");
                 line_height.append(opt);
             }
 
-            line_height.val(await localforage.getItem("epube.lineHeight") || DEFAULT_LINE_HEIGHT);
+            line_height.val((await localforage.getItem("epube.lineHeight")) || DEFAULT_LINE_HEIGHT);
 
         });
 
+        // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
         $('#dict-modal').on('shown.bs.modal', () => {
+            // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
             $(".dict_query")
                 .off("keyup")
-                .on("keyup", (evt) => {
+                .on("keyup", (evt: any) => {
                     if (evt.which === 13) {
                         evt.preventDefault();
                         this.lookupWord(null, null, '.dict_query');
                     }
                 });
 
+            // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
             $(".dict_result").scrollTop(0);
         });
 
         // TODO: make configurable
+        // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
         $(".dict_search_btn").on("click", function() {
+            // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
             $("#dict-modal").modal('hide');
+            // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
             window.open("https://duckduckgo.com/?q=" + $(".dict_query").val());
         });
 
@@ -757,14 +820,14 @@ class ReaderClass extends AppCommon {
     /**
      * @param {ePub.Book} book
      */
-    initToc(book) {
+    initToc(book: any) {
         const _reader = this;
 
-        function toc_loc_msg(href) {
+        function toc_loc_msg(href: any) {
             try {
                 const cfiBase = book.spine.get(href).cfiBase;
 
-                const loc = book.locations._locations.find(function(k) {
+                const loc = book.locations._locations.find(function(k: any) {
                     return k.indexOf(cfiBase) != -1
                 });
 
@@ -783,16 +846,19 @@ class ReaderClass extends AppCommon {
          * @param {JQuery<HTMLElement>} list
          * @param {number} nest
          */
-        function process_toc_sublist(row, list, nest) {
+        function process_toc_sublist(row: any, list: any, nest: any) {
 
             if (nest == 3) return false;
 
             if (row.subitems) {
 
+                // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
                 const sublist = $("<ul class='toc_sublist list-unstyled'>");
 
-                $.each(row.subitems, function(i, row) {
+                // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
+                $.each(row.subitems, function(i: any, row: any) {
 
+                    // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
                     const a = $("<a>")
                         .attr('href', '#')
                         .html("<b class='pull-right'>" + toc_loc_msg(row.href) + "</b>" + _reader.escapeHtml(row.label))
@@ -801,6 +867,7 @@ class ReaderClass extends AppCommon {
                             book.rendition.display(a.attr('data-href'));
                         });
 
+                    // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
                     sublist.append($("<li>").append(a));
 
                     process_toc_sublist(row, sublist, nest + 1);
@@ -811,17 +878,21 @@ class ReaderClass extends AppCommon {
             }
         }
 
+        // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
         $('#toc-modal').on('shown.bs.modal', function() {
 
             const toc = book.navigation.toc;
 
+            // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
             const list = $(".toc_list");
             list.html("");
 
-            $.each(toc, function(i, row) {
+            // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
+            $.each(toc, function(i: any, row: any) {
 
                 // if anything fails here the toc entry is likely useless anyway (i.e. no cfi)
                 try {
+                    // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
                     const a = $("<a>")
                         .attr('href', '#')
                         .html("<b class='pull-right'>" + toc_loc_msg(row.href) + "</b>" + _reader.escapeHtml(row.label))
@@ -830,6 +901,7 @@ class ReaderClass extends AppCommon {
                             book.rendition.display(a.attr('data-href'));
                         });
 
+                    // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
                     list.append($("<li>").append(a));
 
                     process_toc_sublist(row, list, 0);
@@ -844,18 +916,20 @@ class ReaderClass extends AppCommon {
 
                 list.html("");
 
-                $.each(book.spine.items, function (i, row) {
+                // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
+                $.each(book.spine.items, function (i: any, row: any) {
 
+                    // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
                     const a = $("<a>")
                         .attr('href', '#')
                         .attr('title', row.url)
-                        // @ts-ignore
                         .html(`Section ${i+1}`)
                         .attr('data-href', row.href)
                         .on('click', () => {
                             book.rendition.display(a.attr('data-href'));
                         });
 
+                    // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
                     list.append($("<li>").append(a));
 
                 });
@@ -868,18 +942,22 @@ class ReaderClass extends AppCommon {
     /**
      * @param {Document} doc
      */
-    cleanupEmbeddedStyles(doc) {
+    cleanupEmbeddedStyles(doc: any) {
+        // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
         $(doc).find("p")
-                // @ts-ignore
-                .filter((i, e) => (($(e).text().length >= MIN_LENGTH_TO_JUSTIFY) ? e : null))
+                // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
+                .filter((i: any, e: any) => (($(e).text().length >= MIN_LENGTH_TO_JUSTIFY) ? e : null))
                     .css("text-align", "justify");
 
+        // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
         $(doc).find("html")
                 .attr("class", "");
 
+        // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
         $(doc).find("pre")
                 .css("white-space", "pre-wrap");
 
+        // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
         $(doc).find("a, p, span, em, i, strong, b, body, header, section, div, big, small, table, tr, td, th, ul, ol, li")
                 .attr("class", "")
                 .css("font-family", "inherit")
@@ -893,6 +971,7 @@ class ReaderClass extends AppCommon {
                 .attr("height", "");
 
         // same as above except for allowed font-size
+        // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
         $(doc).find("h1, h2, h3, h4, h5")
             .attr("class", "")
             .css("font-family", "inherit")
@@ -901,20 +980,21 @@ class ReaderClass extends AppCommon {
             .css("background", "")
             .css("background-color", "");
 
-        if (typeof this.hyphenate.en != "undefined") {
-            $(doc).find('p, div').each((i, elem) => {
-                const p = $(elem);
-
-                p.html(this.hyphenate.en(p.html()));
-                p.html(this.hyphenate.ru(p.html()));
-            });
+        if (typeof (this.hyphenate as any).en != "undefined") {
+            // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
+            $(doc).find('p, div').each((i: any, elem: any) => {
+    // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
+    const p = $(elem);
+    p.html((this.hyphenate as any).en(p.html()));
+    p.html((this.hyphenate as any).ru(p.html()));
+});
         }
     }
 
     /**
      * @param {string} base_url
      */
-    generateFontsCss(base_url) {
+    generateFontsCss(base_url: any) {
         return `
             /** Calibri */
 
@@ -1092,13 +1172,14 @@ class ReaderClass extends AppCommon {
      * @param {ePub.NavItem} entry
      * @param {number} nest
      */
-    flattenTocSubItems(entry, nest) {
-        let rv = [];
+    flattenTocSubItems(entry: any, nest: any) {
+        let rv: any = [];
 
         if (nest == 3) return false;
 
         if (entry.subitems) {
-            $.each(entry.subitems, (i, r) => {
+            // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
+            $.each(entry.subitems, (i: any, r: any) => {
                 r._nest = nest;
 
                 rv.push(r);
@@ -1114,14 +1195,14 @@ class ReaderClass extends AppCommon {
      *
      * @returns { ePub.NavItem[] }
      */
-    flattenToc(book) {
+    flattenToc(book: any) {
         if (this._flattened_toc) {
             return this._flattened_toc;
         } else {
-            let rv = [];
+            let rv: any = [];
 
-            $.each(book.navigation.toc, (i, r) => {
-                // @ts-ignore
+            // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
+            $.each(book.navigation.toc, (i: any, r: any) => {
                 r._nest = 0;
 
                 rv.push(r);
@@ -1138,21 +1219,25 @@ class ReaderClass extends AppCommon {
      * @param { ePub.Book } book
      * @param { any[] } toc
      */
-    generateTocBar(book, toc) {
+    generateTocBar(book: any, toc: any) {
+        // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
         $(".spacer")
             .html("");
 
-        $.each(toc, function(i, te) {
+        // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
+        $.each(toc, function(i: any, te: any) {
             try {
                 const cfiBase = book.spine.get(te.href).cfiBase;
-                const loc = book.locations._locations.find(function(k) {
+                const loc = book.locations._locations.find(function(k: any) {
                     return k.indexOf(cfiBase) != -1
                 });
 
                 if (loc) {
                     const pct = Math.round(book.locations.percentageFromCfi(loc) * 100);
 
+                    // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
                     $(".spacer").append(
+                        // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
                         $("<div class='toc-bar-entry'>")
                             .attr('data-nest-level', te._nest)
                             .css('left', pct + '%')
@@ -1167,6 +1252,7 @@ class ReaderClass extends AppCommon {
             }
         });
 
+        // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
         $(".spacer").append($("<div class='toc-bar-entry current-position'>"));
 
         this.updateTocBarPosition(book, book.rendition.currentLocation())
@@ -1176,9 +1262,10 @@ class ReaderClass extends AppCommon {
      * @param {ePub.Book} book
      * @param {ePub.Location} location
      */
-    updateTocBarPosition(book, location) {
+    updateTocBarPosition(book: any, location: any) {
         const cur_pct = Math.round(location.start.location / book.locations.length() * 100);
 
+        // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
         $(".toc-bar-entry.current-position")
                 .css('left', cur_pct + '%');
     }
@@ -1206,7 +1293,7 @@ class ReaderClass extends AppCommon {
                 }
             });
 
-        let theme = await localforage.getItem("epube.theme") || "default";
+        let theme = (await localforage.getItem("epube.theme")) || "default";
 
         console.log('called for theme', theme);
 
@@ -1216,6 +1303,7 @@ class ReaderClass extends AppCommon {
 
         console.log('setting main UI theme', theme);
 
+        // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
         $("body")
             .attr("class", typeof EpubeApp != "undefined" ? "is-epube-app" : "")
             .addClass("epube-reader theme-" + theme)
@@ -1251,7 +1339,7 @@ class ReaderClass extends AppCommon {
         }
 
         if (this.book && this.book.rendition)
-            this.book.rendition.getContents().forEach((rendition) => {
+            this.book.rendition.getContents().forEach((rendition: any) => {
                 console.log(`applying styles and theme ${theme} to `, rendition);
 
                 rendition.css("font-size", fontSize);
@@ -1259,6 +1347,7 @@ class ReaderClass extends AppCommon {
                 rendition.css("line-height", lineHeight);
                 rendition.css("text-align", 'justify');
 
+                // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
                 $(rendition.document).find("body")
                     .attr("class", typeof EpubeApp != "undefined" ? "is-epube-app" : "")
                     .addClass("theme-" + theme);
@@ -1268,10 +1357,11 @@ class ReaderClass extends AppCommon {
     /**
      * @param {JQuery.KeyUpEvent<Document, undefined, Document, Document>} e
      */
-    hotkeyHandler(e) {
+    hotkeyHandler(e: any) {
         try {
             //console.log('K3:' + e.which, e);
 
+            // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
             if ($(".modal").is(":visible"))
                 return;
 
@@ -1298,10 +1388,11 @@ class ReaderClass extends AppCommon {
     }
 
     resizeSideColumns() {
+        // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
         let width = $("#reader").position().left;
 
         if (this.book && this.book.rendition)
-            this.book.rendition.getContents().forEach((rendition) => {
+            this.book.rendition.getContents().forEach((rendition: any) => {
                 const body = rendition.document.querySelector('body');
 
                 if (body)
@@ -1310,11 +1401,13 @@ class ReaderClass extends AppCommon {
 
         console.log(`resizing side columns to ${width} px`);
 
+        // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
         $("#left, #right").width(width);
     }
 
     async markAsRead() {
         if (confirm("Mark book as read?")) {
+            // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
             $("#settings-modal").modal('hide');
 
             const total = 100;
@@ -1324,6 +1417,7 @@ class ReaderClass extends AppCommon {
             if (this.isOnline()) {
                 /** @type {HttpResponse} */
                 const data = await Http.post("backend.php", { op: "storelastread", page: String(total), cfi: lastCfi, id: this.urlParam("id"), timestamp: String(lastread_timestamp) });
+                // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
                 $(".lastread_input").val(data.data.page + '%');
             }
 
@@ -1359,37 +1453,45 @@ class ReaderClass extends AppCommon {
     }
 
     /** @param {string} [suffix] */
-    cacheId(suffix) {
+    cacheId(suffix: any) {
         return "epube-book." + this.urlParam("b") + (suffix ? "." + suffix : "");
     }
 
     /**
      * @param {boolean} show
      */
-    showUI(show) {
+    showUI(show: any) {
         if (show)
+            // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
             $(".header,.footer").fadeIn();
         else
+            // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
             $(".header,.footer").fadeOut();
     }
 
     toggleUI() {
+        // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
         if ($(".header").is(":visible"))
+            // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
             $(".header,.footer").fadeOut();
         else
+            // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
             $(".header,.footer").fadeIn();
     }
 
-    async lookupWord(word, callback, elem) {
+    async lookupWord(word: any, callback: any, elem: any) {
         if (elem)
+            // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
             word = $(elem).val();
 
         word = word.replace(/­/g, "");
 
         console.log('lookupWord', word);
 
+        // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
         $(".dict_result").html('Loading, please wait...');
 
+        // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
         $("#dict-modal").modal('show');
 
         try {
@@ -1398,7 +1500,9 @@ class ReaderClass extends AppCommon {
 
             if (data.data) {
 
-                $(".dict_result").html(data.data.result.map((r) => this.escapeHtml(String(r))).join("<br/>"));
+                // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
+                $(".dict_result").html(data.data.result.map((r: any) => this.escapeHtml(String(r))).join("<br/>"));
+                // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
                 $(".dict_query").val(word);
 
                 if (callback) callback();
@@ -1409,7 +1513,8 @@ class ReaderClass extends AppCommon {
 
             console.error(err);
 
-            $(".dict_result").html(`Network error while looking up word: ${this.escapeHtml((String)(err.responseText))}.`);
+            // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
+            $(".dict_result").html(`Network error while looking up word: ${this.escapeHtml((String)((err as any).responseText))}.`);
         }
     }
 
@@ -1417,7 +1522,9 @@ class ReaderClass extends AppCommon {
      * @returns {Promise<void>}
      */
     async search() {
+        // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
         const query = $(".search_input").val();
+        // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
         const list = $(".search_results");
 
         list.html("");
@@ -1428,7 +1535,7 @@ class ReaderClass extends AppCommon {
 
         try {
             const searchResults = await Promise.all(
-                this.book.spine.spineItems.map(async (item) => {
+                this.book.spine.spineItems.map(async (item: any) => {
                     try {
                         await item.load(this.book.load.bind(this.book));
                         const results = await item.find(`${query}`);
@@ -1441,17 +1548,20 @@ class ReaderClass extends AppCommon {
 
             list.html("");
 
-            searchResults.flat().forEach((row) => {
+            searchResults.flat().forEach((row: any) => {
                 console.log('sr', row);
 
+                // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
                 const a = $("<a>")
                     .attr('href', '#')
                     .html(`<b class='pull-right'>${this.book.locations.locationFromCfi(row.cfi)}</b>${this.escapeHtml(row.excerpt)}`)
                     .attr('data-cfi', row.cfi)
                     .on('click', () => {
+                        // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
                         this.book.rendition.display($(a).attr('data-cfi'));
                     });
 
+                // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
                 list.append($("<li>").append(a));
             });
         } catch (e) {
@@ -1465,7 +1575,7 @@ class ReaderClass extends AppCommon {
             if (typeof EpubeApp != "undefined")
                 EpubeApp.showActionBar(false);
             else
-                localforage.getItem("epube.keep-ui-visible").then((keep) => {
+                localforage.getItem("epube.keep-ui-visible").then((keep: any) => {
                     if (!keep) this.showUI(false);
                 });
     }
@@ -1476,7 +1586,7 @@ class ReaderClass extends AppCommon {
         if (typeof EpubeApp != "undefined")
             EpubeApp.showActionBar(false);
         else
-            localforage.getItem("epube.keep-ui-visible").then((keep) => {
+            localforage.getItem("epube.keep-ui-visible").then((keep: any) => {
                 if (!keep) this.showUI(false);
             });
     }
@@ -1484,12 +1594,14 @@ class ReaderClass extends AppCommon {
     /**
      * @param {HTMLElement} elem
      */
-    async openPrevious(elem) {
+    async openPrevious(elem: any) {
+        // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
         const cfi = $(elem).attr("data-location-cfi");
 
         if (cfi)
             await this.book.rendition.display(cfi);
 
+        // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
         $(elem).fadeOut();
     }
 
@@ -1512,7 +1624,7 @@ class ReaderClass extends AppCommon {
      * @param { ePub.Book } book
      * @param { ePub.Location } location
      */
-    async onRelocated(book, location) {
+    async onRelocated(book: any, location: any) {
         // locations not generated yet
         if (book.locations.length() == 0)
             return;
@@ -1520,8 +1632,11 @@ class ReaderClass extends AppCommon {
         const currentCfi = location.start.cfi;
         const currentPct = Math.round(book.locations.percentageFromCfi(currentCfi) * 100);
 
+        // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
         $("#cur_page").text(Math.floor(location.start.location / LOCATION_DIVISOR));
+        // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
         $("#total_pages").text(Math.floor(book.locations.length() / LOCATION_DIVISOR));
+        // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
         $("#page_pct").text(Math.round(book.locations.percentageFromCfi(currentCfi)*100) + '%');
 
         this.updateTocBarPosition(book, location);
@@ -1529,10 +1644,13 @@ class ReaderClass extends AppCommon {
         const displayed = location.start.displayed;
 
         if (displayed) {
+            // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
             $("#chapter_cur_page").text(displayed.page);
+            // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
             $("#chapter_total_pages").text(displayed.total);
 
             if (displayed.total > 0)
+                // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
                 $("#chapter_pct").text(Math.round(displayed.page / displayed.total * 100) + '%')
         }
 
@@ -1558,6 +1676,7 @@ class ReaderClass extends AppCommon {
 
     async clearLastRead() {
         if (confirm("Reset reading progress for this book?")) {
+            // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
             $("#settings-modal").modal('hide');
 
             const total = this.book.locations.length();
@@ -1571,12 +1690,14 @@ class ReaderClass extends AppCommon {
 
             await this.book.rendition.display(this.book.locations.cfiFromPercentage(0));
 
+            // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
             $(".lastread_input").val('0%');
         }
     }
 
     async resetLocations() {
         if (confirm("Reset stored pagination data? This will also reset reading progress.")) {
+            // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
             $("#settings-modal").modal('hide');
 
             await localforage.removeItem(this.cacheId("lastread"));
@@ -1593,9 +1714,12 @@ class ReaderClass extends AppCommon {
     }
 
     async openLastRead() {
+        // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
         $(".loading").show();
+        // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
         $(".loading-message").html("Opening last read page…");
 
+        // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
         $("#settings-modal").modal('hide');
 
         const rendition = this.book.rendition;
@@ -1607,7 +1731,7 @@ class ReaderClass extends AppCommon {
 
         let location_found = false;
 
-        const lr_local = await localforage.getItem(this.cacheId("lastread")) || {};
+        const lr_local = (await localforage.getItem(this.cacheId("lastread"))) || {};
         console.log('got local lastread', lr_local);
 
         if (this.isOnline()) {
@@ -1646,6 +1770,7 @@ class ReaderClass extends AppCommon {
             }
         }
 
+        // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
         $(".loading").fadeOut();
     }
 
@@ -1653,13 +1778,13 @@ class ReaderClass extends AppCommon {
      * @param {?string} a
      * @param {?string} b
      */
-    calculateCfiDelta(a, b) {
+    calculateCfiDelta(a: any, b: any) {
         if (!a || !b)
             return -1;
 
-        // @ts-ignore
+        // @ts-expect-error TS(2304): Cannot find name 'ePub'.
         const acfi = new ePub.CFI(a);
-        // @ts-ignore
+        // @ts-expect-error TS(2304): Cannot find name 'ePub'.
         const bcfi = new ePub.CFI(b);
 
         console.log('calculateCfiDelta', acfi, bcfi);
@@ -1691,7 +1816,7 @@ class ReaderClass extends AppCommon {
      * @param {ePub.Rendition} rendition
      * @param {string} cfi
      */
-    async moveToCfiVerify(rendition, cfi, attempts = 5, maxDelta = 5) {
+    async moveToCfiVerify(rendition: any, cfi: any, attempts = 5, maxDelta = 5) {
         for (let att = 1; att < attempts; att++) {
             this.blockLastReadUpdate();
 
@@ -1728,7 +1853,8 @@ class ReaderClass extends AppCommon {
     /**
      * @param {HTMLElement} elem
      */
-    async onThemeChanged(elem) {
+    async onThemeChanged(elem: any) {
+        // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
         const theme = $(elem).val();
 
         await localforage.setItem("epube.theme", theme);
@@ -1738,7 +1864,8 @@ class ReaderClass extends AppCommon {
     /**
      * @param {HTMLElement} elem
      */
-    async onLineHeightChanged(elem) {
+    async onLineHeightChanged(elem: any) {
+        // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
         const height = $(elem).val();
 
         await localforage.setItem("epube.lineHeight", height);
@@ -1748,7 +1875,8 @@ class ReaderClass extends AppCommon {
     /**
      * @param {HTMLElement} elem
      */
-    async onTextSizeChanged(elem) {
+    async onTextSizeChanged(elem: any) {
+        // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
         const size = $(elem).val();
 
         await localforage.setItem("epube.fontSize", size);
@@ -1758,7 +1886,8 @@ class ReaderClass extends AppCommon {
     /**
      * @param {HTMLElement} elem
      */
-    async onFontChanged(elem) {
+    async onFontChanged(elem: any) {
+        // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
         const font = $(elem).val();
 
         await localforage.setItem("epube.fontFamily", font);
@@ -1772,12 +1901,13 @@ class ReaderLoader {
     /**
      * @param {ReaderClass} app
      */
-    async init(app) {
+    async init(app: any) {
         const cacheName = await app.getActiveCacheName();
 
         console.log('loader init for cache:', cacheName);
 
         if (typeof EpubeApp != "undefined") {
+            // @ts-expect-error TS(2581): Cannot find name '$'. Do you need to install type ... Remove this comment to see the full error message
             $("body").addClass("epube-app");
         }
 
@@ -1808,10 +1938,12 @@ class ReaderLoader {
             let promise;
             if (req.url.match(/\.(ttf|otf)$/)) {
                 promise = response.blob().then((blob) => {
+                    // @ts-expect-error TS(7053): Element implicitly has an 'any' type because expre... Remove this comment to see the full error message
                     this._res_data[key] = URL.createObjectURL(blob);
                 });
             } else {
                 promise = response.text().then((text) => {
+                    // @ts-expect-error TS(7053): Element implicitly has an 'any' type because expre... Remove this comment to see the full error message
                     this._res_data[key] = text;
                 });
             }
@@ -1822,6 +1954,7 @@ class ReaderLoader {
             }));
         }
 
+        // @ts-expect-error TS(2550): Property 'allSettled' does not exist on type 'Prom... Remove this comment to see the full error message
         await Promise.allSettled(promises);
 
         if (Object.keys(this._res_data).length === 0) loadFailed = true;
diff --git a/src/worker.ts b/src/worker.ts
index 44ea5b1..7afde1b 100644
--- a/src/worker.ts
+++ b/src/worker.ts
@@ -11,52 +11,40 @@ const MANIFEST_ASSETS = BUILD_MANIFEST_ASSETS;
 
 // Install: precache all assets from manifest
 sw.addEventListener('install', (event) => {
-    event.waitUntil(
-        (async () => {
-            console.log('[worker] install started', CACHE_NAME);
-
-            const cache = await caches.open(CACHE_NAME);
-
-            try {
-                // 1. Fetch all assets concurrently with version parameters
-                const fetchPromises = MANIFEST_ASSETS.map(async (url) => {
-                    const cleanUrl = new URL(url, location.href);
-
-                    // normalize = strip CACHE_VERSION suffix from pathname
-                    cleanUrl.pathname = cleanUrl.pathname.replace("_" + CACHE_VERSION, "");
-
-                    // this is our original URL from manifest (with suffix if set)
-                    const networkUrl = new URL(url, location.href);
-
-                    const response = await fetch(networkUrl.toString(), { cache: 'reload' });
-
-                    // Emulate cache.addAll behavior: fail if any status is not 200-299
-                    if (!response.ok) {
-                        throw new Error(`Failed to fetch ${cleanUrl} (Status: ${response.status})`);
-                    }
-
-                    return {
-                        cleanUrlStr: cleanUrl.toString(),
-                        response: response.clone()
-                    };
-                });
-
-                const results = await Promise.all(fetchPromises);
-                await Promise.all(results.map(({ cleanUrlStr, response }) => cache.put(cleanUrlStr, response)));
-
-                console.log('[worker] all assets cached successfully');
-
-                // Only skip waiting if the entire cache was successfully built
-                sw.skipWaiting();
-            } catch (err) {
-                console.error('[worker] Critical precache failed! Critical asset missing:', err);
-                // Do NOT call skipWaiting(). Let this installation fail so the old worker stays safe.
-
-                // we need to tell the browser the install failed so it throws away this worker, otherwise it gets stuck in waiting
-                throw err;
-            }
-        })()
-    );
+    (event as any).waitUntil((async () => {
+        console.log('[worker] install started', CACHE_NAME);
+        const cache = await caches.open(CACHE_NAME);
+        try {
+            // 1. Fetch all assets concurrently with version parameters
+            const fetchPromises = MANIFEST_ASSETS.map(async (url) => {
+                const cleanUrl = new URL(url, location.href);
+                // normalize = strip CACHE_VERSION suffix from pathname
+                cleanUrl.pathname = cleanUrl.pathname.replace("_" + CACHE_VERSION, "");
+                // this is our original URL from manifest (with suffix if set)
+                const networkUrl = new URL(url, location.href);
+                const response = await fetch(networkUrl.toString(), { cache: 'reload' });
+                // Emulate cache.addAll behavior: fail if any status is not 200-299
+                if (!response.ok) {
+                    throw new Error(`Failed to fetch ${cleanUrl} (Status: ${response.status})`);
+                }
+                return {
+                    cleanUrlStr: cleanUrl.toString(),
+                    response: response.clone()
+                };
+            });
+            const results = await Promise.all(fetchPromises);
+            await Promise.all(results.map(({ cleanUrlStr, response }) => cache.put(cleanUrlStr, response)));
+            console.log('[worker] all assets cached successfully');
+            // Only skip waiting if the entire cache was successfully built
+            (sw as any).skipWaiting();
+        }
+        catch (err) {
+            console.error('[worker] Critical precache failed! Critical asset missing:', err);
+            // Do NOT call skipWaiting(). Let this installation fail so the old worker stays safe.
+            // we need to tell the browser the install failed so it throws away this worker, otherwise it gets stuck in waiting
+            throw err;
+        }
+    })());
 });
 
 sw.addEventListener('message', (event) => {
@@ -72,11 +60,9 @@ sw.addEventListener('message', (event) => {
 // Activate: clean up old caches and take control of all pages
 sw.addEventListener('activate', (event) => {
     console.log('[worker] activate');
-
     // Create the async task block
     const activationTask = async () => {
         // await loadConfig();
-
         const keyList = await caches.keys();
         for (const key of keyList) {
             if (key.includes(CACHE_PREFIX) && key !== CACHE_NAME) {
@@ -84,101 +70,83 @@ sw.addEventListener('activate', (event) => {
                 await caches.delete(key);
             }
         }
-
+        // @ts-expect-error TS(2551): Property 'clients' does not exist on type 'Window ... Remove this comment to see the full error message
         await sw.clients.claim();
     };
-
     // Hand the executed promise directly to the event
-    event.waitUntil(activationTask());
+    (event as any).waitUntil(activationTask());
 });
 
 // Fetch: cache-first for static assets, network-first for API
 sw.addEventListener('fetch', (event) => {
-    const url = new URL(event.request.url);
-
+    const url = new URL((event as any).request.url);
     // console.log('[fetch]', url);
-
     // /assets/ belong to android app
-    if (url.pathname.startsWith('/assets/')) return;
-
+    if (url.pathname.startsWith('/assets/'))
+        return;
     // request API endpoints from the network if possible and cache them locally
     if (url.pathname.match('backend.php')) {
-        event.respondWith(
-            // @ts-ignore-next-line
-            (async () => {
-                try {
-                    const networkResp = await fetch(event.request);
-
-                    if (networkResp.ok) {
-                        const cache = await caches.open(CACHE_NAME);
-                        await cache.put(networkResp.url, networkResp.clone());
-                    }
-
-                    return networkResp;
-                } catch (err) {
-                    // Network failed, try to get the cached API response
-                    const cachedResp = await caches.match(event.request);
-                    if (cachedResp) return cachedResp;
+        (event as any).respondWith((async () => {
+            try {
+                const networkResp = await fetch((event as any).request);
+                if (networkResp.ok) {
+                    const cache = await caches.open(CACHE_NAME);
+                    await cache.put(networkResp.url, networkResp.clone());
                 }
-            })()
-        );
+                return networkResp;
+            }
+            catch (err) {
+                // Network failed, try to get the cached API response
+                const cachedResp = await caches.match((event as any).request);
+                if (cachedResp)
+                    return cachedResp;
+            }
+        })());
         return;
     }
-
     // index & read UI: online first; if offline, map index pages to offline.html & map all read.html?* to offline read.html
     if (url.pathname == "/" || url.pathname.match("index.html|offline.html|read.html")) {
-        event.respondWith(
-            // @ts-ignore-next-line
-            (async () => {
-                try {
-                    const networkResp = await fetch(event.request);
-
-                    if (networkResp.ok) {
-                        const cache = await caches.open(CACHE_NAME);
-                        await cache.put(networkResp.url, networkResp.clone());
-                    }
-
-                    return networkResp;
-                } catch (err) {
-                    // i.e. read.html?id=1234&b=1234
-                    if (url.pathname.includes("read.html")) {
-                        return caches.match("read.html");
-                    } else {
-                        return caches.match('/offline.html');
-                    }
+        (event as any).respondWith((async () => {
+            try {
+                const networkResp = await fetch((event as any).request);
+                if (networkResp.ok) {
+                    const cache = await caches.open(CACHE_NAME);
+                    await cache.put(networkResp.url, networkResp.clone());
                 }
-            })()
-        );
-
+                return networkResp;
+            }
+            catch (err) {
+                // i.e. read.html?id=1234&b=1234
+                if (url.pathname.includes("read.html")) {
+                    return caches.match("read.html");
+                }
+                else {
+                    return caches.match('/offline.html');
+                }
+            }
+        })());
         return;
     }
-
     // everything else: cache-first with network fallback
-    event.respondWith(
-        (async () => {
-            const cache = await caches.open(CACHE_NAME);
-            const cached = await cache.match(event.request);
-
-            if (cached) {
-                // if cached, try to update: fire background network check without waiting for it (no await)
-                fetch(event.request)
-                    .then((networkResp) => {
-                        if (networkResp.ok) cache.put(event.request, networkResp.clone());
-                    })
-                    .catch((e) => console.warn('[worker] Background update failed:', e));
-
-                // Return cached asset immediately
-                return cached;
-            }
-
-            // Cache miss: fetch from network and cache it
-            const networkResp = await fetch(event.request);
-
-            /* if (networkResp.ok) { -- we don't cache all responses
-                await cache.put(event.request, networkResp.clone());
-            } */
-
-            return networkResp;
-        })()
-    );
+    (event as any).respondWith((async () => {
+        const cache = await caches.open(CACHE_NAME);
+        const cached = await cache.match((event as any).request);
+        if (cached) {
+            // if cached, try to update: fire background network check without waiting for it (no await)
+            fetch((event as any).request)
+                .then((networkResp) => {
+                if (networkResp.ok)
+                    cache.put((event as any).request, networkResp.clone());
+            })
+                .catch((e) => console.warn('[worker] Background update failed:', e));
+            // Return cached asset immediately
+            return cached;
+        }
+        // Cache miss: fetch from network and cache it
+        const networkResp = await fetch((event as any).request);
+        /* if (networkResp.ok) { -- we don't cache all responses
+            await cache.put(event.request, networkResp.clone());
+        } */
+        return networkResp;
+    })());
 });