-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
46 lines (46 loc) · 1.47 KB
/
main.js
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
window.setInterval(() => {
const body = fetch("/ping", {
method: 'GET',
}).then(body => {
body.text().then(str => {
if (str && str !== 'null') {
const res = JSON.parse(str);
if (res) {
for (const val of res) {
for (const [id, value] of Object.entries(val)) {
if (id === '$$$evaluate') {
eval(value);
} else
if (id === 'console') {
console.log(value);
} else {
console.log('dom:', id, value);
const el = document.getElementById(id);
if (el) {
el.innerHTML = value;
}
}
}
}
}
}
});
});
}, pingTimeMs);
async function sendObject(object) {
try {
const body = await fetch("/exchange", {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(object)
});
const str = await body.text();
const res = JSON.parse(str);
return res || {};
} catch (error) {
console.log(error);
}
return {};
}