2021-09-08 17:21:46 +04:00
|
|
|
function $(id) { return document.getElementById(id); }
|
2021-02-10 01:01:50 +04:00
|
|
|
|
2021-09-08 17:21:46 +04:00
|
|
|
function updateRadioStatus() {
|
2021-02-10 01:01:50 +04:00
|
|
|
fetch("/stats")
|
|
|
|
.then(r => r.json())
|
2021-12-01 02:19:38 +04:00
|
|
|
.then(r => {
|
2021-02-10 01:01:50 +04:00
|
|
|
$("radio-status").innerHTML =
|
2021-12-01 02:19:38 +04:00
|
|
|
`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;
|
2021-02-10 01:01:50 +04:00
|
|
|
}).catch(() => {
|
2021-12-01 02:19:38 +04:00
|
|
|
$("radio-status").textContent = "Radio is offline.";
|
2021-02-10 01:01:50 +04:00
|
|
|
$("radio-song").textContent =
|
|
|
|
$("radio-listeners").textContent =
|
|
|
|
$("radio-listener-peak").textContent = "n/a";
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-09-01 22:14:08 +04:00
|
|
|
function updateLastPlayedSong() {
|
|
|
|
fetch('/lastsong')
|
|
|
|
.then(r => r.json())
|
|
|
|
.then(last_played => {
|
2022-01-22 19:04:33 +04:00
|
|
|
let cur_artist = $('last-played').firstChild.lastChild.children[1].innerText;
|
2021-09-02 01:13:02 +04:00
|
|
|
let cur_title = $('last-played').firstChild.lastChild.lastChild.innerText;
|
2021-09-01 22:14:08 +04:00
|
|
|
|
2021-09-02 01:13:02 +04:00
|
|
|
if (last_played.artist == cur_artist && last_played.title == cur_title)
|
2021-09-01 22:14:08 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
$('last-played').firstChild.firstChild.remove();
|
|
|
|
|
|
|
|
let row = $('last-played').insertRow();
|
2022-01-22 19:04:33 +04:00
|
|
|
let start_time = row.insertCell();
|
|
|
|
start_time.appendChild(document.createTextNode(last_played.start_time_local));
|
2021-09-01 22:14:08 +04:00
|
|
|
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));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-01-22 19:04:33 +04:00
|
|
|
document.getElementById("btn-update").addEventListener("click", () => {
|
|
|
|
updateLastPlayedSong();
|
|
|
|
updateRadioStatus();
|
|
|
|
})
|
|
|
|
|
2021-09-01 22:14:08 +04:00
|
|
|
setInterval(updateRadioStatus, 45000);
|
|
|
|
setInterval(updateLastPlayedSong, 45000);
|