From 4b8a66b60fd77b119ca85ef480804ff35e51f611 Mon Sep 17 00:00:00 2001 From: murtaugh Date: Thu, 28 May 2020 11:49:31 +0200 Subject: [PATCH] Update '12/liveplayer.js' --- 12/liveplayer.js | 46 +++++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/12/liveplayer.js b/12/liveplayer.js index c0f6527..54ec6d2 100644 --- a/12/liveplayer.js +++ b/12/liveplayer.js @@ -1,21 +1,29 @@ -(function () { -var last_timestamp; - -async function poll () { - var rows = await (await fetch("/cgi-bin/radioimplicancies.cgi")).json(); - console.log("rows", rows); - if (rows) { - // get the last (most recent) item - var d = rows[rows.length-1]; - if (d.time && d.time != last_timestamp) { - console.log("CURRENT METADATA", d); - last_timestamp = d.time; +function liveplayer (elt) { + var last_timestamp; + + async function poll () { + var rows = await (await fetch("/cgi-bin/radioimplicancies.cgi")).json(); + // console.log("rows", rows); + if (rows) { + // get the last (most recent) item + var d = rows[rows.length-1]; + if (d.time && d.time != last_timestamp) { + last_timestamp = d.time; + console.log("CURRENT METADATA", d); + var old_nowplaying = elt.querySelector(".nowplaying"); + if (old_nowplaying) { + old_nowplaying.classList.remove("nowplaying"); + } + var nowplaying = elt.querySelector(d.title); + if (nowplaying) { + nowplaying.classList.add("nowplaying"); + } + + } } - } -} - -window.setInterval(poll, 5000); + } - - -})(); \ No newline at end of file + window.setInterval(poll, 5000); +} + +liveplayer(document); \ No newline at end of file