From 8a5666743f2fb24861bafc5d2170d4e0ae035271 Mon Sep 17 00:00:00 2001 From: "Alexander \"Arav\" Andreev" Date: Tue, 22 Aug 2023 16:50:27 +0400 Subject: [PATCH] Further code shortening in main.js! --- web/assets/js/main.js | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/web/assets/js/main.js b/web/assets/js/main.js index 5764ff6..80a543b 100644 --- a/web/assets/js/main.js +++ b/web/assets/js/main.js @@ -36,15 +36,15 @@ $("radio-update").addEventListener("click", () => { setInterval(updateRadioStatus, 45000); setInterval(updateLastPlayedSong, 45000); +const audio = document.getElementsByTagName("audio")[0]; +audio.hidden = true; +const audio_src = audio.childNodes[0].src; + const volume = $("radio-volume"); -volume.addEventListener("input", e => { - audio.volume = parseFloat(e.target.value) / 100.0; }); +audio.volume = volume.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; +volume.addEventListener("input", e => audio.volume = e.target.value / 100.0); audio.addEventListener("timeupdate", e => { const ct = e.target.currentTime; @@ -53,14 +53,9 @@ audio.addEventListener("timeupdate", e => { const h = Math.floor(ct / 3600); $("radio-elapsed").textContent = `${h}h ${m}m ${s}s`; }); -$("player").style.display = - $("player").firstChild.style.display = "flex"; +$("player").style.display = $("player").firstChild.style.display = "flex"; $("radio-play").addEventListener("click", e => { - if (audio.paused) { - audio.src = audio_src; - audio.play(); - } else - audio.src = ""; + audio.paused ? (audio.src = audio_src) && audio.play() : audio.src = ""; e.target.style.maskImage = e.target.style.webkitMaskImage = audio.paused ? "url(/assets/img/play.svg)" : "url(/assets/img/stop.svg)"; });