commit bc65b66a054e106ca9546652ed75e145e8148d3e Author: nin0 Date: Sun May 4 11:42:47 2025 -0400 init diff --git a/spotifyMainColor.ts b/spotifyMainColor.ts new file mode 100644 index 0000000..03935a3 --- /dev/null +++ b/spotifyMainColor.ts @@ -0,0 +1,40 @@ +/* + * Vencord, a Discord client mod + * Copyright (c) 2025 Vendicated and contributors + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +import { Devs } from "@utils/constants"; +import definePlugin from "@utils/types"; +import { SpotifyStore } from "plugins/spotifyControls/SpotifyStore"; + +export default definePlugin({ + name: "SpotifyMainColor", + description: "Get main color of now playing track and set as variable", + authors: [Devs.nin0dev], + async setTrackMainColor() { + if (!SpotifyStore.track) { + document.getElementById("vc-spotify-main-color")!.innerText = ""; + return; + } + const mainColor = await window.colorjs.average(SpotifyStore.track?.album.image.url, { + format: "hex" + }); + + const style = document.createElement("style"); + style.setAttribute("id", "vc-spotify-main-color"); + style.textContent = `:root { --vc-spotify-main-color: hsl(from ${mainColor} h s 85%); }`; + document.head.appendChild(style); + }, + async start() { + const cjs = await fetch("https://unpkg.com/color.js@1.2.0/dist/color.js"); + (0, eval)(await cjs.text()); + + this.setTrackMainColor(); + + SpotifyStore.addChangeListener(this.setTrackMainColor); + }, + stop() { + SpotifyStore.removeChangeListener(this.setTrackMainColor); + } +});