diff options
| author | Andrew Dolgov <fox@fakecake.org> | 2026-06-16 12:10:49 +0300 |
|---|---|---|
| committer | Andrew Dolgov <fox@fakecake.org> | 2026-06-16 12:10:49 +0300 |
| commit | e681773ceed41032b2096f710cfb6c6268bef004 (patch) | |
| tree | 921ec30c3782f19078b4a1c62870c92b510a2edb /src | |
| parent | 54cc92644a53f2f1758a0667f58cf4270ac51303 (diff) | |
| download | the-epube-e681773ceed41032b2096f710cfb6c6268bef004.tar.gz the-epube-e681773ceed41032b2096f710cfb6c6268bef004.tar.xz | |
more types
Diffstat (limited to 'src')
| -rw-r--r-- | src/app.js | 54 | ||||
| -rw-r--r-- | src/reader.js | 32 |
2 files changed, 83 insertions, 3 deletions
diff --git a/src/app.js b/src/app.js index ca93be3..faf51d0 100644 --- a/src/app.js +++ b/src/app.js @@ -3,6 +3,12 @@ 'use strict'; class Cookie { + + /** + * @param {string} name + * @param {string | number | boolean} value + * @param {number} lifetime + */ static set(name, value, lifetime) { const d = new Date(); d.setTime(d.getTime() + lifetime * 1000); @@ -10,6 +16,9 @@ class Cookie { document.cookie = name + "=" + encodeURIComponent(value) + "; " + expires; } + /** + * @param {string} name + */ static get(name) { name = name + "="; const ca = document.cookie.split(';'); @@ -28,6 +37,9 @@ class Cookie { } class AppCommon { + /** + * @param {string} name + */ urlParam(name){ try { const results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href); @@ -100,6 +112,7 @@ class AppCommon { } } + /** @param {boolean} is_night */ applyNightMode(is_night) { console.log("night mode changed to", is_night); @@ -112,20 +125,24 @@ class AppCommon { class AppClass extends AppCommon { _dl_progress_timeout; + /** @type{string} */ index_mode = ""; + /** @type{string} */ index_query = ""; + /** @type{number} */ index_offset = 0; cached_urls = []; + /** @type{string} */ version = BUILD_CACHE_VERSION; + /** @type{string} */ cosmeticVersion = BUILD_VERSION; - // cacheManifest = []; - + /** @type{string} */ csrf_token = ""; async init() { @@ -232,9 +249,15 @@ class AppClass extends AppCommon { window.location.reload(); } + /** + * @param {HTMLElement} elem + */ async showSummary(elem) { const bookId = elem.getAttribute("data-book-id"); + if (!bookId) + return; + if (this.isOnline()) { /** @type{HttpResponse} */ @@ -280,15 +303,25 @@ class AppClass extends AppCommon { }); } + /** + * @param {HTMLElement} elem + * @param {boolean} is_fav + */ updateFavoritePrompt(elem, is_fav) { $(elem) .text(is_fav ? "Remove from favorites" : "Add to favorites") .attr('data-is-fav', is_fav ? 1 : 0); } + /** + * @param {HTMLElement} elem + */ async toggleFavorite(elem) { const bookId = elem.getAttribute("data-book-id"); + if (!bookId) + return; + if (elem.getAttribute("data-is-fav") == "0" || confirm("Remove favorite?")) { try { @@ -316,8 +349,15 @@ class AppClass extends AppCommon { }); } + /** + * @param {HTMLElement} elem + */ async updateOfflinePrompt(elem) { const bookId = elem.getAttribute("data-book-id"); + + if (!bookId) + return; + const cacheId = "epube-book." + bookId; const book = await localforage.getItem(cacheId); @@ -364,6 +404,10 @@ class AppClass extends AppCommon { this.populateOfflineList(); } + /** + * @param {string} bookId + * @param {Function} callback + */ async get(bookId, callback) { console.log("offline cache: " + bookId); @@ -442,6 +486,9 @@ class AppClass extends AppCommon { } } + /** + * @param {HTMLElement} elem + */ removeFromList(elem) { const bookId = elem.getAttribute("data-book-id"); @@ -537,6 +584,9 @@ class AppClass extends AppCommon { this.updateIndexPagination(data); } + /** + * @param {BookList} data + */ updateIndexPagination(data) { const prevLi = $(".pager .previous"); const nextLi = $(".pager .next"); diff --git a/src/reader.js b/src/reader.js index 1df71b5..f436810 100644 --- a/src/reader.js +++ b/src/reader.js @@ -751,6 +751,9 @@ class ReaderClass extends AppCommon { } + /** + * @param {ePub.Book} book + */ initToc(book) { const _reader = this; @@ -762,7 +765,8 @@ class ReaderClass extends AppCommon { return k.indexOf(cfiBase) != -1 }); - return Math.round(_reader.book.locations.locationFromCfi(loc) / LOCATION_DIVISOR); + if (loc) + return Math.round(_reader.book.locations.locationFromCfi(loc) / LOCATION_DIVISOR); } catch (e) { console.warn(e); @@ -771,6 +775,11 @@ class ReaderClass extends AppCommon { return ""; } + /** + * @param {ePub.NavItem} row + * @param {JQuery<HTMLElement>} list + * @param {number} nest + */ function process_toc_sublist(row, list, nest) { if (nest == 3) return false; @@ -853,6 +862,9 @@ class ReaderClass extends AppCommon { } /* embedded styles may conflict with our font sizes, etc */ + /** + * @param {Document} doc + */ cleanupEmbeddedStyles(doc) { $(doc).find("p") // @ts-ignore @@ -896,6 +908,9 @@ class ReaderClass extends AppCommon { } } + /** + * @param {string} base_url + */ generateFontsCss(base_url) { return ` /** Calibri */ @@ -1070,6 +1085,10 @@ class ReaderClass extends AppCommon { `; } + /** + * @param {ePub.NavItem} entry + * @param {number} nest + */ flattenTocSubItems(entry, nest) { let rv = []; @@ -1150,6 +1169,10 @@ class ReaderClass extends AppCommon { this.updateTocBarPosition(book, book.rendition.currentLocation()) } + /** + * @param {ePub.Book} book + * @param {ePub.Location} location + */ updateTocBarPosition(book, location) { const cur_pct = Math.round(location.start.location / book.locations.length() * 100); @@ -1239,6 +1262,9 @@ class ReaderClass extends AppCommon { }); } + /** + * @param {JQuery.KeyUpEvent<Document, undefined, Document, Document>} e + */ hotkeyHandler(e) { try { //console.log('K3:' + e.which, e); @@ -1329,10 +1355,14 @@ class ReaderClass extends AppCommon { } } + /** @param {string} [suffix] */ cacheId(suffix) { return "epube-book." + this.urlParam("b") + (suffix ? "." + suffix : ""); } + /** + * @param {boolean} show + */ showUI(show) { if (show) $(".header,.footer").fadeIn(); |
