Skip to main content

Playbar

Create buttons in the player.

namespace Playbar {
class Button {
constructor(label: string, icon: SVGIcon | string, onClick: (self: Button) => void, disabled?: boolean, active?: boolean, registerOnCreate?: boolean);
label: string;
icon: string;
onClick: (self: Button) => void;
disabled: boolean;
active: boolean;
element: HTMLButtonElement;
tippy: any;
register: () => void;
deregister: () => void;
}

class Widget {
constructor(label: string, icon: SVGIcon | string, onClick?: (self: Widget) => void, disabled?: boolean, active?: boolean, registerOnCreate?: boolean);
label: string;
icon: string;
onClick: (self: Widget) => void;
disabled: boolean;
active: boolean;
element: HTMLButtonElement;
tippy: any;
register: () => void;
deregister: () => void;
}
};

Button

Create buttons next to the player extra control buttons (e.g. queue, lyrics, Now Playing View, etc.).

This is useful for creating buttons whose actions have an impact on or relate to the player, and are generally dynamic/stateful, such as a button that toggles the player's loop mode.

Parameters

ParameterTypeDescription
labelstringLabel of the button.
iconSVGIcon | stringIcon of the button.
onClick(self: Button) => voidCallback function when the button is clicked.
disabledboolean | undefinedWhether the button is disabled.
activeboolean | undefinedWhether the button is active.
registerOnCreateboolean | undefinedWhether the button should be registered to the player on creation.

Properties

tip

All of the listed properties are dynamic and can be changed at any time. Look into the example below for more information.

NameTypeDescription
labelstringLabel of the button.
iconstringIcon of the button.
disabledbooleanWhether the button is disabled.
activebooleanWhether the button is active.
onClick(self: Button) => voidCallback function when the button is clicked.
elementHTMLButtonElementHTML element of the button.
tippyanyTippy instance of the button. For more information, see Tippy.js.

Methods

register

Register the button to the player.

register(): void;
deregister

Deregister the button from the player.

deregister(): void;

Example

caution

Tippy, onclick or any other click events will not work if disabled is set to true. You will need to manually enable the button inside your extension.

This is due to the limitations of Tippy itself and how HTML elements work.

// By default, the button will be registered to the player on creation.
// You can disable this by setting registerOnCreate to false.
// Each button comes with a preconfigured Tippy instance that aims to mimic the original Spotify tooltip.
const button = new Spicetify.Playbar.Button(
"My Button",
"play",
(self) => {
// Do something when the button is clicked.
},
false, // Whether the button is disabled.
false, // Whether the button is active.
);

// You can also register the button to the player later.
button.register();

// Remove the button from the player when it is no longer needed.
button.deregister();
// If you don't want to remove the button entirely, you can also disable it.
button.disabled = true;

// Change button properties.
// Changing label will also change the tooltip content.
button.label = "Hello world!";
button.icon = "play";

// You can also set properties of the HTML element.
button.element.style.color = "red";
button.element.oncontextmenu = () => {
Spicetify.showNotification("You right-clicked me!");
};
button.element.addEventListener("click", () => {
// Do something else.
Spicetify.showNotification("You clicked me!");
});

// You can also change properties of the Tippy instance. For more information, see https://atomiks.github.io/tippyjs/v6/tippy-instance/.
button.tippy.setContent("Hello world!");

// Or if you want to use HTML.
button.tippy.setProps({
content: "<b>Hello world!</b>",
allowHTML: true,
});

Widget

Create widgets in the player, next to track information similar to the Heart button.

This is useful for creating buttons whose actions have an impact on the state of the player and the track being played, such as a button that adds the current track to a playlist.

Parameters

ParameterTypeDescription
labelstringLabel of the widget.
iconSVGIcon | stringIcon of the widget.
onClick(self: Widget) => voidCallback function when the widget is clicked.
disabledboolean | undefinedWhether the widget is disabled.
activeboolean | undefinedWhether the widget is active.
registerOnCreateboolean | undefinedWhether the widget should be registered to the player on creation.

Properties

tip

All of the listed properties are dynamic and can be changed at any time. Look into the example below for more information.

NameTypeDescription
labelstringLabel of the widget.
iconstringIcon of the widget.
disabledbooleanWhether the widget is disabled.
activebooleanWhether the widget is active.
onClick(self: Widget) => voidCallback function when the widget is clicked.
elementHTMLButtonElementHTML element of the widget.
tippyanyTippy instance of the widget. For more information, see Tippy.js.

Methods

register

Register the widget to the player.

register(): void;
deregister

Deregister the widget from the player.

deregister(): void;

Example

caution

Tippy, onclick or any other click events will not work if disabled is set to true. You will need to manually enable the widget inside your extension.

This is due to the limitations of Tippy itself and how HTML elements work.

// By default, the widget will be registered to the player on creation.
// You can disable this by setting registerOnCreate to false.
// Each widget comes with a preconfigured Tippy instance that aims to mimic the original Spotify tooltip.
const widget = new Spicetify.Playbar.Widget(
"My Widget",
"play",
(self) => {
// Do something when the widget is clicked.
},
false, // Whether the widget is disabled.
false, // Whether the widget is active.
);

// You can also register the widget to the player later.
widget.register();

// Remove the widget from the player when it is no longer needed.
widget.deregister();

// Change widget properties.
// Changing label will also change the tooltip content.
widget.label = "Hello world!";
widget.icon = "play";

// You can also set properties of the HTML element.
widget.element.style.color = "red";
widget.element.oncontextmenu = () => {
Spicetify.showNotification("You right-clicked me!");
};
widget.element.addEventListener("click", () => {
// Do something else.
Spicetify.showNotification("You clicked me!");
});

// You can also change properties of the Tippy instance. For more information, see https://atomiks.github.io/tippyjs/v6/tippy-instance/.
widget.tippy.setContent("Hello world!");

// Or if you want to use HTML.
widget.tippy.setProps({
content: "<b>Hello world!</b>",
allowHTML: true,
});