webmusic.js: replace ifs with switch

This commit is contained in:
Leah 2021-03-06 20:31:24 +01:00 committed by Leah (ctucx)
parent 0000568e2b
commit e19f06a9d0

View file

@ -21,37 +21,47 @@ window.onload = function () {
}; };
window.onkeyup = function (event) { window.onkeyup = function (event) {
if (event.key === " " || event.key === "p") { switch (event.key) {
if (gstate !== "idle") { case " ":
togglePlayback(); case "p":
} else { if (gstate == "idle" && total !== 0) {
playSong(queue[0]) playSong(queue[0])
} } else {
} togglePlayback();
else if (event.key === "r") { }
toggleRepeat(); break;
}
else if (event.key === "c") { case "r":
toggleContinue(); toggleRepeat();
} break;
else if (event.key === "ArrowUp") {
previousTrack(); case "c":
} toggleContinue();
else if (event.key === "ArrowDown") { break;
nextTrack();
} case "ArrowUp":
else if (event.key === "ArrowLeft") { previousTrack();
if (sound.seek() < 10) { break;
sound.seek(0);
} else { case "ArrowDown":
sound.seek(sound.seek()-10); nextTrack();
} break;
}
else if (event.key === "ArrowRight") { case "ArrowLeft":
sound.seek(sound.seek()+10); if (sound.seek() < 10) {
} sound.seek(0);
else if (event.key === "Escape") { } else {
document.getElementById("back").click(); sound.seek(sound.seek()-10);
}
break;
case "ArrowRight":
sound.seek(sound.seek()+10);
break;
case "Escape":
document.getElementById("back").click();
break;
} }
}; };