From f4612e28a5e9ae160060258ce2a8341ad11181b4 Mon Sep 17 00:00:00 2001 From: Sepi Date: Sat, 8 May 2021 18:04:46 +0900 Subject: [PATCH 1/2] Update shuffle+.js Add "Add to Queue and Shuffle+" function. --- Extensions/shuffle+.js | 43 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/Extensions/shuffle+.js b/Extensions/shuffle+.js index 8291c1fd86..80e01d8616 100644 --- a/Extensions/shuffle+.js +++ b/Extensions/shuffle+.js @@ -124,6 +124,49 @@ ) 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) { + fetchListFromUri(uris[0]) + .then((list) => setQueue(shuffle(next_tracks.concat(list)))) + .catch((err) => Spicetify.showNotification(`${err}`)); + return; + } + + const list = uris.map((uri) => ({ uri })); + setQueue(shuffle(next_tracks.concat(list))); + }, + (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; + }, + "shuffle" + ) + cntxMenu2.register(); + + /** * * @param {string} uri From 600fa2b5c4d1f3bb944d75e34ca309f836a13063 Mon Sep 17 00:00:00 2001 From: Sepi Date: Sat, 8 May 2021 23:02:40 +0900 Subject: [PATCH 2/2] Add check URIs functions --- Extensions/shuffle+.js | 59 ++++++++++++++++-------------------------- 1 file changed, 22 insertions(+), 37 deletions(-) diff --git a/Extensions/shuffle+.js b/Extensions/shuffle+.js index 80e01d8616..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,24 +122,7 @@ const list = uris.map((uri) => ({ uri })); playList(shuffle(list)); }, - (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; - }, + checkUris, "shuffle" ) cntxMenu.register(); @@ -144,29 +147,11 @@ const list = uris.map((uri) => ({ uri })); setQueue(shuffle(next_tracks.concat(list))); }, - (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; - }, + checkUris, "shuffle" ) cntxMenu2.register(); - /** * * @param {string} uri