2022-03-08 01:17:24 +04:00
|
|
|
function $(id) { return document.getElementById(id); }
|
|
|
|
|
|
|
|
function updateRadioStatus() {
|
2022-05-24 18:49:24 +04:00
|
|
|
fetch("/status")
|
2022-03-08 01:17:24 +04:00
|
|
|
.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.";
|
2022-05-24 18:52:39 +04:00
|
|
|
$("radio-song").textContent = "";
|
|
|
|
$("radio-listeners").textContent =
|
|
|
|
$("radio-listener-peak").textContent = "0";
|
2022-03-08 01:17:24 +04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function updateLastPlayedSong() {
|
|
|
|
fetch('/lastsong')
|
|
|
|
.then(r => r.json())
|
|
|
|
.then(last_played => {
|
2023-03-12 21:57:03 +04:00
|
|
|
if ($('last-played').firstChild === null)
|
|
|
|
$('last-played').appendChild(document.createElement("tbody"))
|
2023-06-12 21:50:10 +04:00
|
|
|
else if (last_played.time == $('last-played').firstChild.lastChild.firstChild.innerText)
|
|
|
|
return;
|
2022-03-08 01:17:24 +04:00
|
|
|
|
2023-03-12 21:50:06 +04:00
|
|
|
if ($('last-played').firstChild.children.length == 10)
|
|
|
|
$('last-played').firstChild.firstChild.remove();
|
2022-03-08 01:17:24 +04:00
|
|
|
|
|
|
|
let row = $('last-played').insertRow();
|
2022-04-01 18:42:13 +04:00
|
|
|
row.insertCell().appendChild(document.createTextNode(last_played.time));
|
|
|
|
row.insertCell().appendChild(document.createTextNode(last_played.listeners == 0 ? "" : last_played.listeners));
|
|
|
|
row.insertCell().appendChild(document.createTextNode(last_played.song));
|
2022-03-08 01:17:24 +04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
document.getElementById("btn-update").addEventListener("click", () => {
|
|
|
|
updateLastPlayedSong();
|
|
|
|
updateRadioStatus();
|
|
|
|
})
|
|
|
|
|
|
|
|
setInterval(updateRadioStatus, 45000);
|
2023-08-20 01:20:28 +04:00
|
|
|
setInterval(updateLastPlayedSong, 45000);
|
|
|
|
|
|
|
|
let audio = document.getElementsByTagName("audio")[0];
|
|
|
|
let volume = $("volume");
|
|
|
|
|
2023-08-20 02:10:29 +04:00
|
|
|
const audio_src = audio.childNodes[0].src;
|
2023-08-20 01:20:28 +04:00
|
|
|
audio.hidden = true;
|
|
|
|
audio.volume = parseFloat(volume.value) / 100.0;
|
|
|
|
document.querySelector("div.player").style.display = "flex";
|
|
|
|
$("radio").style.display = "flex";
|
|
|
|
|
|
|
|
$("play").addEventListener("click", e => {
|
2023-08-20 02:10:29 +04:00
|
|
|
if (audio.paused) {
|
|
|
|
audio.src = audio_src;
|
|
|
|
audio.play();
|
|
|
|
} else {
|
|
|
|
audio.pause();
|
|
|
|
audio.src = "";
|
|
|
|
}
|
2023-08-20 01:20:28 +04:00
|
|
|
e.target.style.maskImage = audio.paused ? "url(/assets/img/play.svg)" : "url(/assets/img/stop.svg)"; });
|
|
|
|
|
|
|
|
audio.addEventListener("timeupdate", e => {
|
|
|
|
const ct = e.target.currentTime;
|
|
|
|
const s = Math.floor(ct % 60);
|
|
|
|
const m = Math.floor((ct / 60) % 60);
|
|
|
|
const h = Math.floor(ct / 3600);
|
|
|
|
$("cur-time").textContent = `${h}h ${m}m ${s}s`; });
|
|
|
|
|
|
|
|
volume.addEventListener("input", e => {
|
|
|
|
audio.volume = parseFloat(e.target.value) / 100.0; });
|
|
|
|
|
|
|
|
$("vol-up").addEventListener("click", () => {
|
|
|
|
volume.value = +volume.value + 10; audio.volume = +volume.value / 100.0; });
|
|
|
|
$("vol-down").addEventListener("click", () => {
|
|
|
|
volume.value -= 10; audio.volume = +volume.value / 100.0; });
|