Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
//. get you location code by executing document.documentElement.lang
(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',
'zh-Hans-CN': '从稍后观看中移除',
}
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!")
})();
@xlryegor

This comment has been minimized.

Copy link

@xlryegor xlryegor commented Apr 17, 2021

Man, thank you so much! I have tried multiple solutions on the net, but it seems your script is the only one which works for me :)

@qoomon

This comment has been minimized.

Copy link
Owner Author

@qoomon qoomon commented Apr 17, 2021

Glad to hear that.

@sendpoint-boop

This comment has been minimized.

Copy link

@sendpoint-boop sendpoint-boop commented Jun 5, 2021

Thanks for sharing this, it worked to clear my watch later list of about 2500 videos...

It got through it in chunks of a few hundred videos at a time, took a few minutes to run, grateful.

@qoomon

This comment has been minimized.

Copy link
Owner Author

@qoomon qoomon commented Jun 5, 2021

I am glad to hear that.

@DoughyInTheMiddle

This comment has been minimized.

Copy link

@DoughyInTheMiddle DoughyInTheMiddle commented Jun 9, 2021

Is here a way to see if the playlist item has been viewed or not an only delete viewed videos?

I'm not familiar enough with JS, however, way back in Ye Olden Dayz I taught myself VBA by poking things with a stick a lot. Just have to translate a little syntax in my head...provided the functions are there in the YT API.

@qoomon

This comment has been minimized.

Copy link
Owner Author

@qoomon qoomon commented Jun 10, 2021

@DoughyInTheMiddle this functionality is already available by youtube itself, just click the three dot menu below the "Watch later" headline and click "Remove watched videos"

@dederaditya

This comment has been minimized.

Copy link

@dederaditya dederaditya commented Jun 14, 2021

Thank you so much!!!

@qoomon

This comment has been minimized.

Copy link
Owner Author

@qoomon qoomon commented Jun 14, 2021

glad I could help :-)

@henriquepiresmartins

This comment has been minimized.

Copy link

@henriquepiresmartins henriquepiresmartins commented Jun 16, 2021

Thank you very much friend!
Of all the scripts I tested, this was the only one that worked for me.
Added pt-BR language support according to your orientation.

@qoomon

This comment has been minimized.

Copy link
Owner Author

@qoomon qoomon commented Jun 16, 2021

@henriquepiresmartins may you share your REMOVE_BUTTON_TEXT_MAP entry? so I can add it.

@henriquepiresmartins

This comment has been minimized.

Copy link

@henriquepiresmartins henriquepiresmartins commented Jun 17, 2021

@henriquepiresmartins may you share your REMOVE_BUTTON_TEXT_MAP entry? so I can add it.

Of course my friend

Only add this line in bold:

(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',
}

@qoomon

This comment has been minimized.

Copy link
Owner Author

@qoomon qoomon commented Jun 17, 2021

@Hanan-Neor

This comment has been minimized.

Copy link

@Hanan-Neor Hanan-Neor commented Jun 30, 2021

To whom who got stuck with the tanslation , just switch the display language to english. Works well, thanks!

@Schlaegel

This comment has been minimized.

Copy link

@Schlaegel Schlaegel commented Jul 2, 2021

Wow. Thanks. 2500 videos later, and I've gone through a time machine of my YouTube stages.

@sandorex

This comment has been minimized.

Copy link

@sandorex sandorex commented Jul 4, 2021

Thank you so much, i've tried other script and it works really slowly and stops after about ~80 entries

@chekoopa

This comment has been minimized.

Copy link

@chekoopa chekoopa commented Aug 29, 2021

Do you know how to deal with 400 error? It seems to work, only to fall into chain of errors, even though videos disappear, they actually aren't deleted and are shown again after a refresh.

@qoomon

This comment has been minimized.

Copy link
Owner Author

@qoomon qoomon commented Aug 30, 2021

@chekoopa unfortunately I've no idea. This script just simulate clicks so I have no influence on the requests itself.

@xiaolitongxue666

This comment has been minimized.

Copy link

@xiaolitongxue666 xiaolitongxue666 commented Sep 23, 2021

Thanks a lot , if you web is in Chinese , just add

	'zh-Hans-CN': '从稍后观看中移除',

It's works ~

@qoomon

This comment has been minimized.

Copy link
Owner Author

@qoomon qoomon commented Sep 23, 2021

@xiaolitongxue666 I'll add your translation entry

@xiaolitongxue666

This comment has been minimized.

Copy link

@xiaolitongxue666 xiaolitongxue666 commented Sep 23, 2021

@xiaolitongxue666 I'll add your translation entry

OK 👌 !~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment