From d0eaac975b8baedc7abe2bffc90a2b2fefd4c405 Mon Sep 17 00:00:00 2001 From: Jip Fr Date: Wed, 10 Jul 2024 12:12:14 +0200 Subject: [PATCH] feat(reader): add proxy-md setting --- public/js/pages/reader.js | 19 ++++++++++--------- public/js/reusable/reader-settings.js | 7 +++++++ public/js_compiled/pages/reader.js | 11 ++++++++--- .../js_compiled/reusable/reader-settings.js | 10 ++++++++-- views/partials/settings-inner.handlebars | 4 ++++ 5 files changed, 37 insertions(+), 14 deletions(-) diff --git a/public/js/pages/reader.js b/public/js/pages/reader.js index 12b30a1..5ca8932 100644 --- a/public/js/pages/reader.js +++ b/public/js/pages/reader.js @@ -421,13 +421,10 @@ function doImages(bypassCache = false) { img.setAttribute("data-i", clone.length - i); img.style.minHeight = "30vh"; - const referer = location.href.includes("mangasee") - ? "mangasee" - : location.href.includes("manganelo") - ? "manganelo" - : location.href.includes("mangahere") - ? "mangahere" - : "null"; + let referer = "null"; + if (location.href.includes("mangasee")) referer = "mangasee"; + if (location.href.includes("manganelo")) referer = "manganelo"; + if (location.href.includes("mangahere")) referer = "mangahere"; // Set source const proxySrc = `/proxy-image?url=${encodeURIComponent( @@ -436,10 +433,14 @@ function doImages(bypassCache = false) { const isBookMode = getSettings()["double-pages"] === "yes"; + const isMangaDex = location.href.includes("mangadex"); + const imgUrl = + isMangaDex && getSettings()["proxy-md"] === "yes" ? proxySrc : url; + if (isBookMode) { - img.setAttribute("src", url); + img.setAttribute("src", imgUrl); } else { - img.setAttribute("data-src", url); + img.setAttribute("data-src", imgUrl); img.src = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII="; } diff --git a/public/js/reusable/reader-settings.js b/public/js/reusable/reader-settings.js index 30f4a61..caeee2c 100644 --- a/public/js/reusable/reader-settings.js +++ b/public/js/reusable/reader-settings.js @@ -11,6 +11,7 @@ const defaultSettings = { "double-pages": "no", "image-scaling": "width", "tap-navigation": "yes", + "proxy-md": "yes", }; // Get current settings @@ -116,11 +117,17 @@ function updateSettingToggles(settings) { } } +function mdProxyUpdated() { + localStorage.removeItem("image-cache"); + initImages(); +} + // Set setting async function setSetting(key, value) { let settings = getSettings(); settings[key] = value; localStorage.setItem("settings", JSON.stringify(settings)); + if (key === "proxy-md") mdProxyUpdated(); } initSettings(); diff --git a/public/js_compiled/pages/reader.js b/public/js_compiled/pages/reader.js index d70c73a..0368064 100644 --- a/public/js_compiled/pages/reader.js +++ b/public/js_compiled/pages/reader.js @@ -463,15 +463,20 @@ function doImages() { img.setAttribute("alt", "Page ".concat(Number(clone.length - i))); img.setAttribute("data-i", clone.length - i); img.style.minHeight = "30vh"; - var referer = location.href.includes("mangasee") ? "mangasee" : location.href.includes("manganelo") ? "manganelo" : location.href.includes("mangahere") ? "mangahere" : "null"; + var referer = "null"; + if (location.href.includes("mangasee")) referer = "mangasee"; + if (location.href.includes("manganelo")) referer = "manganelo"; + if (location.href.includes("mangahere")) referer = "mangahere"; // Set source var proxySrc = "/proxy-image?url=".concat(encodeURIComponent(url), "&referer=").concat(referer).concat(bypassCache ? "&c=".concat(+Date.now()) : ""); var isBookMode = getSettings()["double-pages"] === "yes"; + var isMangaDex = location.href.includes("mangadex"); + var imgUrl = isMangaDex && getSettings()["proxy-md"] === "yes" ? proxySrc : url; if (isBookMode) { - img.setAttribute("src", url); + img.setAttribute("src", imgUrl); } else { - img.setAttribute("data-src", url); + img.setAttribute("data-src", imgUrl); img.src = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII="; } img.addEventListener("error", function () { diff --git a/public/js_compiled/reusable/reader-settings.js b/public/js_compiled/reusable/reader-settings.js index 87aea15..634cfab 100644 --- a/public/js_compiled/reusable/reader-settings.js +++ b/public/js_compiled/reusable/reader-settings.js @@ -19,7 +19,8 @@ var defaultSettings = { "enable-keyboard-controls": "no", "double-pages": "no", "image-scaling": "width", - "tap-navigation": "yes" + "tap-navigation": "yes", + "proxy-md": "yes" }; // Get current settings @@ -114,6 +115,10 @@ function updateSettingToggles(settings) { _loop2(); } } +function mdProxyUpdated() { + localStorage.removeItem("image-cache"); + initImages(); +} // Set setting function setSetting(_x, _x2) { @@ -129,7 +134,8 @@ function _setSetting() { settings = getSettings(); settings[key] = value; localStorage.setItem("settings", JSON.stringify(settings)); - case 3: + if (key === "proxy-md") mdProxyUpdated(); + case 4: case "end": return _context.stop(); } diff --git a/views/partials/settings-inner.handlebars b/views/partials/settings-inner.handlebars index 9c1125f..c973224 100644 --- a/views/partials/settings-inner.handlebars +++ b/views/partials/settings-inner.handlebars @@ -92,4 +92,8 @@ +
+ + +
\ No newline at end of file