Refactored main.js.
This commit is contained in:
parent
82e2720156
commit
5e247f8d5c
@ -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`; });
|
||||
|
Loading…
Reference in New Issue
Block a user