From f57732570ff2be31dcc8e8a53e5bc09eafbb0577 Mon Sep 17 00:00:00 2001 From: Thomas Fitzpatrick <22730962+ohitstom@users.noreply.github.com> Date: Sun, 7 May 2023 00:49:37 +0100 Subject: [PATCH] feat(lyrics-plus): playbar button (#2327) --- CustomApps/lyrics-plus/PlaybarButton.js | 47 +++++++++++++++++++++++++ CustomApps/lyrics-plus/Settings.js | 15 ++++++++ CustomApps/lyrics-plus/index.js | 1 + CustomApps/lyrics-plus/manifest.json | 3 +- 4 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 CustomApps/lyrics-plus/PlaybarButton.js diff --git a/CustomApps/lyrics-plus/PlaybarButton.js b/CustomApps/lyrics-plus/PlaybarButton.js new file mode 100644 index 0000000000..3351fb22c4 --- /dev/null +++ b/CustomApps/lyrics-plus/PlaybarButton.js @@ -0,0 +1,47 @@ +(function PlaybarButton() { + if (!Spicetify.Platform) { + setTimeout(PlaybarButton, 300); + return; + } + + const button = new Spicetify.Playbar.Button( + "Lyrics Plus", + ``, + () => + Spicetify.Platform.History.location.pathname !== "/lyrics-plus" + ? Spicetify.Platform.History.push("/lyrics-plus") + : Spicetify.Platform.History.goBack(), + false, + false, + false + ); + + const style = document.createElement("style"); + style.innerHTML = ` + .main-nowPlayingBar-lyricsButton { + display: none !important; + } + li[data-id="/lyrics-plus"] { + display: none; + } + `; + style.classList.add("lyrics-plus:visual:playbar-button"); + + if (Spicetify.LocalStorage.get("lyrics-plus:visual:playbar-button") === "true") setPlaybarButton(); + window.addEventListener("lyrics-plus", event => { + if (event.detail?.name === "playbar-button") event.detail.value ? setPlaybarButton() : removePlaybarButton(); + }); + + button.active = Spicetify.Platform.History.location.pathname === "/lyrics-plus"; + Spicetify.Platform.History.listen(location => (button.active = location.pathname === "/lyrics-plus")); + + function setPlaybarButton() { + document.head.appendChild(style); + button.register(); + } + + function removePlaybarButton() { + style.remove(); + button.deregister(); + } +})(); diff --git a/CustomApps/lyrics-plus/Settings.js b/CustomApps/lyrics-plus/Settings.js index 4e2c8de1b9..0799a483db 100644 --- a/CustomApps/lyrics-plus/Settings.js +++ b/CustomApps/lyrics-plus/Settings.js @@ -431,6 +431,12 @@ function openConfig() { react.createElement("h2", null, "Options"), react.createElement(OptionList, { items: [ + { + desc: "Playbar button", + key: "playbar-button", + info: "Replace Spotify's lyrics button with Lyrics Plus.", + type: ConfigSlider + }, { desc: "Global delay", info: "Offset (in ms) across all tracks.", @@ -538,6 +544,15 @@ function openConfig() { CONFIG.visual[name] = value; localStorage.setItem(`${APP_NAME}:visual:${name}`, value); lyricContainerUpdate && lyricContainerUpdate(); + + const configChange = new CustomEvent("lyrics-plus", { + detail: { + type: "config", + name: name, + value: value + } + }); + window.dispatchEvent(configChange); } }), react.createElement("h2", null, "Providers"), diff --git a/CustomApps/lyrics-plus/index.js b/CustomApps/lyrics-plus/index.js index c00ceea116..0b3de125e7 100644 --- a/CustomApps/lyrics-plus/index.js +++ b/CustomApps/lyrics-plus/index.js @@ -36,6 +36,7 @@ const KARAOKE = 0, const CONFIG = { visual: { + ["playbar-button"]: getConfig("lyrics-plus:visual:playbar-button", false), colorful: getConfig("lyrics-plus:visual:colorful"), noise: getConfig("lyrics-plus:visual:noise"), ["background-color"]: localStorage.getItem("lyrics-plus:visual:background-color") || "var(--spice-main)", diff --git a/CustomApps/lyrics-plus/manifest.json b/CustomApps/lyrics-plus/manifest.json index bc712713f4..72b93a85bd 100644 --- a/CustomApps/lyrics-plus/manifest.json +++ b/CustomApps/lyrics-plus/manifest.json @@ -78,5 +78,6 @@ "Utils.js", "Settings.js", "Translator.js" - ] + ], + "subfiles_extension": ["PlaybarButton.js"] }