diff options
Diffstat (limited to 'src/static')
| -rw-r--r-- | src/static/main.js | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/src/static/main.js b/src/static/main.js index 45b7f9b..0900c41 100644 --- a/src/static/main.js +++ b/src/static/main.js @@ -1,9 +1,23 @@ +topE = document.querySelector("#top"); +programE = document.querySelector("#program"); + async function update() { - const html = await (await fetch("/update")).text(); - document.querySelector("#top").innerHTML = html.split("\n").slice(0, 1)[0]; - document.querySelector("#program").outerHTML = html.split("\n").slice(1).join("\n"); + 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() + update() }, 5000); |
