SpotifyBackgroundSwitcher/script.js

64 lines
2.0 KiB
JavaScript
Raw Normal View History

2022-06-29 04:49:59 -03:00
// ==UserScript==
2022-07-03 01:15:11 -03:00
// @name Spotify Background Changer
2022-06-29 04:49:59 -03:00
// @namespace http://tampermonkey.net/
2022-09-13 09:27:11 -03:00
// @source https://github.com/IsaacShoebottom/SpotifyBackgroundSwitcher
2022-07-03 01:46:11 -03:00
// @version 0.1.5
2022-06-29 04:49:59 -03:00
// @description Changes the background of Spotify playlists and albums in a rainbow pattern
2022-06-29 05:03:34 -03:00
// @author Isaac Shoebottom
2022-09-13 09:26:45 -03:00
// @updateURL https://raw.githubusercontent.com/IsaacShoebottom/SpotifyBackgroundSwitcher/master/script.js
// @downloadURL https://raw.githubusercontent.com/IsaacShoebottom/SpotifyBackgroundSwitcher/master/script.js
2022-06-30 13:54:58 -03:00
// @match https://open.spotify.com/*
2022-06-29 04:49:59 -03:00
// @grant none
// ==/UserScript==
"use strict";
let background;
let colorInterval;
2022-06-29 04:49:59 -03:00
const selector = ".gHImFiUWOg93pvTefeAD.xYgjMpAjE5XT05aRIezb";
2022-07-03 01:38:46 -03:00
const timer = 16; //in milliseconds
const probeTimer = 500 //in milliseconds, timer for checking for selector
const difference = 60; //delta between the top and bottom
2022-06-29 05:18:23 -03:00
const start = {
intensity: 235,
darkness: 75,
};
2022-06-29 04:49:59 -03:00
// [r, g, b]
const color = [start.intensity, start.darkness, start.darkness];
2022-06-29 04:49:59 -03:00
let isIncrease = true;
let currentColor = 2;
2022-06-29 04:49:59 -03:00
function changeColor() {
if (color[currentColor] === (isIncrease ? start.intensity : start.darkness)) {
isIncrease = !isIncrease;
currentColor = (currentColor + 1) % 3;
} else {
color[currentColor] += isIncrease ? 1 : -1;
}
2022-06-29 04:49:59 -03:00
background.style.background = `linear-gradient(rgb(${color.join(",")}),rgba(${color.map(c => c - difference).join(",")}, 0.5)),var(--background-noise)`;
2022-06-29 04:49:59 -03:00
}
function probeBackground() {
2022-07-03 01:40:57 -03:00
console.log("Begin probing for background");
setInterval(() => {
const newBackground = document.querySelector(selector);
if (!newBackground) {
return;
2022-06-29 04:49:59 -03:00
}
if (newBackground !== background) {
2022-07-03 01:40:57 -03:00
console.log("Spotify background changed")
clearInterval(colorInterval);
colorInterval = setInterval(changeColor, timer)
background = newBackground;
2022-06-29 04:49:59 -03:00
}
}, probeTimer);
2022-07-03 01:46:11 -03:00
}
2022-09-13 09:26:45 -03:00
probeBackground();