From a2973f463a108fc55433987972759106fa888be3 Mon Sep 17 00:00:00 2001 From: Grason Chan Date: Tue, 26 Oct 2021 00:37:19 +0800 Subject: [PATCH] fix(Turntable): hide the song preview when the queue is the same song --- Turntable/rotateTurntable.js | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/Turntable/rotateTurntable.js b/Turntable/rotateTurntable.js index b5fae4a..4cb6621 100644 --- a/Turntable/rotateTurntable.js +++ b/Turntable/rotateTurntable.js @@ -96,32 +96,25 @@ window.addEventListener("load", rotateTurntable = () => { function handleTracksNamePreview() { const prevTracks = Spicetify.Queue.prevTracks; + const currentTrack = Spicetify.Queue.track; const nextTracks = Spicetify.Queue.nextTracks; - // let prevTracksIndexRefer = 1; - // let nextTracksIndexRefer = 0; - - // while ( - // prevTracks[prevTracks.length - prevTracksIndexRefer].metadata.hidden - // || - // prevTracks[prevTracks.length - prevTracksIndexRefer].provider == "ad" - // ) ++prevTracksIndexRefer; - // previousSong.innerHTML = `< ${prevTracks[prevTracks.length - prevTracksIndexRefer].metadata.title}`; - - // while ( - // nextTracks[nextTracksIndexRefer].metadata.hidden - // || - // nextTracks[nextTracksIndexRefer].provider == "ad" - // ) ++nextTracksIndexRefer; - // nextSong.innerHTML = `${nextTracks[nextTracksIndexRefer].metadata.title} >`; - trackCondition = element => !element.contextTrack.metadata.hidden && element.provider != "ad"; const prevTrack = prevTracks.slice().reverse().find(trackCondition); - previousSong.innerHTML = `< ${prevTrack.contextTrack.metadata.title}`; - const nextTrack = nextTracks.find(trackCondition); - nextSong.innerHTML = `${nextTrack.contextTrack.metadata.title} >`; + + const prevTrackTitle = prevTrack.contextTrack.metadata.title; + const currentTrackTitle = currentTrack.contextTrack.metadata.title; + const nextTrackTitle = nextTrack.contextTrack.metadata.title; + + if (currentTrackTitle === prevTrackTitle && currentTrackTitle === nextTrackTitle) { + previousSong.innerHTML = ""; + nextSong.innerHTML = ""; + } else { + previousSong.innerHTML = `< ${prevTrackTitle}`; + nextSong.innerHTML = `${nextTrackTitle} >`; + } } function handleConfigSwitch() {