From f4835ffdcb80ed5fa711ea9b33b295dae36258b2 Mon Sep 17 00:00:00 2001 From: "user@node5.net" Date: Mon, 29 Jun 2026 23:03:07 +0200 Subject: web: fetch with js to avoid flickering --- src/static/main.js | 36 +++++++----------------------------- 1 file changed, 7 insertions(+), 29 deletions(-) (limited to 'src/static') diff --git a/src/static/main.js b/src/static/main.js index 7bea389..86cda7e 100644 --- a/src/static/main.js +++ b/src/static/main.js @@ -1,31 +1,9 @@ -const url = '/text'; -const parts = ["top", "program"]; -const elements = {}; - -function get_element(part){ - elements[part] = document.getElementById(part); -} - -const program_element = parts.forEach(get_element); - -function set_element_text(part, text){ - elements[part].innerHTML = text; +async function update() { + const html = await (await fetch("/update")).text(); + document.querySelector("#top").innerHTML = html.split("\n").slice(0, 1)[0]; + document.querySelector("#program").innerHTML = html.split("\n").slice(1).join("\n"); } -async function getEvents() { - try { - const response = await fetch(url); - if (!response.ok) { - throw new Error(`Response status: ${response.status}`); - } - - const events = await response.json(); - console.log(events) - - } catch (error) { - console.error(error.message); - } -} - -getEvents(); - +setInterval(() => { + update() +}, 5000); -- cgit v1.3.1