From 6f4184b1606855763d6f36c3ea3f60e4b7d9697c Mon Sep 17 00:00:00 2001 From: Grason Chan Date: Sun, 4 Jul 2021 22:45:09 +0800 Subject: [PATCH] fix(Turntable): correctly control the rotation of the turntable, for spicetify v2.4.0 --- Turntable/rotateTurntable.js | 52 +++++++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 16 deletions(-) diff --git a/Turntable/rotateTurntable.js b/Turntable/rotateTurntable.js index 90be524..83e36e9 100644 --- a/Turntable/rotateTurntable.js +++ b/Turntable/rotateTurntable.js @@ -1,52 +1,72 @@ window.addEventListener("load", rotateTurntable = () => { - if (!Spicetify.Player.origin || !document.querySelector("#fad-art-image")) { + const fadBtn = document.querySelector(".main-topBar-button[title='Full App Display']"); + + if (!Spicetify.Player.origin || !fadBtn) { 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"; + fadArt && (fadArt.style.animationPlayState = "running"); return playState = true; } else { - fadArt.style.animationPlayState = "paused"; + fadArt && (fadArt.style.animationPlayState = "paused"); return playState = false; } } + function handleFadControl(event) { + event.stopPropagation(); + } + function handleFadDblclick() { const fadControlsBtns = document.querySelectorAll("#fad-controls button"); for (const fadControl of fadControlsBtns) { - fadControl.addEventListener("dblclick", event => event.stopPropagation()); + fadControl.addEventListener("dblclick", handleFadControl); } } + function handleConfigSwitch() { + const genericModal = document.querySelector("generic-modal"); + + handleInitalStatus(genericModal); + } + function handleInitalStatus(genericModal) { - if (genericModal) { - genericModal.remove(); - } + genericModal.remove(); handleRotate(); handleFadDblclick(); } - handleInitalStatus(); - - Spicetify.Player.addEventListener("onplaypause", () => handleRotate(true)); - - fullAppDisplay.addEventListener("contextmenu", () => { - const genericModal = document.querySelector("generic-modal"); + function handleContextMenu() { const configSwitchBtns = document.querySelectorAll("#popup-config-container button.switch"); for (const configSwitch of configSwitchBtns) { - configSwitch.addEventListener("click", () => handleInitalStatus(genericModal)); + configSwitch.addEventListener("click", handleConfigSwitch); } + } + + handleRotate(); + + Spicetify.Player.addEventListener("onplaypause", () => handleRotate(true)); + + fadBtn.addEventListener("click", () => { + const fullAppDisplay = document.querySelector("#full-app-display"); + const fadArt = document.querySelector("#fad-art-image"); + + playState + ? fadArt.style.animationPlayState = "running" + : fadArt.style.animationPlayState = "paused"; + + handleFadDblclick(); + + fullAppDisplay.addEventListener("contextmenu", handleContextMenu); }); });