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
1 changed files with 41 additions and 31 deletions

View File

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