Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ShaneHudson/113d61fa88c79b4d16a5 to your computer and use it in GitHub Desktop.
Save ShaneHudson/113d61fa88c79b4d16a5 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.
*/
(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();
});
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment