aboutsummaryrefslogtreecommitdiff
path: root/app/src/web/ts/document_watcher.ts
blob: e671149c6a33754e44dd53eae8a0a4594e124216 (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
// Emit key once half the viewport is covered
(function () {
    const isReady = () => {
        return document.body.scrollHeight > innerHeight + 100
    };

    if (isReady()) {
        console.log('Already ready');
        Frost.isReady();
        return
    }

    console.log('Injected document watcher');

    const observer = new MutationObserver(() => {
        if (isReady()) {
            observer.disconnect();
            Frost.isReady();
            console.log(`Documented surpassed height in ${performance.now()}`);
        }
    });

    observer.observe(document, {
        childList: true,
        subtree: true
    })
}).call(undefined);