function liveplayer (elt) { var last_timestamp, DELAY_TIME_SECS = 20; 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("liveplayer: current metadata", d); window.setTimeout(function () { var old_nowplaying = elt.querySelector(".now_playing"); if (old_nowplaying) { old_nowplaying.classList.remove("now_playing"); } var nowplaying = elt.querySelector("#"+d.title); if (nowplaying) { console.log("liveplayer: nowplaying", nowplaying); nowplaying.classList.add("now_playing"); } else { console.log("liveplayer: warning no div matching title " + d.title); } }, DELAY_TIME_SECS*1000); } } } window.setInterval(poll, 5000); }