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.

35 lines
1.0 KiB

export default () => {
// deno-lint-ignore ban-types
const oldOnloadHandler: Function = window.onload ?? (() => {});
window.onload = () => {
oldOnloadHandler();
const params = new URL(document.location.href).searchParams;
if (params.get("chapter")) {
localStorage.setItem(
`${params.get("id")}_progress`,
params.get("chapter") as string,
);
}
const readingHistory: string[] = JSON.parse(
localStorage.getItem("readingHistory") ?? "[]",
);
readingHistory.forEach((id, idx) => {
if (id === params.get("id")) {
readingHistory.splice(idx, 1);
}
});
readingHistory.unshift(params.get("id") as string);
//TODO: do pagination on the history page to make this un-necessary
if (readingHistory.length > 50) {
readingHistory.pop();
}
localStorage.setItem("readingHistory", JSON.stringify(readingHistory));
};
};