Added updateLastPlayedSong function that drops first song from a table and inserts a new one at the bottom.

This commit is contained in:
Alexander Andreev 2021-09-01 22:14:08 +04:00
parent d3fb86dbdb
commit 784dc503a5
Signed by: Arav
GPG Key ID: 610DF2574456329F

View File

@ -1,4 +1,4 @@
function getRadioStats() { function updateRadioStatus() {
const $ = id => document.getElementById(id); const $ = id => document.getElementById(id);
fetch("/stats") fetch("/stats")
@ -17,6 +17,28 @@ function getRadioStats() {
}); });
} }
function updateLastPlayedSong() {
const $ = id => document.getElementById(id);
getRadioStats(); fetch('/lastsong')
setInterval(getRadioStats, 45000); .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(); }
setInterval(updateRadioStatus, 45000);
setInterval(updateLastPlayedSong, 45000);