Skip to content

Commit ae90588

Browse files
ohitstomrxri
andauthored
feat(topbar): cross-version classname support (#3162)
Co-authored-by: ririxi <dev@ririxi.dev>
1 parent 11171db commit ae90588

File tree

1 file changed

+13
-18
lines changed

1 file changed

+13
-18
lines changed

jsHelper/spicetifyWrapper.js

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2060,11 +2060,12 @@ Object.defineProperty(Spicetify, "TippyProps", {
20602060
});
20612061

20622062
Spicetify.Topbar = (() => {
2063+
let leftGeneratedClassName;
2064+
let rightGeneratedClassName;
20632065
let leftContainer;
20642066
let rightContainer;
20652067
const leftButtonsStash = new Set();
20662068
const rightButtonsStash = new Set();
2067-
const generatedClassName = "Button-medium-medium-buttonTertiary-iconOnly-condensed-disabled-isUsingKeyboard-useBrowserDefaultFocusStyle";
20682069

20692070
class Button {
20702071
constructor(label, icon, onClick, disabled = false, isRight = false) {
@@ -2080,19 +2081,12 @@ Spicetify.Topbar = (() => {
20802081
this.label = label;
20812082

20822083
this.element.appendChild(this.button);
2083-
const globalHistoryButtons = document.querySelector(".main-globalNav-historyButtons");
20842084
if (isRight) {
2085-
this.button.classList.add("encore-over-media-set", "main-topBar-buddyFeed");
2086-
if (globalHistoryButtons) this.button.classList.add("main-globalNav-buddyFeed");
2087-
2085+
this.button.className = rightGeneratedClassName;
20882086
rightButtonsStash.add(this.element);
20892087
rightContainer?.prepend(this.element);
20902088
} else {
2091-
this.button.classList.add("main-topBar-button");
2092-
if (globalHistoryButtons) {
2093-
this.button.classList.add("main-globalNav-icon", generatedClassName);
2094-
}
2095-
2089+
this.button.className = leftGeneratedClassName;
20962090
leftButtonsStash.add(this.element);
20972091
leftContainer?.append(this.element);
20982092
}
@@ -2136,9 +2130,15 @@ Spicetify.Topbar = (() => {
21362130

21372131
function waitForTopbarMounted() {
21382132
const globalHistoryButtons = document.querySelector(".main-globalNav-historyButtons");
2133+
leftGeneratedClassName = document.querySelector(
2134+
".main-topBar-historyButtons .main-topBar-button, .main-globalNav-historyButtons .main-globalNav-icon"
2135+
)?.className;
2136+
rightGeneratedClassName = document.querySelector(
2137+
".main-topBar-container .main-topBar-buddyFeed, .main-actionButtons .main-topBar-buddyFeed, .main-actionButtons .main-globalNav-buddyFeed"
2138+
)?.className;
21392139
leftContainer = document.querySelector(".main-topBar-historyButtons") ?? globalHistoryButtons;
21402140
rightContainer = document.querySelector(".main-actionButtons");
2141-
if (!leftContainer || !rightContainer) {
2141+
if (!leftContainer || !rightContainer || !leftGeneratedClassName || !rightGeneratedClassName) {
21422142
setTimeout(waitForTopbarMounted, 100);
21432143
return;
21442144
}
@@ -2148,19 +2148,14 @@ Spicetify.Topbar = (() => {
21482148
if (button.parentNode) button.parentNode.removeChild(button);
21492149

21502150
const buttonElement = button.querySelector("button");
2151-
if (globalHistoryButtons) {
2152-
buttonElement.classList.add("main-globalNav-icon", generatedClassName);
2153-
} else {
2154-
buttonElement.classList.remove("main-globalNav-icon", generatedClassName);
2155-
}
2151+
buttonElement.className = leftGeneratedClassName;
21562152
}
21572153
leftContainer.append(...leftButtonsStash);
21582154
for (const button of rightButtonsStash) {
21592155
if (button.parentNode) button.parentNode.removeChild(button);
21602156

21612157
const buttonElement = button.querySelector("button");
2162-
if (globalHistoryButtons) buttonElement.classList.add("main-globalNav-buddyFeed");
2163-
else buttonElement.classList.remove("main-globalNav-buddyFeed");
2158+
buttonElement.className = rightGeneratedClassName;
21642159
}
21652160
rightContainer.prepend(...rightButtonsStash);
21662161
}

0 commit comments

Comments
 (0)