mirror of
https://github.com/danbulant/dribbblish-dynamic-theme
synced 2026-06-06 08:11:39 +00:00
change cover listener
This commit is contained in:
parent
a7d99725c2
commit
bff439eaa3
1 changed files with 12 additions and 27 deletions
|
|
@ -540,7 +540,6 @@ function updateColors(textColHex, sideColHex, checkDarkMode = true) {
|
||||||
if (checkDarkMode) checkDarkLightMode([textColHex, sideColHex]);
|
if (checkDarkMode) checkDarkLightMode([textColHex, sideColHex]);
|
||||||
}
|
}
|
||||||
|
|
||||||
let coverListenerInstalled = false;
|
|
||||||
async function songchange() {
|
async function songchange() {
|
||||||
if (!document.querySelector(".main-trackInfo-container")) return setTimeout(songchange, 300);
|
if (!document.querySelector(".main-trackInfo-container")) return setTimeout(songchange, 300);
|
||||||
|
|
||||||
|
|
@ -565,9 +564,7 @@ async function songchange() {
|
||||||
bgImage = "/images/tracklist-row-song-fallback.svg";
|
bgImage = "/images/tracklist-row-song-fallback.svg";
|
||||||
textColor = "#509bf5";
|
textColor = "#509bf5";
|
||||||
updateColors(textColor, textColor);
|
updateColors(textColor, textColor);
|
||||||
coverListenerInstalled = false;
|
|
||||||
}
|
}
|
||||||
if (!coverListenerInstalled) hookCoverChange(true);
|
|
||||||
|
|
||||||
if (album_uri !== undefined && !album_uri.includes("spotify:show")) {
|
if (album_uri !== undefined && !album_uri.includes("spotify:show")) {
|
||||||
moment.locale(Spicetify.Locale.getLocale());
|
moment.locale(Spicetify.Locale.getLocale());
|
||||||
|
|
@ -584,7 +581,6 @@ async function songchange() {
|
||||||
} else if (Spicetify.Player.data.track.provider == "ad") {
|
} else if (Spicetify.Player.data.track.provider == "ad") {
|
||||||
// ad
|
// ad
|
||||||
albumInfoSpan.innerHTML = "Advertisement";
|
albumInfoSpan.innerHTML = "Advertisement";
|
||||||
coverListenerInstalled = false;
|
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
// When clicking a song from the homepage, songChange is fired with half empty metadata
|
// When clicking a song from the homepage, songChange is fired with half empty metadata
|
||||||
|
|
@ -623,32 +619,21 @@ async function pickCoverColor(img) {
|
||||||
updateColors(textColor, sidebarColor);
|
updateColors(textColor, sidebarColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
waitForElement([".main-nowPlayingBar-left"], (queries) => {
|
function registerCoverListenner() {
|
||||||
var observer = new MutationObserver(function (mutations) {
|
if (!document.querySelector(".main-image-image.cover-art-image")) return setTimeout(registerCoverListenner, 250);
|
||||||
mutations.forEach(function (mutation) {
|
pickCoverColor(document.querySelector(".main-image-image.cover-art-image"));
|
||||||
if (mutation.removedNodes.length > 0) coverListenerInstalled = false;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
observer.observe(queries[0], { childList: true });
|
|
||||||
});
|
|
||||||
|
|
||||||
function hookCoverChange(pick) {
|
const observer = new MutationObserver((muts) => {
|
||||||
waitForElement([".cover-art-image"], (queries) => {
|
const img = document.querySelector(".main-image-image.cover-art-image");
|
||||||
coverListenerInstalled = true;
|
if (!img) return registerCoverListenner();
|
||||||
var elem = queries.slice(-1)[0];
|
pickCoverColor(img);
|
||||||
if (pick && elem.complete && elem.naturalHeight !== 0) pickCoverColor(elem);
|
});
|
||||||
elem.addEventListener("load", function () {
|
observer.observe(document.querySelector(".main-image-image.cover-art-image"), {
|
||||||
try {
|
attributes: true,
|
||||||
pickCoverColor(elem);
|
attributeFilter: ["src"]
|
||||||
} catch (error) {
|
|
||||||
console.error(error);
|
|
||||||
setTimeout(pickCoverColor, 300, elem);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
registerCoverListenner();
|
||||||
hookCoverChange(false);
|
|
||||||
|
|
||||||
// Check latest release every 10m
|
// Check latest release every 10m
|
||||||
waitForElement([".main-userWidget-box"], ([userWidget]) => {
|
waitForElement([".main-userWidget-box"], ([userWidget]) => {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue