-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpreview.js
More file actions
66 lines (61 loc) · 1.69 KB
/
preview.js
File metadata and controls
66 lines (61 loc) · 1.69 KB
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
63
64
65
66
var urlParams = new URLSearchParams(location.search)
var bodyHTML = document.body.innerHTML
function getCode() {
var c = urlParams.get('content')
if (!!c) c = btoa(c)
return c
}
var eleVal = urlParams.get('eleval')
var code = getCode()
addCode()
setInterval(addCode, 1)
function addCode() {
code = getCode()
if (!!code) {
if (code.endsWith('<')) {
needsClose = '/>'
}
else if (code.endsWith('</')) {
needsClose = '>'
}
else {
needsClose = ''
}
let ELEMENTS = code.split('<')
let i = 0
ELEMENTS.forEach(e => {
if (!!e) {
if (e.includes(' ')) {
e = e.split(' ')[0]
}
else {
e = e.split('>')[0]
}
ELEMENTS[i] = e
if (code.endsWith(`</${e}`)) {
needsClose = '>'
}
else if (code.endsWith(`<${e}`)) {
needsClose = '>'
}
}
else {
ELEMENTS[i] = ''
}
})
document[eleVal].innerHTML = code + needsClose + bodyHTML
}
}
var dTitle = document.title
var pTitle = parent.document.title
setInterval(function() {
if (document.title !== dTitle) {
dTitle = document.title
if (pTitle.includes(' | ')) {
parent.document.title = `${dTitle} | ${parent.title} | ${pTitle.split(' | ')[1]}`
}
else {
parent.document.title = `${dTitle} | ${parent.title} | ${pTitle}`
}
}
}, 1000)