Skip to content

Instantly share code, notes, and snippets.

@stevebrun
Created June 4, 2024 16:59
Show Gist options
  • Save stevebrun/577cf2ef492d005bdd896167759c00c1 to your computer and use it in GitHub Desktop.
Save stevebrun/577cf2ef492d005bdd896167759c00c1 to your computer and use it in GitHub Desktop.
A bookmarklet to automatically remove privated, deleted, and watched videos from a YouTube Watch later playlist.
javascript: (function(){
let success = true;
const interval = setInterval(function(){
const progress = 'contains(@style, "width: 100%;")'
+ ' or contains(@style,"width: 99%;") or contains(@style,"width: 98%;")'
+ ' or contains(@style,"width: 97%;") or contains(@style,"width: 96%;")'
+ ' or contains(@style,"width: 95%;") or contains(@style,"width: 94%;")'
+ ' or contains(@style,"width: 93%;") or contains(@style,"width: 92%;")'
+ ' or contains(@style,"width: 91%;") or contains(@style,"width: 90%;")';
const menu = document.evaluate('//*[*[contains(@class,"ytd-thumbnail")]['+progress+']'
+ ' or a[@id="video-title"][@title="[Private video]" or @title="[Deleted video]"]]'
+ '/ancestor-or-self::div[@id="container"]/../../div[@id="menu"]//button[@id="button"]',
document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
if (menu == null) { return clearInterval(interval); }
menu.click();
const remove = document.evaluate('//*[@slot="dropdown-content"]//*[@role="listbox"]'
+ '//*[@role="menuitem"]//*[@role="option"]//span[contains(text(), "Remove from")]',
document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
if (remove == null && !success) { return clearInterval(interval); }
if (remove != null) { remove.click(); }
success = remove != null;
}, 1000);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment