-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathscript.h
28 lines (27 loc) · 888 Bytes
/
script.h
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
/*
This is the javaScript file. You can take a JavaScript, paste it here in quotes,
add \ at the end of each line, escape the internal quotes with \, and you're done
*/
#define SCRIPTJS "function setup(event) { \
console.log(\"begin\"); \
setInterval(fetchJSON, 3000); \
} \
function fetchJSON() { \
fetch(\'/readings\') \
.then(response => response.json()) \
.then(data => getResponse(data)) \
.catch(error => getResponse(error)); \
} \
function getResponse(data) { \
console.log(data); \
for (property in data) { \
let label = property; \
let value = data[property]; \
console.log(label); \
console.log(value); \
if (document.getElementById(label) != null) { \
document.getElementById(label).innerHTML = value; \
} \
} \
} \
window.addEventListener(\'DOMContentLoaded\', setup);"