Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save michael-jennings/301540104fb25cd465679dc326f69c79 to your computer and use it in GitHub Desktop.
Save michael-jennings/301540104fb25cd465679dc326f69c79 to your computer and use it in GitHub Desktop.
Script to remove all videos from Youtube Watch Later playlist

UPDATED 10.25.2021

Modifications by Michael-Jennings:

  • The "deleteLimit" variable lets you set the maximum number of videos to remove.
  • Improved document.querySelector(...) criteria so "[Private]"/"[Deleted]" videos get removed too. (Originally it would not remove them, and when enough stacked up at the top the page would stop loading more items, which stopped the removal process)
  • Throttled the automated "Remove from" button click rate to 1 per interval so YouTube can keep up with the requests and to accurately count completed deletes.

IMPORTANT! YOU MUST DO THIS BEFORE RUNNING THE SCRIPT:

  1. Click "..." near the shuffle buttton and under the playlist's picture & name, which is on the left side the video list. If it shows a menu button that says "Show unavailable videos" then click it, and you should see this message above the video list: "Unavailable videos will be hidden during playback"**

  2. Sort by "Date added (oldest)"

  3. Optional: I find it helps to zoom out so the page loads / shows more of the list.

  4. Press F12 / open chrome developer tools.

  5. Copy and paste the code below into the console.

  6. Edit the maxDeletes number to limit the number of videos to trim from the beginning of the list.

  7. Press enter and go do something productive. It'll take a while :)

YouTube - Watch Later

(() => {

  // MAXIMUM NUMBER OF VIDEOS TO DELETE:
  maxDeletes = 3000;
  
  // REMOVAL RATE (IN MILLISECONDS)
  removalRate = 1250;
  
  deleteCounter = 0;
  deleteInterval = setInterval(function () {
    document.querySelector('#primary button.yt-icon-button').click();
    var things = document.evaluate(
      '//span[contains(text(),"Remove from")]',
      document,
      null,
      XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
      null
    );
    for (var i = 0; (i < things.snapshotLength) & (deleteCounter < maxDeletes); i++) {
      things.snapshotItem(i).click();
      deleteCounter++;
      console.log('deleteCounter: ' + deleteCounter);
      // I know, I know... This makes the for-loop pointless :)
      break;
    }
    if (deleteCounter >= maxDeletes) {
      clearInterval(deleteInterval);
    }
  }, removalRate);
})();

Original File


UPDATED 3.12.2020

The old version of youtube with "disable_polymer" is not working anymore, so the script also stopped working.

Thanks to JanTheDeveloper we have a new working script. Big up!

I just changed the '//span[contains(text(),"Watch later")]', to '//span[contains(text(),"Remove from")]', and it should work for any playlist, not just the watch later one. (thanks to hudsonite for the tip)

setInterval(function () {
  document.querySelector('#primary button[aria-label="Action menu"]').click();
  var things = document.evaluate(
    '//span[contains(text(),"Remove from")]',
    document,
    null,
    XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
    null
  );
  for (var i = 0; i < things.snapshotLength; i++) {
    things.snapshotItem(i).click();
  }
}, 1000);

I moved the old working code to another gist

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