Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save iasinDev/3c0354afcd417e45793cea53b7033008 to your computer and use it in GitHub Desktop.
Save iasinDev/3c0354afcd417e45793cea53b7033008 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
// adjust REMOVE_BUTTON_TEXT to your language (default is english)
(async function() {
const REMOVE_BUTTON_TEXT = "Remove from Watch later"
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)
actionMenuButton.click()
let removeButton = await untilDefined(() => document.evaluate(
`//ytd-popup-container/tp-yt-iron-dropdown//tp-yt-paper-item[contains(., "${REMOVE_BUTTON_TEXT}")]`,
document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue);
console.debug("click removeButton", 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