summaryrefslogtreecommitdiff
path: root/assets/js/main.js
blob: bcd6af64b0d4988f1762fa8a578ce3fd7377a1de (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
class Main {
    constructor() {}

    async Init() {
        await this.Get()
    }

    #Loading() {}
    async Get(x) {
        this.object = {
            session: document.cookie,
            url: window.location.href
        }
        this.fetch = '/'
        if (x) this.fetch = x

        await fetch(this.fetch, {
            method: 'post',
            body: JSON.stringify(this.object),
            headers: new Headers({
                'Content-Type': 'application/json'
            })
        })
            .then(res => res.json())
            .then(output => {
                const head = document.getElementsByTagName('head')[0]
                const body = document.getElementsByTagName('body')[0]
                const section = document.getElementById('main')

                for (let i = 0; i < output.css.length; i++) {
                    const link = document.createElement('link')
                    link.rel = 'stylesheet'
                    link.type = 'text/css'
                    link.href = `${window.location.origin}/css/${output.css[i]}`
                    head.appendChild(link)
                }
                for (let i = 0; i < output.js.length; i++) {
                    const script = document.createElement('script')
                    script.src = `${window.location.origin}/js/${output.js[i]}`
                    body.appendChild(script)
                }

                section.innerHTML = DOMPurify.sanitize(output.html)
            })
    }
}

new Main().Init()