aboutsummaryrefslogtreecommitdiff
path: root/app/src/web/ts/menu.ts
blob: 6f9dbf16fe3eae5796bde009cde50db4716605c1 (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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Click menu and move contents to main view
(function () {
    const viewport = document.querySelector("#viewport");
    const root = document.querySelector("#root");
    const bookmarkJewel = document.querySelector("#bookmarks_jewel");
    if (!viewport || !root || !bookmarkJewel) {
        console.log('Menu.js: main elements not found');
        Frost.emit(0);
        return
    }
    const menuA = bookmarkJewel.querySelector("a");
    if (!menuA) {
        console.log('Menu.js: menu links not found');
        Frost.emit(0);
        return
    }
    const jewel = document.querySelector('#mJewelNav');
    if (!jewel) {
        console.log('Menu.js: jewel is null');
        return
    }

    const y = new MutationObserver(() => {
        viewport.removeAttribute('style');
        root.removeAttribute('style');
    });

    y.observe(viewport, {
        attributes: true
    });
    y.observe(root, {
        attributes: true
    });

    const x = new MutationObserver(() => {
        const menu = document.querySelector('.mSideMenu');
        if (menu) {
            x.disconnect();
            console.log("Found side menu");
            // Transfer elements
            while (root.firstChild) {
                root.removeChild(root.firstChild);
            }
            while (menu.childNodes.length) {
                viewport.appendChild(menu.childNodes[0]);
            }
            Frost.emit(0);
            setTimeout(() => {
                y.disconnect();
                console.log('Unhook styler');
            }, 500);
        }
    });
    x.observe(jewel, {
        childList: true,
        subtree: true
    });
    menuA.click();
}).call(undefined);