Dwelling/radio/static/assets/js/main.js

22 lines
675 B
JavaScript

function getRadioStats() {
const $ = id => document.getElementById(id);
fetch("/stats")
.then(r => r.json())
.then(radio => {
$("radio-status").innerHTML =
`On-air since <time datetime="${radio.server_start_iso8601}">${radio.server_start_date}</time>`;
$("radio-song").textContent = radio.song;
$("radio-listeners").textContent = radio.listeners;
$("radio-listener-peak").textContent = radio.listener_peak;
}).catch(() => {
$("radio-status").textContent = "Now is offline";
$("radio-song").textContent =
$("radio-listeners").textContent =
$("radio-listener-peak").textContent = "n/a";
});
}
getRadioStats();
setInterval(getRadioStats, 45000);