Forked from JamieMason/spotify-save-all-in-playlist.js
Created
April 30, 2014 08:51
Revisions
-
ShaneHudson revised this gist
Apr 30, 2014 . 1 changed file with 9 additions and 9 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -5,41 +5,41 @@ * 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. -
JamieMason revised this gist
Apr 30, 2014 . 1 changed file with 4 additions and 3 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -9,10 +9,9 @@ // 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.'); } @@ -38,7 +37,9 @@ // 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. -
JamieMason revised this gist
Apr 30, 2014 . 1 changed file with 29 additions and 8 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -5,15 +5,36 @@ * 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 hasMatches = typeof document.createElement('div').matches === 'function'; var hasContentWindow = document.createElement('iframe').contentDocument === null; if (!hasQuerySelector || !hasQuerySelectorAll || !hasMatches || !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.contentDocument.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) { @@ -25,7 +46,7 @@ // and click them. button.click(); }); }()); -
JamieMason created this gist
Apr 30, 2014 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,31 @@ /* * 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() { // Get the ID of the playlist you're currently viewing at https://play.spotify.com. var playlistFrameId = document.querySelector('iframe[id^=collection]').getAttribute('id'); // Get the child window that playlist is being displayed in. var playlistFrame = window[playlistFrameId].contentWindow; // Get all the + or √ buttons var saveButtons = playlistFrame.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) { return !button.parentNode.parentNode.matches('.added'); }) // Loop over the remaining buttons. .forEach(function(button) { // and click them. button.click(); }); }());