Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mahadevan/3bbd59995bd12799d8ff4cdd039c51c8 to your computer and use it in GitHub Desktop.
Save mahadevan/3bbd59995bd12799d8ff4cdd039c51c8 to your computer and use it in GitHub Desktop.
Clean YouTube Watch Later Videos
// This script will remove all videos from watch later list
//
// Usage
//
// #1 go to https://www.youtube.com/playlist?list=WL
// #2 run following script
(async function() {
const sleep = (timeout) => new Promise(res => setTimeout(res, timeout))
const untilDefined = async (factory, timeout = 100) => {
while (true) {
let value = factory()
if (value != null) return value
await sleep(timeout)
}
}
console.info("start...")
while(true) {
let videos = document.querySelectorAll('#primary ytd-playlist-video-renderer')
if(videos.length == 0) break;
for (let videoElement of videos) {
let videoTitle = videoElement.querySelector('a#video-title')
console.info("remove: " + videoTitle.innerText)
console.info(" " + videoTitle.href)
let actionMenu = videoElement.querySelector('#menu')
let actionMenuButton = actionMenu.querySelector('#button');
console.debug("click actionMenuButton")
actionMenuButton.click();
let removeButton = await untilDefined(() => document.evaluate('//span[contains(text(),"Remove from")]',
actionMenu, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue);
console.debug("click removeButton")
removeButton.click();
await sleep(200)
}
}
console.info("done!")
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment