Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save astamicu/eb351ce10451f1a51b71a1287d36880f to your computer and use it in GitHub Desktop.
Save astamicu/eb351ce10451f1a51b71a1287d36880f to your computer and use it in GitHub Desktop.
Script to remove all videos from Youtube Watch Later playlist

UPDATED 22.11.2022

It's been two years since the last update, so here's the updated working script as per the comments below.

Thanks to BryanHaley for this.

setInterval(function () {
    video = document.getElementsByTagName('ytd-playlist-video-renderer')[0];

    video.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();
    }
}, 500);

Non-english users will need to change "Action menu" and "Remove from" to what YouTube uses for their localization.

@LosAlamosAl
Copy link

Sadly, as of 1/8/2024, none of these (English versions) work. Various errors (POST errors at YouTube, "Something went wrong", "This functionality currently not available; please try again later"). A common theme is that they work for a while (maybe 100 or so videos) then they die.

If you get stuck with continuously running Javascript as I did:

  • in the JavaScrip console window type debugger; throw 1
  • then from the Chrome "Window" menu --> "Task Manager"; find the Watch Later tab and kill it.

FYI, I'm running Chrome version 120.0.6099.71 (Official Build) (arm64) on MacOS 14.2

@jzisser9
Copy link

jzisser9 commented Jan 9, 2024

@LosAlamosAl if I had to guess, it's YouTube rate-limiting at work. Especially if it's a nice round number like 100.

@LosAlamosAl
Copy link

@jzisser9 Almost certainly, since it's about the same number (+- 10) with the user script by @js6pak. I cranked it down to about 5 seconds per deletion--same results.

@AttiliaTheHun
Copy link

Not sure if somebody mentioned it already, but you can click on your profile icon and select "Change language" (select English) and then there is no need for localized versions of the script. Next time you open youtube you simply change the language back, if it doesn't happen automatically.

@mpr1255
Copy link

mpr1255 commented Feb 15, 2024 via email

@derharry
Copy link

derharry commented Mar 11, 2024

Thanks for the script :-) I set the seconds down to 200ms - that speeded it up for me.
I was looking for hours for the button to remove everything at once, but it seems that Google removed it.

@vinivosh
Copy link

vinivosh commented Apr 1, 2024

Brazilian Portuguese version:

setInterval(function () {
    video = document.getElementsByTagName('ytd-playlist-video-renderer')[0];

    video.querySelector('#primary button[aria-label="Menu de ações"]').click();

    var things = document.evaluate(
        '//span[contains(text(),"Remover de")]',
        document,
        null,
        XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
        null
    );

    for (var i = 0; i < things.snapshotLength; i++) 
    {
        things.snapshotItem(i).click();
    }
}, 500);

@guilhermecgs
Copy link

Brazilian Portuguese version:

setInterval(function () {
    video = document.getElementsByTagName('ytd-playlist-video-renderer')[0];

    video.querySelector('#primary button[aria-label="Menu de ações"]').click();

    var things = document.evaluate(
        '//span[contains(text(),"Remover de")]',
        document,
        null,
        XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
        null
    );

    for (var i = 0; i < things.snapshotLength; i++) 
    {
        things.snapshotItem(i).click();
    }
}, 500);

👍

@macaua-23
Copy link

Thanks a lot @vinivosh & @colejd. It works.

@ArthurYdalgo
Copy link

Thanks for the script :-) I set the seconds down to 200ms - that speeded it up for me. I was looking for hours for the button to remove everything at once, but it seems that Google removed it.

probably because the requests were timing out

@SbMan1
Copy link

SbMan1 commented Apr 26, 2024

Made my own userscript which doesn't rely on the language and allows you to delete with progress threshold: https://gist.github.com/js6pak/33bdefdefac09c387f55d08c5b9526fa

I modified this to also remove videos published over X days old, and those that are private or deleted. This currently relies on the language though (English). It could be updated to look for 'no_thumbnail' in the thumbnail source though

Do you happen to still have this code as this would be very helpful. I just noticed I have 4,800 Watched Later and heard if I hit 5k I can't add anymore. I also msg'd js6pak on his forked page. I'll just do Date Added ( Oldest ) to make it the easiest, if I delete ones I don't want then oh well. Thanks for your time.

@BIRTAX38
Copy link

BIRTAX38 commented May 1, 2024

Polska wersja:

setInterval(function () {
    video = document.getElementsByTagName('ytd-playlist-video-renderer')[0];

    video.querySelector('#primary button[aria-label="Menu czynności"]').click();

    var things = document.evaluate(
        '//span[contains(text(),"Usuń z")]',
        document,
        null,
        XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
        null
    );

    for (var i = 0; i < things.snapshotLength; i++) 
    {
        things.snapshotItem(i).click();
    }
}, 400);

@jeduardobras
Copy link

Brazilian Portuguese version:

setInterval(function () {
    video = document.getElementsByTagName('ytd-playlist-video-renderer')[0];

    video.querySelector('#primary button[aria-label="Menu de ações"]').click();

    var things = document.evaluate(
        '//span[contains(text(),"Remover de")]',
        document,
        null,
        XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
        null
    );

    for (var i = 0; i < things.snapshotLength; i++) 
    {
        things.snapshotItem(i).click();
    }
}, 500);

Works for the European Portuguese version of YouTube as well. Thanks!

@John-nata
Copy link

John-nata commented Aug 14, 2024

Hi guys!
Just wanna share my userscript (inspired by @colejd's script) to helps you tidy up your YT playlists : YT-Playlist-Cleaner

Here are the key features :
-Customisable settings for deletion criteria
-Auto-scroll functionality to process large playlists
-Improved user interface with progress bar and status updates
-Pause and resume functionality
-Configurable delays between deletions to avoid rate limiting

screenshot

Tbh, I received some helpful suggestions from Claude AI to optimize some parts of my script before uploading it online.
Let me know what you think!

@Someone117
Copy link

I created a similar script that works by just clicking the 3 dots and then on the "Remove from playlist" button. By default, this script removes 100 videos, but that is also adjustable

This should work for all languages, so paste the script into your console and run.

YT might change their UI and you may have different screen resolution, so you may need to adjust the click x and y for each. You may also need to increase the delay if videos don't load fast enough (you can also run it multiple times).

function simulateClick(x, y) {
    // What acually does the clicking
    var event = new MouseEvent('click', {
        view: window,
        bubbles: true,
        cancelable: true,
        clientX: x,
        clientY: y
    });
    document.elementFromPoint(x, y).dispatchEvent(event);
}

function performClicks() {
    let count = 0;

    function clickSequence() {
        // change this number to remove more videos
        if (count >= 100) {
            console.log("Completed 100 click sequences.");
            return;
        }

        // change this when the UI changes, this should be the location of the 3 dots
        simulateClick(1872, 256);
        console.log(`Click sequence ${count + 1} pt 1`);

        setTimeout(function() {
            // change this when the UI changes, this should be the location of the "Remove From Playlist" button
            simulateClick(1784, 333);
            console.log(`Click sequence ${count + 1} pt 2`);

            count++;

            // Wait 100ms, you may want to set this to more time to let the next video load
            setTimeout(clickSequence, 100);
        // Wait 100ms, you may want to set this to more time to let the next video load
        }, 100);
    }

    // Start
    clickSequence();
}

// Execute the click sequences
performClicks();

This code prints your mouse location to the console so you can tailor the script

document.addEventListener('mousemove', function(event) {
    let x = event.clientX;
    let y = event.clientY;
    console.log(`Mouse position: X: ${x}, Y: ${y}`);
});

@BIRTAX38
Copy link

BIRTAX38 commented Oct 14, 2024

Universal version for all languages:

setInterval(function () {
    video = document.getElementsByTagName('ytd-playlist-video-renderer')[0];

    video.querySelector(`#primary button[aria-label="${window.ytcfg.msgs["VIDEO_ACTION_MENU"]}"]`).click();

    var things = document.evaluate(
        `//span[contains(text(),"${document.querySelector('meta[name="title"]')?.content}")]`,
        document,
        null,
        XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
        null
    );

    for (var i = 0; i < things.snapshotLength; i++) 
    {
        things.snapshotItem(i).click();
    }
}, 400);

@jstrocel
Copy link

window.ytcfg

This object returns an undefined object for me when I tried it in english.

@nightbasilisk
Copy link

To remove hidden videos. Click the dots in Watch Later playlist and select "Show unavailable videos" then run this version of the script:

setInterval(function () {
    video = document.getElementsByTagName('ytd-playlist-video-renderer')[0];

    video.querySelector('#primary 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; i++) 
    {
        things.snapshotItem(i).click();
    }
}, 1000);

@secbug
Copy link

secbug commented Nov 17, 2024

@nightbasilisk That worked perfect for me, but the timeout seemed really long. So I added a little something extra to randomize the clicking, but shorten the average up a little bit.

const getRandomMillis = (min, max) => {
  return Math.random() * (max - min) + min
}

setInterval(function () {
    video = document.getElementsByTagName('ytd-playlist-video-renderer')[0];

    video.querySelector('#primary 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; i++) 
    {
        things.snapshotItem(i).click();
    }
}, getRandomMillis(700, 1100));

@JaiganeshKumaran
Copy link

JaiganeshKumaran commented Nov 26, 2024

No longer works for me. It deletes the first one, and then the menu gets stuck at the top-left corner.

@anhtuan219
Copy link

anhtuan219 commented Dec 5, 2024

Thanks @vinivosh
Here's Vietnamese version, including removing the hidden videos and clearing the interval after the playlist is empty

  1. Go to Youtube Watch Later playlist
  2. Ctrl + Shift + I to open chrome devtools -> Choose the Console tab
  3. Type 'allow pasting' in the console
  4. Paste this into the console
var deleteInterval = setInterval(function () {
    video = document.getElementsByTagName('ytd-playlist-video-renderer')[0];

    if(!video) {
         clearInterval(deleteInterval);
         return;
    }

    video.querySelector('#primary button[aria-label="Menu tác vụ"]').click();

    var things = document.evaluate(
        '//span[contains(text(),"Xóa khỏi")]',
        document,
        null,
        XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
        null
    );

    for (var i = 0; i < things.snapshotLength; i++) 
    {
        things.snapshotItem(i).click();
    }
}, 1000);
  1. Paste this into the console to remove the hidden videos
// Show hidden videos
var btnListWL = document.querySelector('.metadata-buttons-wrapper.style-scope.ytd-playlist-header-renderer');
btnListWL.lastElementChild.lastElementChild.lastElementChild.click();
setTimeout(() => {
     var showHiddenVideoLink = document.querySelector('a[href="/playlist?list=WL"]').click();
}, 500);

// Remove the hidden videos
setTimeout(() => {
var deleteHiddenVideosInterval = setInterval(function () {
    video = document.getElementsByTagName('ytd-playlist-video-renderer')[0];

    if(!video) {
         clearInterval(deleteHiddenVideosInterval);
         return;
    }

    video.querySelector('button').click();

    var things = document.evaluate(
        '//span[contains(text(),"Xóa khỏi")]',
        document,
        null,
        XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
        null
    );

    for (var i = 0; i < things.snapshotLength; i++) 
    {
        things.snapshotItem(i).click();
    }
}, 1000);
}, 1000);

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