Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(topbar): cross-version classname support #3162

Merged
merged 6 commits into from
Sep 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 13 additions & 18 deletions jsHelper/spicetifyWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -2060,11 +2060,12 @@ Object.defineProperty(Spicetify, "TippyProps", {
});

Spicetify.Topbar = (() => {
let leftGeneratedClassName;
let rightGeneratedClassName;
let leftContainer;
let rightContainer;
const leftButtonsStash = new Set();
const rightButtonsStash = new Set();
const generatedClassName = "Button-medium-medium-buttonTertiary-iconOnly-condensed-disabled-isUsingKeyboard-useBrowserDefaultFocusStyle";

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

this.element.appendChild(this.button);
const globalHistoryButtons = document.querySelector(".main-globalNav-historyButtons");
if (isRight) {
this.button.classList.add("encore-over-media-set", "main-topBar-buddyFeed");
if (globalHistoryButtons) this.button.classList.add("main-globalNav-buddyFeed");

this.button.className = rightGeneratedClassName;
rightButtonsStash.add(this.element);
rightContainer?.prepend(this.element);
} else {
this.button.classList.add("main-topBar-button");
if (globalHistoryButtons) {
this.button.classList.add("main-globalNav-icon", generatedClassName);
}

this.button.className = leftGeneratedClassName;
leftButtonsStash.add(this.element);
leftContainer?.append(this.element);
}
Expand Down Expand Up @@ -2136,9 +2130,15 @@ Spicetify.Topbar = (() => {

function waitForTopbarMounted() {
const globalHistoryButtons = document.querySelector(".main-globalNav-historyButtons");
leftGeneratedClassName = document.querySelector(
".main-topBar-historyButtons .main-topBar-button, .main-globalNav-historyButtons .main-globalNav-icon"
)?.className;
rightGeneratedClassName = document.querySelector(
".main-topBar-container .main-topBar-buddyFeed, .main-actionButtons .main-topBar-buddyFeed, .main-actionButtons .main-globalNav-buddyFeed"
)?.className;
leftContainer = document.querySelector(".main-topBar-historyButtons") ?? globalHistoryButtons;
rightContainer = document.querySelector(".main-actionButtons");
if (!leftContainer || !rightContainer) {
if (!leftContainer || !rightContainer || !leftGeneratedClassName || !rightGeneratedClassName) {
setTimeout(waitForTopbarMounted, 100);
return;
}
Expand All @@ -2148,19 +2148,14 @@ Spicetify.Topbar = (() => {
if (button.parentNode) button.parentNode.removeChild(button);

const buttonElement = button.querySelector("button");
if (globalHistoryButtons) {
buttonElement.classList.add("main-globalNav-icon", generatedClassName);
} else {
buttonElement.classList.remove("main-globalNav-icon", generatedClassName);
}
buttonElement.className = leftGeneratedClassName;
}
leftContainer.append(...leftButtonsStash);
for (const button of rightButtonsStash) {
if (button.parentNode) button.parentNode.removeChild(button);

const buttonElement = button.querySelector("button");
if (globalHistoryButtons) buttonElement.classList.add("main-globalNav-buddyFeed");
else buttonElement.classList.remove("main-globalNav-buddyFeed");
buttonElement.className = rightGeneratedClassName;
}
rightContainer.prepend(...rightButtonsStash);
}
Expand Down