Skip to content
This repository was archived by the owner on May 4, 2021. It is now read-only.

Extension

khanhas edited this page Jun 19, 2018 · 4 revisions

Spicetify also allows you inject custom Javascript to support your theme or enhance your Spotify client functionalities. Just simply put .js file Spicetify\Extentions folder, activate it in Spicetify skin then Apply.

To organize scripts in skin easily, put a metadata section at top of each JS with this template:

// START METADATA
// NAME: Your script name
// AUTHOR: Your name
// DESCRIPTION: A little information about what it does
// END METADATA

Because every script is running in same enviroment so your variables/functions might conflict with global variables/functions or other scripts variables/functions. To prevent variables/functions leaking, wrap the whole script inside a function and run it immediately. Ex:

(function MyScript() {
	// do stuff //
})()

In script, you can use my functions and objects below to control player, get information:

Spicetify.Player functions and objects

Spicetify.Player Param Description
.data An object contains current track data like uri, track name, artist, album, cover image uri, ...
.seek (position) Seek track to position. position can be percentage (0 to 1) or milisecond
.getProgressMs () Return elapsed duration in milisecond.
.getProgressPercent () Return elapsed duration in percentage (0 to 1).
.getDuration () Return song total duration in milisecond.
.skipForward ([amount = 15000]) Seek to next amount of milisecond. amount is 15 second on default.
.skipBack ([amount = 15000]) Seek to previous amount of milisecond. amount is 15 second on default.
.next () Skip to next track.
.back () Skip to previous track.
.togglePlay () Toggle Play/Pause.
.play () Resume track.
.pause () Pause track.
.isPlaying () Return a boolean whether player is playing.
.increaseVolume () Increase a small amount of volume.
.decreaseVolume () Decrease a small amount of volume.
.getVolume () Return current volume level.
.getMute () Return mute state (true/false).
.toggleMute () Toggle Mute/No mute.
.setMute (boolean) Set mute state to true or false.
.toggleShuffle () Toggle Shuffle/No shuffle.
.getShuffle () Return current shuffle state (true/false).
.setShuffle (boolean) Set shuffle state to true or false.
.toggleRepeat () Toggle No repeat/Repeat all/Repeat one.
.getRepeat () Return current shuffle state (No repeat = 0/Repeat all = 1/Repeat one = 2).
.setRepeat (mode) Set repeat mode 0 or 1 or 2.
.thumbUp () Thumbup current track.
.thumbDown () Thumbdown current track.
.getThumbUp () Return track thumbup state (true/false).
.getThumbDown () Return track thumbdown state (true/false).
.addEventListener (type, callback) Register a type listener on chrome.player. callback has to be a function.
.removeEventListener (type, callback) Unregister added event type listener.
.dispatchEvent (event) Dispatches an event at chrome.player. event has to be created by Event constructor. Spicetify.Player always dispatch an event with "songchange" type on default whenever player changes track.

Objects:

Name Description
Spicetify.Queue Return current queuing tracks and history.
Spicetify.CosmosAPI Spotify cosmos API
Spicetify.BridgeAPI Spotify Bridge API
Spicetify.PlaybackControl Play a track/album/episode/show/playlist immediately

Functions:

Name Param Description
Spicetify.getAudioData (callback[, uri]) Return current song audio data to payload and call callback(payload). You can specify a song uri to get that song audio data instead of current one.
Spicetify.addToQueue (uri, callback) Add uri to queue. Only track, album, espisode URI types are valid.
Spicetify.removeFromQueue (uri, callback) Remove uri from queue. Only track, album, espisode URI types are valid.
Spicetify.showNotification (text) Show text as a notification bubble in bottom of client.

Clone this wiki locally