about summary refs log tree commit diff stats
path: root/src/app.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/app.ts')
-rw-r--r--src/app.ts126
1 files changed, 90 insertions, 36 deletions
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([