diff options
Diffstat (limited to 'ui/client-scripts')
| -rw-r--r-- | ui/client-scripts/src/pagination.ts | 32 |
1 files changed, 18 insertions, 14 deletions
diff --git a/ui/client-scripts/src/pagination.ts b/ui/client-scripts/src/pagination.ts index 380b20e..62362c1 100644 --- a/ui/client-scripts/src/pagination.ts +++ b/ui/client-scripts/src/pagination.ts @@ -1,18 +1,22 @@ -globalThis.addEventListener("DOMContentLoaded", () => { - const el = document.querySelector(".next_page") as HTMLElement +function init_paging() { + const el = document.querySelector(".next_page") as HTMLAnchorElement if (!el) return - const cont = document.body.parentElement! - console.log(cont); - - cont.addEventListener("scroll", () => { - const end = cont.scrollTop + cont.clientHeight - console.log(end, cont.scrollHeight); - - if (end + 1000 > el.scrollHeight) { - el.textContent = "Loading more..." - el.click() + document.body.onscroll = () => { + const end = document.body.clientHeight - document.body.parentElement!.scrollTop - document.body.parentElement!.clientHeight + if (end < 200) { + document.body.onscroll = () => { } + load_next(el) } + } +} - }) -}) +async function load_next(el: HTMLAnchorElement) { + const res = await fetch(el.href + "&no_scaff") + if (!res.ok) throw "aaa" + const ext = await res.text() + el.remove() + document.getElementById("main")!.innerHTML += ext + init_paging() +} +globalThis.addEventListener("DOMContentLoaded", init_paging) |