1
0

Refactored main.js.

This commit is contained in:
Alexander Andreev 2023-08-22 04:18:30 +04:00
parent 82e2720156
commit 5e247f8d5c
Signed by: Arav
GPG Key ID: D22A817D95815393

View File

@ -35,24 +35,31 @@ function updateLastPlayedSong() {
document.getElementsByName("update")[0].addEventListener("click", () => { document.getElementsByName("update")[0].addEventListener("click", () => {
updateLastPlayedSong(); updateLastPlayedSong();
updateRadioStatus(); updateRadioStatus(); });
})
setInterval(updateRadioStatus, 45000); setInterval(updateRadioStatus, 45000);
setInterval(updateLastPlayedSong, 45000); setInterval(updateLastPlayedSong, 45000);
const audio = document.getElementsByTagName("audio")[0]; const volume = document.getElementsByName("volume");
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";
volume.addEventListener("input", e => { volume.addEventListener("input", e => {
audio.volume = parseFloat(e.target.value) / 100.0; }); 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 => { document.getElementsByName("play")[0].addEventListener("click", e => {
if (audio.paused) { if (audio.paused) {
audio.src = audio_src; 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 ? e.target.style.maskImage = e.target.style.webkitMaskImage = audio.paused ?
"url(/assets/img/play.svg)" : "url(/assets/img/stop.svg)"; }); "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`; });