Skip to content

Instantly share code, notes, and snippets.

@the-wright-jamie
Last active February 24, 2023 15:24
Show Gist options
  • Save the-wright-jamie/43fdfd93d593b5650f06968a1080d1ae to your computer and use it in GitHub Desktop.
Save the-wright-jamie/43fdfd93d593b5650f06968a1080d1ae to your computer and use it in GitHub Desktop.
Clear search results in history. Useful if you want to clear a certain topic from your recommendations, but not nuke your recommendations entirely

Working as of last edit to this page

Adapted from https://gist.github.com/astamicu/eb351ce10451f1a51b71a1287d36880f
Jump to the code if you don't care about the preamble


Quickly remove videos from your watch history - search for videos, topics, creators you want to remove from your history to make them less likely to show up in your recommendations so you don't have to nuke or reset your recommendations. (YouTube's recommendation algorthmn works, mostly, on the videos in your History, Liked and Watch Later lists). It makes them less likely to show up, but I've found that sometimes not entirely especially if you watch related creators

Unlike the original, it doesn't intervals - you can nuke the entire visable list at once as the button is not hidden behind a meatball menu

However, the history doesn't load like a playlist, so you can only delete a max of 20 video at a time. This means you'll have to rerun the search query, delete again, search etc until you get "This list has no videos" (See here for an example of what that looks like). You don't need to refresh the page each time, and while it's much more of a manual process than the original script, at least you don't have to wait for each element to be clicked as videos are removed instantly.

YouTube has a funny little bug that causes this:
Mass Remove Video Bug

As you can see, there is supposed to be a video there but it's not rendered. This is fine - you can still use run the code to remove the videos, it's just not rendering correctly. You can remove all, re-run the search (without needing to refresh), see the same glitched page, rinse and repeat until you get:
No more videos

Be aware: much like the original script, non-english users will need to change "Remove from watch history" to what YouTube uses for your localization.

The Code

Copy and paste into the commandline:

var things = document.evaluate(
  '//*[@aria-label="Remove from watch history"]',
  document,
  null,
  XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
  null
);
for (var i = 0; i < things.snapshotLength; i++) {
  things.snapshotItem(i).click();
}

Bookmarklet:

javascript: (() => { var things = document.evaluate('//*[@aria-label="Remove from watch history"]', document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); for (var i = 0; i < things.snapshotLength; i++) { things.snapshotItem(i).click(); }})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment