window.onload = () => { // 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)); };