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