Forked from qoomon/youtube_clean_watch_later_videos.js
Created
April 3, 2025 14:35
-
-
Save sutkovyi/4d9567fab76111f8d464022fa79da5f0 to your computer and use it in GitHub Desktop.
Clean YouTube Watch Later Videos
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Version 2.0.1 | |
// 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 in your browser console | |
(async function() { | |
const playlistName = document.querySelector('.metadata-wrapper #container #text')?.textContent || document.querySelector('#text')?.textContent | |
if(!playlistName) { | |
alert(`Couldn't determine playlist name!`) | |
return | |
} | |
if(!confirm(`Are you sure to delete ALL videos from ${playlistName}?`)) { | |
return | |
} | |
console.info("start...") | |
while(true) { | |
const videos = document.querySelectorAll('#primary ytd-playlist-video-renderer') | |
if(videos.length == 0) break | |
for (let videoElement of videos) { | |
const videoTitle = videoElement.querySelector('a#video-title') | |
console.info(`Remove Video\n` | |
+ ` Title: ${videoTitle.innerText}\n` | |
+ ` URL: ${videoTitle.href}`) | |
const actionMenuButton = videoElement.querySelector('#menu #button') | |
console.debug("click actionMenuButton", actionMenuButton) | |
actionMenuButton.click() | |
const removeButton = await untilDefined(() => document.evaluate( | |
`//tp-yt-paper-listbox/ytd-menu-service-item-renderer[./tp-yt-paper-item/yt-formatted-string/span[text() = '${playlistName}']]`, | |
document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue) | |
console.debug("click removeButton", removeButton) | |
removeButton.click() | |
await sleep(200) | |
} | |
} | |
console.info("done!") | |
// === util functions ======================================================== | |
async function sleep (timeout) { | |
return new Promise(res => setTimeout(res, timeout)) | |
} | |
async function untilDefined(factory, checkInterval = 100) { | |
while (true) { | |
const value = factory() | |
if (value != null) return value | |
await sleep(checkInterval) | |
} | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment