Skip to content

Commit

Permalink
Update htmlv2.pug
Browse files Browse the repository at this point in the history
Added per-story scrollkey
  • Loading branch information
sipsuru authored Dec 15, 2024
1 parent 3903f32 commit 3577d8e
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions templates/htmlv2.pug
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ html(lang=langName)
meta(charset="UTF-8")
title= book.title
meta(name="viewport" content="width=device-width, initial-scale=1.0")
meta(name="scroll-key" content= book.id)

body

Expand Down Expand Up @@ -205,7 +206,15 @@ html(lang=langName)

script.
const fontList = ["Arial, sans-serif", "Verdana, sans-serif", "Cambria, serif", "cursive", "monospace"];
let scrollsave = localStorage.getItem("scrollsave");
const scrollKey = document.querySelector('meta[name="scroll-key"]')?.content;
let scrollsave; // Declare in the outer scope

if (scrollKey) {
scrollsave = localStorage.getItem(`scrollsave_${scrollKey}`);
} else {
console.warn("No scroll key defined in the HTML.");
}

let fontsize = localStorage.getItem("fontsize");
let colormode = localStorage.getItem("colormode");
let font = localStorage.getItem("font");
Expand All @@ -231,7 +240,7 @@ script.

window.addEventListener("click", (event) => {

if(!event.path.find((el) => el.id === "top-control" || el.id === "bottom-control")){
if(!event.composedPath().some((el) => el.id === "top-control" || el.id === "bottom-control")){
document.querySelector("#top-control").classList.toggle("active");
document.querySelector("#bottom-control").classList.toggle("active");
}
Expand All @@ -251,7 +260,7 @@ script.
window.clearTimeout(isScrolling);

isScrolling = setTimeout(() => {
localStorage.setItem("scrollsave", currentScroll.toString());
localStorage.setItem(`scrollsave_${scrollKey}`, currentScroll.toString());
}, 80);

});
Expand Down

0 comments on commit 3577d8e

Please sign in to comment.