mirror of
https://github.com/danbulant/dribbblish-dynamic-theme
synced 2026-05-27 14:02:13 +00:00
IMP: properly hook cover event listener when needed
This commit is contained in:
parent
e932b39df8
commit
7624554431
1 changed files with 16 additions and 6 deletions
|
|
@ -299,7 +299,8 @@ async function songchange() {
|
||||||
updateColors(textColor, textColor)
|
updateColors(textColor, textColor)
|
||||||
coverListenerInstalled = false
|
coverListenerInstalled = false
|
||||||
}
|
}
|
||||||
hookCoverChange(true)
|
if (!coverListenerInstalled)
|
||||||
|
hookCoverChange(true)
|
||||||
|
|
||||||
if (album_uri !== undefined && !album_uri.includes('spotify:show')) {
|
if (album_uri !== undefined && !album_uri.includes('spotify:show')) {
|
||||||
const albumInfo = await getAlbumInfo(album_uri.replace("spotify:album:", ""))
|
const albumInfo = await getAlbumInfo(album_uri.replace("spotify:album:", ""))
|
||||||
|
|
@ -341,7 +342,6 @@ async function songchange() {
|
||||||
Spicetify.Player.addEventListener("songchange", songchange)
|
Spicetify.Player.addEventListener("songchange", songchange)
|
||||||
|
|
||||||
function pickCoverColor(img) {
|
function pickCoverColor(img) {
|
||||||
//img.setAttribute('crossOrigin', '')
|
|
||||||
var swatches = new Vibrant(img, 5).swatches()
|
var swatches = new Vibrant(img, 5).swatches()
|
||||||
lightCols = ["Vibrant", "DarkVibrant", "Muted", "LightVibrant"]
|
lightCols = ["Vibrant", "DarkVibrant", "Muted", "LightVibrant"]
|
||||||
darkCols = ["Vibrant", "LightVibrant", "Muted", "DarkVibrant"]
|
darkCols = ["Vibrant", "LightVibrant", "Muted", "DarkVibrant"]
|
||||||
|
|
@ -363,16 +363,26 @@ function pickCoverColor(img) {
|
||||||
updateColors(textColor, sidebarColor, true)
|
updateColors(textColor, sidebarColor, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
waitForElement([".main-nowPlayingBar-left"], (queries) => {
|
||||||
|
var observer = new MutationObserver(function(mutations) {
|
||||||
|
mutations.forEach(function(mutation) {
|
||||||
|
if (mutation.removedNodes.length>0)
|
||||||
|
coverListenerInstalled = false
|
||||||
|
});
|
||||||
|
});
|
||||||
|
observer.observe(queries[0], { childList: true })
|
||||||
|
});
|
||||||
|
|
||||||
function hookCoverChange(pick) {
|
function hookCoverChange(pick) {
|
||||||
waitForElement([".cover-art-image"], (queries) => {
|
waitForElement([".cover-art-image"], (queries) => {
|
||||||
coverListenerInstalled = true;
|
coverListenerInstalled = true
|
||||||
if (pick && queries[0].complete && queries[0].naturalHeight !== 0) pickCoverColor(queries[0]);
|
if (pick && queries[0].complete && queries[0].naturalHeight !== 0) pickCoverColor(queries[0]);
|
||||||
queries[0].addEventListener("load", function () {
|
queries[0].addEventListener("load", function () {
|
||||||
try {
|
try {
|
||||||
pickCoverColor(queries[0]);
|
pickCoverColor(queries[0])
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error)
|
||||||
setTimeout(pickCoverColor, 300, queries[0]);
|
setTimeout(pickCoverColor, 300, queries[0])
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue