Last active
February 21, 2021 05:58
-
-
Save artzub/543d48deb84278f68ea0f8b2f2a4c81c to your computer and use it in GitHub Desktop.
Clear Youtube Watch Later Playlist
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
| // open https://www.youtube.com/playlist?list=WL | |
| (async function() { | |
| const delay = (ms = 100) => new Promise((resolve) => { | |
| setTimeout(() => { | |
| resolve(true); | |
| }, ms) | |
| }); | |
| const loadAll = () => new Promise(async (resolve) => { | |
| let node = document.querySelector('ytd-continuation-item-renderer'); | |
| while(node) { | |
| node.scrollIntoView(); | |
| await delay(300); | |
| node = document.querySelector('ytd-continuation-item-renderer'); | |
| } | |
| resolve(true); | |
| }); | |
| const saveLastVideoId = () => { | |
| localStorage.setItem('_lastVideoId', ''); | |
| const { __data: { data: { videoId } = {} } = {} } = [...document.querySelectorAll('ytd-playlist-video-renderer')] | |
| .filter(({ dataset: { title } }) => title !== '[Private video]') | |
| .pop() | |
| ; | |
| console.log('lastVideoId', videoId); | |
| if (videoId) { | |
| localStorage.setItem('_lastVideoId', videoId); | |
| } | |
| }; | |
| const removeAll = async () => { | |
| const nodes = [...document.querySelectorAll('ytd-playlist-video-renderer')]; | |
| let node = nodes.pop(); | |
| let counter = 0; | |
| node = nodes.pop(); | |
| let menus; | |
| let button; | |
| while(node) { | |
| console.log(node); | |
| node.scrollIntoView(); | |
| button = node.querySelector('#menu').querySelector('yt-icon-button'); | |
| console.log(button); | |
| if (!button) { | |
| continue; | |
| } | |
| button.focus(); | |
| button.click(); | |
| menus = document.querySelector('ytd-popup-container>iron-dropdown'); | |
| while(!menus) { | |
| await delay(300); | |
| menus = document.querySelector('ytd-popup-container>iron-dropdown'); | |
| } | |
| await delay(300); | |
| menus = [...menus.querySelectorAll('ytd-menu-service-item-renderer')] | |
| .find(({ __data: { icon_ } }) => icon_ === 'yt-icons:delete'); | |
| menus.click(); | |
| await delay(500); | |
| node = nodes.pop(); | |
| } | |
| } | |
| await loadAll(); | |
| console.log('loaded'); | |
| saveLastVideoId(); | |
| console.log('last videoId is saved'); | |
| await removeAll(); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment