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.

@corgok
Copy link

corgok commented Apr 26, 2025

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);

This one also works really well. It might be slow, but is running in the background now.

@alexander480
Copy link

alexander480 commented May 1, 2025

This script moves videos out of Watch later and into another playlist.
Just change the 'newPlaylistName' variable, and you're all set. 👍

// Move YouTube Videos From "Watch Later" Into A New Playlist.
setInterval(function () {

  // define name of playlist to move videos into
  const newPlaylistName = 'old watch later';

  // 1) grab the first video entry
  const video = document.querySelector('ytd-playlist-video-renderer');
  if (!video) return;

  // helper to open that video's action menu
  function openMenu(cb) {
    const btn = video.querySelector('ytd-menu-renderer yt-icon-button');
    if (!btn) return console.warn('No action button');
    btn.click();
    setTimeout(cb, 400);
  }

  // 2) open menu & click “Save to…”
  openMenu(() => {
    const items = Array.from(document.querySelectorAll('ytd-menu-service-item-renderer'));
    const saveItem = items.find(el =>
      el.innerText.trim().toLowerCase().startsWith('save to')
    );
    if (!saveItem) {
      console.warn('“Save to…” not found:', items.map(el => el.innerText));
      return;
    }
    saveItem.click();

    // 3) wait for dialog, click to add to new specified playlist
    setTimeout(() => {
      const option = Array.from(document.querySelectorAll('yt-formatted-string'))
        .find(el => el.innerText.trim().toLowerCase() === newPlaylistName);
      if (!option) {
        console.warn('Playlist “' + newPlaylistName + '” not found');
      } else {
        option.click();
      }

      // 4) close save dialog
      document.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape' }));

      // 5) after a short pause, re-open menu & click “Remove from Watch later”
      setTimeout(() => {
        openMenu(() => {
          const remItems = Array.from(document.querySelectorAll('ytd-menu-service-item-renderer'));
          const removeItem = remItems.find(el =>
            el.innerText.trim().toLowerCase().includes('remove from watch later')
          );
          if (!removeItem) {
            console.warn('“Remove from Watch later” not found:', remItems.map(el => el.innerText));
          } else {
            removeItem.click();
          }
        });
      }, 500);

    }, 500);
  });

}, 500);

@akod1ng
Copy link

akod1ng commented Jun 12, 2025

this one worked for me for the liked videos, not the private/hidden ones:


function sleep(ms) {
  return new Promise((resolve) => setTimeout(resolve, ms));
}

async function deleteLikedVideos() {
  `use strict`;
  var items = document.querySelectorAll(
    `#primary ytd-playlist-video-renderer yt-icon-button.dropdown-trigger > button[aria-label]`
  );
  var out;

  for (var i = 0; i < items.length; i++) {
    items[i].click();
    out = setTimeout(function () {
      if (
        document.querySelector(
          `tp-yt-paper-listbox.style-scope.ytd-menu-popup-renderer`
        ).lastElementChild
      ) {
        document
          .querySelector(
            `tp-yt-paper-listbox.style-scope.ytd-menu-popup-renderer`
          )
          .lastElementChild.click();
      }
    }, 100);
    await sleep(500); // sleep cause browser can not handle the process
    clearTimeout(out);
  }
}

deleteLikedVideos();

@TRayT
Copy link

TRayT commented Jun 14, 2025

I made an attempt before looking at the solutions here. For posterity's sake, here is my basic solution:

setInterval(function () {
    document.getElementsByTagName("ytd-playlist-video-renderer")[0].querySelector("button").click();
    setTimeout((() => document.querySelectorAll("ytd-menu-service-item-renderer")[2].click()), 500)
}, 1800);

I changed the array access to only delete old stuff, so it would make more sense to use document.getElementByTagName if you're deleting everything, but I might as well keep it for later modification.

@mycompudoctor
Copy link

Where exactly is everyone posting this script onto? I know its somewhere within the the F12 (inspection) area of the browser but where exactly? Pictures would be greatly appreciated

@akod1ng
Copy link

akod1ng commented Jun 18, 2025

Where exactly is everyone posting this script onto? I know its somewhere within the the F12 (inspection) area of the browser but where exactly? Pictures would be greatly appreciated

You have a tab called console in the development tools: https://developer.chrome.com/docs/devtools/console/javascript/

for the first time you might have to follow steps outlined in the console in order to paste a command

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