Skip to content

Commit

Permalink
feat(shuffle+): add an option to shuffle queue (#2923)
Browse files Browse the repository at this point in the history
  • Loading branch information
rxri committed Mar 26, 2024
1 parent 6f88fb6 commit 4950982
Showing 1 changed file with 41 additions and 3 deletions.
44 changes: 41 additions & 3 deletions Extensions/shuffle+.js
Expand Up @@ -12,6 +12,7 @@

const { React } = Spicetify;
const { useState } = React;
let playbarButton = null;

function getConfig() {
try {
Expand All @@ -22,7 +23,7 @@
throw "";
} catch {
Spicetify.LocalStorage.set("shufflePlus:settings", "{}");
return { artistMode: "all", artistNameMust: false };
return { artistMode: "all", artistNameMust: false, enableQueueButton: false };
}
}

Expand Down Expand Up @@ -180,12 +181,18 @@
React.createElement(checkBoxItem, {
name: "Chosen artist must be included",
field: "artistNameMust"
}),
React.createElement(checkBoxItem, {
name: "Enable Shuffle+ Queue Tracks button in Playbar",
field: "enableQueueButton",
onclickFun: () => renderQueuePlaybarButton()
})
);

Spicetify.PopupModal.display({
title: "Shuffle+",
content: settingsDOMContent
content: settingsDOMContent,
isLarge: true
});
}

Expand Down Expand Up @@ -265,6 +272,24 @@
"playlist-folder"
).register();

renderQueuePlaybarButton();
function renderQueuePlaybarButton() {
if (!playbarButton) {
playbarButton = new Spicetify.Playbar.Button(
"Shuffle+ Queue Tracks",
"enhance",
async () => {
await fetchAndPlay("queue");
},
false,
false
);
}

if (CONFIG.enableQueueButton) playbarButton.register();
else playbarButton.deregister();
}

async function fetchPlaylistTracks(uri) {
const res = await Spicetify.CosmosAsync.get(`sp://core-playlist/v1/playlist/spotify:playlist:${uri}/rows`, {
policy: { link: true, playable: true }
Expand Down Expand Up @@ -407,6 +432,16 @@
return res.map(track => track.uri);
}

function fetchQueue() {
const { _queueState } = Spicetify.Platform.PlayerAPI._queue;
const nextUp = _queueState.nextUp.map(track => track.uri);
const queued = _queueState.queued.map(track => track.uri);
const array = [...new Set([...nextUp, ...queued])];
const current = _queueState.current?.uri;
if (current) array.push(current);
return array;
}

async function fetchCollection(uriObj) {
const { category, type } = uriObj;
const { pathname } = Spicetify.Platform.History.location;
Expand Down Expand Up @@ -528,7 +563,10 @@
let uri;

try {
if (typeof rawUri === "object") {
if (rawUri === "queue") {
list = fetchQueue();
context = null;
} else if (typeof rawUri === "object") {
list = rawUri;
context = null;
} else {
Expand Down

0 comments on commit 4950982

Please sign in to comment.