Skip to content

Commit

Permalink
feat(reader): add proxy-md setting
Browse files Browse the repository at this point in the history
  • Loading branch information
JipFr committed Jul 10, 2024
1 parent 6c985b7 commit d0eaac9
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 14 deletions.
19 changes: 10 additions & 9 deletions public/js/pages/reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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=";
}
Expand Down
7 changes: 7 additions & 0 deletions public/js/reusable/reader-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const defaultSettings = {
"double-pages": "no",
"image-scaling": "width",
"tap-navigation": "yes",
"proxy-md": "yes",
};

// Get current settings
Expand Down Expand Up @@ -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();
11 changes: 8 additions & 3 deletions public/js_compiled/pages/reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
10 changes: 8 additions & 2 deletions public/js_compiled/reusable/reader-settings.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions views/partials/settings-inner.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,8 @@
<label>Keyboard controls</label>
<input type="checkbox" class="switch" data-true="yes" data-false="no" />
</div>
<div class="setting-wrapper toggle" data-setting="proxy-md">
<label>Proxy MangaDex</label>
<input type="checkbox" class="switch" data-true="yes" data-false="no" />
</div>
</div>

0 comments on commit d0eaac9

Please sign in to comment.