commit 5b35aa858f3996740bd973eb16c4eb39e25eec7d
parent eed52e44922c9b8cc8dd04b026eb5efa6a9bf8ef
Author: ctucx <c@ctu.cx>
Date: Sat, 6 Mar 2021 20:31:24 +0100
parent eed52e44922c9b8cc8dd04b026eb5efa6a9bf8ef
Author: ctucx <c@ctu.cx>
Date: Sat, 6 Mar 2021 20:31:24 +0100
webmusic.js: replace ifs with switch
1 file changed, 41 insertions(+), 31 deletions(-)
diff --git a/webmusic.js b/webmusic.js @@ -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; } };