summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorctucx <c@ctu.cx>2021-03-06 20:31:24 +0100
committerctucx <c@ctu.cx>2021-03-06 20:31:24 +0100
commit5b35aa858f3996740bd973eb16c4eb39e25eec7d (patch)
treea6286fb1055f5657f0d6a8a1733bc6654ffa8c8c
parenteed52e44922c9b8cc8dd04b026eb5efa6a9bf8ef (diff)
webmusic.js: replace ifs with switch
-rw-r--r--webmusic.js72
1 files changed, 41 insertions, 31 deletions
diff --git a/webmusic.js b/webmusic.js
index 2864bcd..2b9323d 100644
--- 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;
}
};