Skip to content

Instantly share code, notes, and snippets.

@REDIDSOFT
Created November 30, 2022 14:38
Show Gist options
  • Select an option

  • Save REDIDSOFT/b9c89bf56d430b04391e934cb0d72810 to your computer and use it in GitHub Desktop.

Select an option

Save REDIDSOFT/b9c89bf56d430b04391e934cb0d72810 to your computer and use it in GitHub Desktop.

Revisions

  1. Red ID Software created this gist Nov 30, 2022.
    70 changes: 70 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,70 @@
    // 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
    // adjust REMOVE_BUTTON_TEXT accordingly to your language, see examples below
    (async function() {

    const REMOVE_BUTTON_TEXT = 'Remover de Assistir mais tarde'
    // de-DE: const REMOVE_BUTTON_TEXT = 'Aus "Später ansehen" entfernen'
    // pt-BR: const REMOVE_BUTTON_TEXT = 'Remover de Assistir mais tarde'
    // swe-SE: const REMOVE_BUTTON_TEXT = 'Ta bort från Titta senare'
    // zh-Hans-CN: const REMOVE_BUTTON_TEXT = '从稍后观看中移除'

    const playlistName = document.querySelector("#title a").text

    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(() => {
    for (const actionMenu of [...document.querySelectorAll('ytd-popup-container > tp-yt-iron-dropdown')]) {
    if(actionMenu => actionMenu.style.display !== "none") {
    for (const actionButton of [...actionMenu.querySelectorAll('tp-yt-paper-item')]) {
    if(actionButton.innerText.trim().toLowerCase() === REMOVE_BUTTON_TEXT.toLowerCase()){
    return actionButton
    }
    }
    }
    }
    console.debug("wait for removeButton")
    })
    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)
    }
    }
    })();