Refresh queue regularly

This commit is contained in:
Joscha 2023-08-06 20:49:07 +02:00
parent ad5da60b5a
commit 6af47b8c30
3 changed files with 23 additions and 9 deletions

View file

@ -1,6 +0,0 @@
function main() {
alert("Hello world!");
}
const BUTTON = document.getElementById("button");
BUTTON?.addEventListener("click", main);

16
static/queue/main.ts Normal file
View file

@ -0,0 +1,16 @@
const COUNT = document.getElementById("count")!;
const QUEUE = document.getElementById("queue")!;
const REFRESH_SECONDS = 10;
function update() {
fetch("table")
.then(response => response.text())
.then(text => {
QUEUE.innerHTML = text;
let count = QUEUE.querySelectorAll("tbody tr").length;
COUNT.textContent = String(count);
document.title = document.title.replace(/^queue \(\d+\)/, `queue (${count})`);
});
}
setInterval(update, REFRESH_SECONDS * 1000);