Skip to content

Commit

Permalink
Merge pull request spicetify#558 from SeitaHigashi/improve-shuffle+
Browse files Browse the repository at this point in the history
Improve shuffle+.js
  • Loading branch information
khanhas authored May 8, 2021
2 parents f6363af + 600fa2b commit e6a9ab9
Showing 1 changed file with 43 additions and 15 deletions.
58 changes: 43 additions & 15 deletions Extensions/shuffle+.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,26 @@
if (headers.length > 0) clearInterval(iframeInterval);
}, 500)

const checkUris = (uris) => {
if (uris.length === 1) {
const uriObj = Spicetify.URI.fromString(uris[0]);
switch (uriObj.type) {
case Spicetify.URI.Type.SHOW:
case Spicetify.URI.Type.PLAYLIST:
case Spicetify.URI.Type.PLAYLIST_V2:
case Spicetify.URI.Type.FOLDER:
case Spicetify.URI.Type.ALBUM:
case Spicetify.URI.Type.COLLECTION:
case Spicetify.URI.Type.ARTIST:
return true;
}
return false;
}
// User selects multiple tracks in a list.
return true;
}


const cntxMenu = new Spicetify.ContextMenu.Item(
"Play with Shuffle+",
(uris) => {
Expand All @@ -102,27 +122,35 @@
const list = uris.map((uri) => ({ uri }));
playList(shuffle(list));
},
checkUris,
"shuffle"
)
cntxMenu.register();

const cntxMenu2 = new Spicetify.ContextMenu.Item(
"Add to Queue and Shuffle+",
(uris) => {
let next_tracks = Spicetify.Queue.next_tracks;
let delimiterIndex = next_tracks.findIndex(
(value) => value.uri === "spotify:delimiter"
);
if(delimiterIndex !== -1) {
next_tracks.splice(delimiterIndex);
}
if (uris.length === 1) {
const uriObj = Spicetify.URI.fromString(uris[0]);
switch (uriObj.type) {
case Spicetify.URI.Type.SHOW:
case Spicetify.URI.Type.PLAYLIST:
case Spicetify.URI.Type.PLAYLIST_V2:
case Spicetify.URI.Type.FOLDER:
case Spicetify.URI.Type.ALBUM:
case Spicetify.URI.Type.COLLECTION:
case Spicetify.URI.Type.ARTIST:
return true;
}
return false;
fetchListFromUri(uris[0])
.then((list) => setQueue(shuffle(next_tracks.concat(list))))
.catch((err) => Spicetify.showNotification(`${err}`));
return;
}
// User selects multiple tracks in a list.
return true;

const list = uris.map((uri) => ({ uri }));
setQueue(shuffle(next_tracks.concat(list)));
},
checkUris,
"shuffle"
)
cntxMenu.register();
cntxMenu2.register();

/**
*
Expand Down

0 comments on commit e6a9ab9

Please sign in to comment.