diff --git a/Extensions/shuffle+.js b/Extensions/shuffle+.js index 8291c1fd86..b06ff0520a 100644 --- a/Extensions/shuffle+.js +++ b/Extensions/shuffle+.js @@ -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) => { @@ -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(); /** *