41 lines
1.3 KiB
JavaScript
41 lines
1.3 KiB
JavaScript
function $(id) { return document.getElementById(id); }
|
|
|
|
function updateRadioStatus() {
|
|
fetch("/stats")
|
|
.then(r => r.json())
|
|
.then(r => {
|
|
$("radio-status").innerHTML =
|
|
`On-air since <time datetime="${r.server_start_iso8601}">${r.server_start_date}</time>`;
|
|
$("radio-song").textContent = r.song;
|
|
$("radio-listeners").textContent = r.listeners;
|
|
$("radio-listener-peak").textContent = r.listener_peak;
|
|
}).catch(() => {
|
|
$("radio-status").textContent = "Radio is offline.";
|
|
$("radio-song").textContent =
|
|
$("radio-listeners").textContent =
|
|
$("radio-listener-peak").textContent = "n/a";
|
|
});
|
|
}
|
|
|
|
function updateLastPlayedSong() {
|
|
fetch('/lastsong')
|
|
.then(r => r.json())
|
|
.then(last_played => {
|
|
let cur_artist = $('last-played').firstChild.lastChild.firstChild.innerText;
|
|
let cur_title = $('last-played').firstChild.lastChild.lastChild.innerText;
|
|
|
|
if (last_played.artist == cur_artist && last_played.title == cur_title)
|
|
return;
|
|
|
|
$('last-played').firstChild.firstChild.remove();
|
|
|
|
let row = $('last-played').insertRow();
|
|
let artist_cell = row.insertCell();
|
|
artist_cell.appendChild(document.createTextNode(last_played.artist));
|
|
let title_cell = row.insertCell();
|
|
title_cell.appendChild(document.createTextNode(last_played.title));
|
|
});
|
|
}
|
|
|
|
setInterval(updateRadioStatus, 45000);
|
|
setInterval(updateLastPlayedSong, 45000); |