2021-09-01 22:14:08 +04:00
|
|
|
function updateRadioStatus() {
|
2021-02-10 01:01:50 +04:00
|
|
|
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";
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-09-01 22:14:08 +04:00
|
|
|
function updateLastPlayedSong() {
|
|
|
|
const $ = id => document.getElementById(id);
|
|
|
|
|
|
|
|
fetch('/lastsong')
|
|
|
|
.then(r => r.json())
|
|
|
|
.then(last_played => {
|
|
|
|
let { cur_artist, cur_song } = $('radio-song').innerText.split(' - ');
|
|
|
|
|
|
|
|
if (last_played.artist == cur_artist && last_played.title == cur_song)
|
|
|
|
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));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function updateAll() { updateRadioStatus(); updateLastPlayedSong(); }
|
2021-02-10 01:01:50 +04:00
|
|
|
|
2021-09-01 22:14:08 +04:00
|
|
|
setInterval(updateRadioStatus, 45000);
|
|
|
|
setInterval(updateLastPlayedSong, 45000);
|