Skip to content

Commit

Permalink
feat(settings): cache scroll pos - boilerplate
Browse files Browse the repository at this point in the history
  • Loading branch information
ohitstom committed Sep 19, 2023
1 parent 02bdf27 commit d17c60d
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Comfy/theme.script.js
Original file line number Diff line number Diff line change
Expand Up @@ -955,6 +955,7 @@
isLarge: true,
});

// Discord Text
const header = document.querySelector(".main-trackCreditsModal-header");
const container = document.createElement("div");
const extraText = document.createElement("a");
Expand All @@ -965,6 +966,25 @@
container.appendChild(document.querySelector("h1.main-type-alto"));
container.appendChild(extraText);
header.prepend(container);

// Scroll Position
const section = document.querySelector(".main-trackCreditsModal-mainSection");
const cache = sessionStorage.getItem("comfy-settings-scroll");
const scrollVal = cache ? cache * (section.scrollHeight - section.clientHeight) : 0;

function handleScroll(event) {
const a = section.scrollTop;
const b = section.scrollHeight - section.clientHeight;
const c = a / b;
sessionStorage.setItem("comfy-settings-scroll", c);

// If section is no longer in the DOM, remove the event listener
if (!document.contains(section)) {
section.removeEventListener("scroll", handleScroll);
}
}
section.scrollTo(null, scrollVal);
section.addEventListener("scroll", handleScroll);
},
false,
true
Expand Down

0 comments on commit d17c60d

Please sign in to comment.