Added updateLastPlayedSong function that drops first song from a table and inserts a new one at the bottom.
This commit is contained in:
parent
d3fb86dbdb
commit
784dc503a5
@ -1,4 +1,4 @@
|
||||
function getRadioStats() {
|
||||
function updateRadioStatus() {
|
||||
const $ = id => document.getElementById(id);
|
||||
|
||||
fetch("/stats")
|
||||
@ -17,6 +17,28 @@ function getRadioStats() {
|
||||
});
|
||||
}
|
||||
|
||||
function updateLastPlayedSong() {
|
||||
const $ = id => document.getElementById(id);
|
||||
|
||||
getRadioStats();
|
||||
setInterval(getRadioStats, 45000);
|
||||
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(); }
|
||||
|
||||
setInterval(updateRadioStatus, 45000);
|
||||
setInterval(updateLastPlayedSong, 45000);
|
Loading…
Reference in New Issue
Block a user