Skip to content

Instantly share code, notes, and snippets.

@JamieMason
Last active November 19, 2022 06:08
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save JamieMason/3b0453b54c6fa58a5192 to your computer and use it in GitHub Desktop.
Save JamieMason/3b0453b54c6fa58a5192 to your computer and use it in GitHub Desktop.
This Script adds every song in the playlist you're currently viewing at https://play.spotify.com to "Your Music". Open your browser console and paste this script to run it.
/*
* This Script adds every song in the playlist you're currently
* viewing at https://play.spotify.com to "Your Music".
*
* Open your browser console and paste this script to run it.
*/
(function() {
// Check this web browser has all the functionality we need to do this task.
var hasQuerySelector = typeof document.querySelector === 'function';
var hasQuerySelectorAll = typeof document.querySelectorAll === 'function';
var hasContentWindow = document.createElement('iframe').contentDocument === null;
if (!hasQuerySelector || !hasQuerySelectorAll || !hasContentWindow) {
return console.error('Please try a newer Web Browser.');
}
// Look for the playlist we should be viewing.
var playlistFrame = document.querySelector('iframe[id^=collection]');
if (!playlistFrame) {
return console.error('No playlist found on this page.');
}
// Get the ID of the playlist you're currently viewing at https://play.spotify.com.
var playlistFrameId = playlistFrame.getAttribute('id');
// Get the child window that playlist is being displayed in.
var playlistWindow = window[playlistFrameId];
if (!playlistWindow) {
return console.error('Cannot access playlist.');
}
// Get all the + or √ buttons
var saveButtons = playlistWindow.document.querySelectorAll('[data-ta-id="track-add-button"]');
// filter out the √ buttons (delete the "!" to filter out the + buttons instead).
[].slice.call(saveButtons).filter(function(button) {
var tableRow = button.parentNode.parentNode;
var isTickButton = tableRow.className.search(/\badded\b/) !== -1;
return !isTickButton;
})
// Loop over the remaining buttons.
.forEach(function(button) {
// and click them.
button.click();
});
}());
@ShaneHudson
Copy link

Note: To make this work for artist pages etc, use Spotify's Add all to playlist feature and convert the playlist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment