summaryrefslogtreecommitdiff
path: root/src/static/main.js
blob: 0900c4121a67f2cafb38b05a5e5a8ff330b15687 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
topE = document.querySelector("#top");
programE = document.querySelector("#program");

async function update() {
	try {
		const response = await fetch("/update");
		if (response.status == 200) {
			html = await response.text();
			topE.innerHTML = html.split("\n").slice(0, 1)[0];
			programE.outerHTML = html.split("\n").slice(1).join("\n");
		}
	} catch (err) {
		// Happens when the server is closed / unreachable
		if (!topE.textContent.endsWith("❗")) {
			topE.textContent = (topE.textContent.slice(0, -1) || topE.textContent) + "❗";
		}
		console.log("Fetch failed:", err);
	}
}

setInterval(() => {
	update()
}, 5000);