diff --git a/web/assets/js/main.js b/web/assets/js/main.js index 069cad6..64e82ef 100644 --- a/web/assets/js/main.js +++ b/web/assets/js/main.js @@ -35,24 +35,31 @@ function updateLastPlayedSong() { document.getElementsByName("update")[0].addEventListener("click", () => { updateLastPlayedSong(); - updateRadioStatus(); -}) + updateRadioStatus(); }); setInterval(updateRadioStatus, 45000); setInterval(updateLastPlayedSong, 45000); -const audio = document.getElementsByTagName("audio")[0]; -const volume = document.getElementsByName("volume")[0]; - -const audio_src = audio.childNodes[0].src; -audio.hidden = true; -audio.volume = parseFloat(volume.value) / 100.0; -document.querySelector("#player div:first-child").style.display = "flex"; -$("player").style.display = "flex"; +const volume = document.getElementsByName("volume"); volume.addEventListener("input", e => { audio.volume = parseFloat(e.target.value) / 100.0; }); +const audio = document.getElementsByTagName("audio")[0]; +const audio_src = audio.childNodes[0].src; +audio.hidden = true; +audio.volume = parseFloat(volume.value) / 100.0; + +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); + document.getElementsByClassName("elapsed")[0].textContent = `${h}h ${m}m ${s}s`; }); + +$("player").firstChild.style.display = "flex"; +$("player").style.display = "flex"; + document.getElementsByName("play")[0].addEventListener("click", e => { if (audio.paused) { audio.src = audio_src; @@ -63,10 +70,3 @@ document.getElementsByName("play")[0].addEventListener("click", e => { } e.target.style.maskImage = e.target.style.webkitMaskImage = 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); - document.getElementsByClassName("elapsed")[0].textContent = `${h}h ${m}m ${s}s`; });