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.
-
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"**
-
Sort by "Date added (oldest)"
-
Optional: I find it helps to zoom out so the page loads / shows more of the list.
-
Press F12 / open chrome developer tools.
-
Copy and paste the code below into the console.
-
Edit the maxDeletes number to limit the number of videos to trim from the beginning of the list.
-
Press enter and go do something productive. It'll take a while :)
(() => {
// 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);
})();
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