Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bergpb/67ab387ee8d9a46e5f58d6049674dea6 to your computer and use it in GitHub Desktop.
Save bergpb/67ab387ee8d9a46e5f58d6049674dea6 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_MAP if your language is missing
(async function() {
const REMOVE_BUTTON_TEXT_MAP = {
'en': 'Remove from Watch later',
'en-GB': 'Remove from Watch later',
'de-DE': 'Aus "Später ansehen" entfernen',
'pt-BR': 'Remover de Assistir mais tarde'
}
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 languageCode = document.documentElement.lang
let removeButtonText = REMOVE_BUTTON_TEXT_MAP[languageCode] || REMOVE_BUTTON_TEXT_MAP[languageCode.split('-')[0]]
let removeButton = await untilDefined(() => document.evaluate(
`//ytd-popup-container/tp-yt-iron-dropdown//tp-yt-paper-item[contains(., "${removeButtonText}")]`,
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