Decouple color update rate from background query
This commit is contained in:
parent
d6650842af
commit
8717dae916
19
script.js
19
script.js
@ -2,7 +2,7 @@
|
|||||||
// @name Spotify Background Changer
|
// @name Spotify Background Changer
|
||||||
// @namespace http://tampermonkey.net/
|
// @namespace http://tampermonkey.net/
|
||||||
// @source https://github.com/Glaceon575/SpotifyBackgroundSwitcher
|
// @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
|
// @description Changes the background of Spotify playlists and albums in a rainbow pattern
|
||||||
// @author Isaac Shoebottom
|
// @author Isaac Shoebottom
|
||||||
// @updateURL https://raw.githubusercontent.com/Glaceon575/SpotifyBackgroundSwitcher/master/script.js
|
// @updateURL https://raw.githubusercontent.com/Glaceon575/SpotifyBackgroundSwitcher/master/script.js
|
||||||
@ -14,8 +14,9 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
let background;
|
let background;
|
||||||
const selector = ".gHImFiUWOg93pvTefeAD.xYgjMpAjE5XT05aRIezb";
|
let colorInterval;
|
||||||
|
|
||||||
|
const selector = ".gHImFiUWOg93pvTefeAD.xYgjMpAjE5XT05aRIezb";
|
||||||
const timer = 33; //in milliseconds
|
const timer = 33; //in milliseconds
|
||||||
const probeTimer = 500 //in milliseconds, timer for checking for selector
|
const probeTimer = 500 //in milliseconds, timer for checking for selector
|
||||||
const difference = 60; //delta between the top and bottom
|
const difference = 60; //delta between the top and bottom
|
||||||
@ -46,20 +47,16 @@ function changeColor() {
|
|||||||
|
|
||||||
|
|
||||||
function probeBackground() {
|
function probeBackground() {
|
||||||
console.log("probing background");
|
console.log("Probing for background");
|
||||||
const interval = setInterval(() => {
|
setInterval(() => {
|
||||||
const newBackground = document.querySelector(selector);
|
const newBackground = document.querySelector(selector);
|
||||||
if (!newBackground) {
|
if (!newBackground) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!background) {
|
if (newBackground !== background) {
|
||||||
|
clearInterval(colorInterval);
|
||||||
|
colorInterval = setInterval(changeColor, timer)
|
||||||
background = newBackground;
|
background = newBackground;
|
||||||
}
|
}
|
||||||
if (!newBackground.isSameNode(background)) {
|
|
||||||
background = newBackground;
|
|
||||||
clearInterval(interval);
|
|
||||||
probeBackground();
|
|
||||||
}
|
|
||||||
changeColor();
|
|
||||||
}, probeTimer);
|
}, probeTimer);
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user