From 8717dae916ad96f2f38907aad1effb770741683c Mon Sep 17 00:00:00 2001 From: Isaac Shoebottom Date: Sun, 3 Jul 2022 01:34:10 -0300 Subject: [PATCH] Decouple color update rate from background query --- script.js | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/script.js b/script.js index 2974bde..faec032 100644 --- a/script.js +++ b/script.js @@ -2,7 +2,7 @@ // @name Spotify Background Changer // @namespace http://tampermonkey.net/ // @source https://github.com/Glaceon575/SpotifyBackgroundSwitcher -// @version 0.1.1 +// @version 0.1.2 // @description Changes the background of Spotify playlists and albums in a rainbow pattern // @author Isaac Shoebottom // @updateURL https://raw.githubusercontent.com/Glaceon575/SpotifyBackgroundSwitcher/master/script.js @@ -14,8 +14,9 @@ "use strict"; let background; -const selector = ".gHImFiUWOg93pvTefeAD.xYgjMpAjE5XT05aRIezb"; +let colorInterval; +const selector = ".gHImFiUWOg93pvTefeAD.xYgjMpAjE5XT05aRIezb"; const timer = 33; //in milliseconds const probeTimer = 500 //in milliseconds, timer for checking for selector const difference = 60; //delta between the top and bottom @@ -46,20 +47,16 @@ function changeColor() { function probeBackground() { - console.log("probing background"); - const interval = setInterval(() => { + console.log("Probing for background"); + setInterval(() => { const newBackground = document.querySelector(selector); if (!newBackground) { return; } - if (!background) { + if (newBackground !== background) { + clearInterval(colorInterval); + colorInterval = setInterval(changeColor, timer) background = newBackground; } - if (!newBackground.isSameNode(background)) { - background = newBackground; - clearInterval(interval); - probeBackground(); - } - changeColor(); }, probeTimer); } \ No newline at end of file