Last active
November 19, 2022 06:08
-
-
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 file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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(); | |
}); | |
}()); |
Any errors, please comment here and mention what browser and version you're using.
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
You need to be viewing a playlist page when running this script, such as;
https://play.spotify.com/user/gotnosugarbaby/playlist/1kQxKzUFW0ZcLDEOyrvkcL