Skip to content

Instantly share code, notes, and snippets.

Revisions

  1. ShaneHudson revised this gist Apr 30, 2014. 1 changed file with 9 additions and 9 deletions.
    18 changes: 9 additions & 9 deletions spotify-save-all-in-playlist.js
    Original 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.contentDocument.querySelectorAll('[data-ta-id="track-add-button"]');
    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;
    return !isTickButton;
    })

    // Loop over the remaining buttons.
  2. @JamieMason JamieMason revised this gist Apr 30, 2014. 1 changed file with 4 additions and 3 deletions.
    7 changes: 4 additions & 3 deletions spotify-save-all-in-playlist.js
    Original 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 hasMatches = typeof document.createElement('div').matches === 'function';
    var hasContentWindow = document.createElement('iframe').contentDocument === null;

    if (!hasQuerySelector || !hasQuerySelectorAll || !hasMatches || !hasContentWindow) {
    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) {
    return !button.parentNode.parentNode.matches('.added');
    var tableRow = button.parentNode.parentNode;
    var isTickButton = tableRow.className.search(/\badded\b/) !== -1;
    return isTickButton;
    })

    // Loop over the remaining buttons.
  3. @JamieMason JamieMason revised this gist Apr 30, 2014. 1 changed file with 29 additions and 8 deletions.
    37 changes: 29 additions & 8 deletions spotify-save-all-in-playlist.js
    Original 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 = document.querySelector('iframe[id^=collection]').getAttribute('id');
    var playlistFrameId = playlistFrame.getAttribute('id');

    // Get the child window that playlist is being displayed in.
    var playlistFrame = window[playlistFrameId].contentWindow;

    var playlistWindow = window[playlistFrameId];

    if (!playlistWindow) {
    return console.error('Cannot access playlist.');
    }

    // Get all the + or √ buttons
    var saveButtons = playlistFrame.document.querySelectorAll('[data-ta-id="track-add-button"]');
    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();

    });

    }());
    }());
  4. @JamieMason JamieMason created this gist Apr 30, 2014.
    31 changes: 31 additions & 0 deletions spotify-save-all-in-playlist.js
    Original 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();

    });

    }());