Updated main.js. Added a new update() function that does everything. Not completed yet.
This commit is contained in:
parent
35429e57d2
commit
c2c8c82212
@ -1,5 +1,19 @@
|
||||
const $ = id => document.getElementById(id);
|
||||
|
||||
function update() {
|
||||
fetch("/api/status")
|
||||
.then(r => r.json())
|
||||
.then(r => {
|
||||
$("radio-song").textContent = `${r.current_song.artist} - ${r.current_song.title}`;
|
||||
$("radio-duration").textContent = r.current_song.duration;
|
||||
$("radio-listeners").textContent = r.listeners.current;
|
||||
$("radio-listener-peak").textContent = r.listeners.peak;
|
||||
}).catch(() => {
|
||||
$("radio-song").textContent = "";
|
||||
$("radio-listeners").textContent =
|
||||
$("radio-listener-peak").textContent = "0"; });
|
||||
}
|
||||
|
||||
function updateRadioStatus() {
|
||||
fetch("/status")
|
||||
.then(r => r.json())
|
||||
@ -29,12 +43,9 @@ function updateLastPlayedSong() {
|
||||
row.insertCell().appendChild(document.createTextNode(last_played.listeners == 0 ? "" : last_played.listeners));
|
||||
row.insertCell().appendChild(document.createTextNode(last_played.song)); }); }
|
||||
|
||||
$("radio-update").addEventListener("click", () => {
|
||||
updateLastPlayedSong();
|
||||
updateRadioStatus(); });
|
||||
$("radio-update").addEventListener("click", () => update());
|
||||
|
||||
setInterval(updateRadioStatus, 45000);
|
||||
setInterval(updateLastPlayedSong, 45000);
|
||||
setInterval(update, 45000);
|
||||
|
||||
const audio = document.getElementsByTagName("audio")[0];
|
||||
audio.hidden = true;
|
||||
|
Loading…
Reference in New Issue
Block a user