ctucx.git: webmusic-nginx

nginx xslt-based index files optimized for music, inspired by https://git.ztn.sh/zotan/webmusic

commit 4abc74c024995fb508c0493a8fcf1207a0b78b4a
parent 45dd844c9d098fbcb567f985d1eb1061e6581754
Author: ctucx <c@ctu.cx>
Date: Sat, 6 Mar 2021 20:36:43 +0100

webmusic.js: code improovements
1 file changed, 13 insertions(+), 8 deletions(-)
M
webmusic.js
|
21
+++++++++++++--------
diff --git a/webmusic.js b/webmusic.js
@@ -67,22 +67,26 @@ window.onkeyup = function (event) {
 
 
 function togglePlayback() {
-	if (sound.playing())
+	if (sound.playing()) {
 		sound.pause();
-	else
+	} else {
 		sound.play();
+	}
 }
 
 function setState(state) {
 	gstate = state;
+
 	console.log("now in state: " + state);
 	updateState();
 }
 
 
 function playSong(url) {
-	if (document.getElementsByClassName("playing").length > 0)
+	if (document.getElementsByClassName("playing").length > 0) {
 		document.getElementsByClassName("playing")[0].classList.remove("playing");
+	}
+
 	index = queue.indexOf(url);
 	sound.stop();
 	sound.unload();

@@ -134,8 +138,9 @@ function updateState() {
 	document.getElementById("state").setAttribute('onclick', 'togglePlayback()');
 	let statestr = "[";
 	statestr += gstate;
-	if (sound.playing())
+	if (sound.playing()) {
 		statestr += " " + formatTime(Math.round(sound.seek())) + "/" + formatTime(Math.round(sound.duration()));
+	}
 
 	statestr += "]";
 	document.getElementById("state").innerHTML = statestr;

@@ -157,16 +162,16 @@ function initState() {
 }
 
 function previousTrack() {
-	if (index-- === 0)
-		index = total-1;
+	if (index-- === 0) index = total-1;
+
 	if (continuelist) {
 		playSong(queue[index])
 	}
 }
 
 function nextTrack() {
-	if (++index === total)
-		index = 0;
+	if (++index === total) index = 0;
+
 	if (continuelist) {
 		playSong(queue[index])
 	}