Created
March 20, 2024 08:43
-
-
Save 20jasper/5b8cae21c4f936506633b70c97066812 to your computer and use it in GitHub Desktop.
Delete videos from youtube playlist
This file contains 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
/* | |
Fill up your watch later playlist with a ton of videos? | |
Use this script to remove some! | |
Navigate to any YouTube playlist and run the script | |
I typically go to my watch later playlist and sort by oldest | |
Deletes around 1 video every 2 seconds | |
Edit `MAX_TO_REMOVE` to delete more or less videos | |
*/ | |
(() => { | |
const MAX_TO_REMOVE = 100; | |
const INTERVAL = { beforeRemove: 2 * 1_000, afterRemove: 1 * 1_000 }; | |
const SELECTORS = { | |
actionsMenu: '#primary button[aria-label="Action menu"]', | |
optionButton: "ytd-menu-service-item-renderer", | |
}; | |
function openOptions() { | |
document.querySelector(SELECTORS.actionsMenu).click(); | |
} | |
function removeVideo() { | |
[...document.querySelectorAll(SELECTORS.optionButton)] | |
.find((x) => x.innerText.toLowerCase().includes("remove from")) | |
.click(); | |
} | |
function sleep(ms) { | |
return new Promise((resolve) => setTimeout(resolve, ms)); | |
} | |
let i = 0; | |
const id = setInterval(async () => { | |
openOptions(); | |
await sleep(INTERVAL.beforeRemove); | |
removeVideo(); | |
i += 1; | |
if (i >= MAX_TO_REMOVE) { | |
clearInterval(id); | |
} | |
}, INTERVAL.afterRemove); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment