aboutsummaryrefslogtreecommitdiff
path: root/ui/client-scripts/src/pagination.ts
blob: 3226f6c7d1b85165d0ec9cb5c51801f1c10b5f59 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/*
    This file is part of jellything (https://codeberg.org/metamuffin/jellything)
    which is licensed under the GNU Affero General Public License (version 3); see /COPYING.
    Copyright (C) 2026 metamuffin <metamuffin.org>
*/

function init_paging() {
    const el = document.querySelector(".next_page") as HTMLAnchorElement
    if (!el) return
    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)