You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.0 KiB

const oldOnloadHandler = window.onload ?? (() => {});
window.onload = () => {
oldOnloadHandler();
// Scroll header to current entry
document.getElementById("selected-header")?.scrollIntoView({
block: "center",
inline: "center"
});
// Sync history
const params = new URL(document.location.href).searchParams;
if (params.get("chapter")) {
localStorage.setItem(
`${params.get("id")}_progress`,
params.get("chapter")
);
}
const readingHistory = JSON.parse(
localStorage.getItem("readingHistory") ?? "[]"
);
readingHistory.forEach((id, idx) => {
if (id === params.get("id")) {
readingHistory.splice(idx, 1);
}
});
readingHistory.unshift(params.get("id"));
//TODO: do pagination on the history page to make this un-necessary
if (readingHistory.length > 50) {
readingHistory.pop();
}
localStorage.setItem("readingHistory", JSON.stringify(readingHistory));
};