-
-
Save alane019/4eb230477f6b495d0235b72f318bbfc3 to your computer and use it in GitHub Desktop.
// This script can be used to clear all videos from youtube's built-in "watch later" playlist which has a limit of 5,000 videos. | |
// Without this, you would need to click the remove button on each video in the list. | |
// Youtube made changes recently that caused errors for a previously working script. | |
// Script written by: janthedeveloper (https://github.com/JanTheDeveloper) | |
// Bookmark wrapper added by: shelldonhull (https://github.com/sheldonhull) | |
// Full conversation here: https://gist.github.com/astamicu/eb351ce10451f1a51b71a1287d36880f#file-readme-md | |
// 1. Save the javascript text below as a bookmark in google chrome(Simply replace the URL field in any existing bookmark, and give the bookmark any name) | |
javascript:(() => {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); })(); | |
// 2.) Enter this exact URL into google chrome web browswer: https://www.youtube.com/playlist?list=WL&disable_polymer=true | |
// NOTE 1: THE URL MUST END WITH "&disable_polymer=true" | |
// NOTE 2: You'll need to be signed into your youtube account when using this URL, if you're not already. | |
// 3.) Once you're on the correct Watch Later playlist page, click the bookmark that you saved in the step 1. This will start deleting videos. | |
// Source: https://gist.github.com/astamicu/eb351ce10451f1a51b71a1287d36880f#gistcomment-3552367 (as of 12/14/2020) | |
// You can save any javascript snippet as a bookmark and run as needed using this format: | |
// javascript:(() => { REPLACE_THIS_TEXT_WITH_SCRIPT })(); | |
// If page is being displayed in language other than English, see comment from Gater73 below. Update portions on html tags that vary based on language. | |
// Full script, without the bookmark wrapper code below (This could be entered into the chrome dev-tools console as an alternative to using the bookmarked script) | |
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); | |
Thanks for that, all i had to do is change "Action Menu" and "Remove from" to the language i use and it worked perfectly, sad a company the size of google didnt implemented a simple feature to clear old playlist videos
Thanks for sharing this. I updated the Gist with a note about this.
Previously posted this here
Not sure how good this is, but worked for me. Since there's no language dependent querySelector, should work for most people (I hope...)
Caveat: It might take a while, but just leave it doing it's thing
It works on this url: https://www.youtube.com/playlist?list=WL
There were over 2000+ videos on my watch later. I tried removing the ones I had already watched using the Youtube's built in feature, but the request would eventually throw me a 502 after a minute or so of waiting.
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
async function deleteFirstVideo(){
let menu = document.querySelectorAll("yt-icon-button[class='dropdown-trigger style-scope ytd-menu-renderer']")[1];
menu.click();
// Tiny delay to give the menu time to render
await sleep(300);
let menuItems = document.querySelector("tp-yt-paper-listbox[class='style-scope ytd-menu-popup-renderer']").children;
// In case of unavailable videos, there's only the remove button
let button = menuItems[2] ?? menuItems[0];
button.click();
}
// Just check how much you have in the playlist
let videos_count = 2000;
for (i=0; i < videos_count ; i++){
deleteFirstVideo();
// 1500ms would get me 429 response after a couple of requests
await sleep(1750);
}
MacOS. Doesn't work for me because of problem below:
Uncaught TypeError: Cannot read properties of null (reading 'click')
at :1:103
How to solve this?
@ArthurYdalgo 's code works well, without throwing into 5xx errors. Thanks
Thanks for that, all i had to do is change "Action Menu" and "Remove from" to the language i use and it worked perfectly, sad a company the size of google didnt implemented a simple feature to clear old playlist videos