From 5cb616a78c0cca0b12c65709937a4535b5aace7c Mon Sep 17 00:00:00 2001 From: Grason Chan Date: Sun, 4 Jul 2021 12:40:40 +0800 Subject: [PATCH] fix(Turntable): correctly control the rotation of the turntable --- Turntable/rotateTurntable.js | 52 +++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/Turntable/rotateTurntable.js b/Turntable/rotateTurntable.js index 125b94a..1439e4d 100644 --- a/Turntable/rotateTurntable.js +++ b/Turntable/rotateTurntable.js @@ -1,30 +1,34 @@ -window.addEventListener("load", () => { - (function rotateTurntable() { - if (!Spicetify.Player.origin || !document.querySelector("#fad-art-image")) { - setTimeout(rotateTurntable, 250); - return; +window.addEventListener("load", rotateTurntable = () => { + if (!Spicetify.Player.origin || !document.querySelector("#fad-art-image")) { + setTimeout(rotateTurntable, 250); + return; + } + + const fullAppDisplay = document.querySelector("#full-app-display"); + + let playState; + + function handleRotate(fromEvent) { + const fadArt = document.querySelector("#fad-art-image"); + + if (!fromEvent && Spicetify.Player.isPlaying() || fromEvent && !playState) { + fadArt.style.animationPlayState = "running"; + return playState = true; + } else { + fadArt.style.animationPlayState = "paused"; + return playState = false; } + } - const fullAppDisplay = document.querySelector("#full-app-display"); + handleRotate(); - function handleRotate() { - const fadArt = document.querySelector("#fad-art-image"); + Spicetify.Player.addEventListener("onplaypause", () => handleRotate(true)); - Spicetify.Player.isPlaying() - ? fadArt.style.animationPlayState = "running" - : fadArt.style.animationPlayState = "paused"; + fullAppDisplay.addEventListener("contextmenu", () => { + const configSwitchBtns = document.querySelectorAll("#popup-config-container button.switch"); + + for (const configSwitch of configSwitchBtns) { + configSwitch.addEventListener("click", () => handleRotate()); } - - handleRotate(); - - Spicetify.Player.addEventListener("onplaypause", () => setTimeout(handleRotate)); - - fullAppDisplay.addEventListener("contextmenu", () => { - const configSwitchBtns = document.querySelectorAll("#popup-config-container button.switch"); - - for (const configSwitch of configSwitchBtns) { - configSwitch.addEventListener("click", handleRotate); - } - }); - })(); + }); });