blob: 5da93edf6a89af78bca791f7a678d5e47004df71 (
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
60
61
62
|
class Main {
constructor() {
this.object = {
head: document.getElementsByTagName('head')[0],
body: document.getElementsByTagName('body')[0]
}
}
async Init() {
await this.Get()
}
#Loading() {}
async Get(x) {
const object = {
session: document.cookie,
url: window.location.href
}
this.fetch = '/'
if (x) this.fetch = x
await fetch(this.fetch, {
method: 'post',
body: JSON.stringify(object),
headers: new Headers({
'Content-Type': 'application/json'
})
})
.then(res => res.json())
.then(output => {
this.output = output
const section = document.getElementById('main')
this.#LoadCSS(output.css).then(output => {
section.innerHTML = DOMPurify.sanitize(this.output.html)
this.output.js.map(file => {
const script = document.createElement('script')
script.src = `${window.location.origin}/js/${file}`
this.object.body.appendChild(script)
})
})
//section.innerHTML = DOMPurify.sanitize(output.html)
})
}
async #LoadCSS (files) {
const promises = files.map(file => {
return new Promise(res => {
const link = document.createElement('link')
link.rel = 'stylesheet'
link.type = 'text/css'
link.href = `${window.location.origin}/css/${file}`
this.object.head.appendChild(link)
link.onload = res
})
})
return Promise.all(promises)
}
}
new Main().Init()
|