Created
January 5, 2024 05:49
-
-
Save bludnic/69453d2bb951a8a3f5777ed49ebce444 to your computer and use it in GitHub Desktop.
Unsubscribing from all YouTube channels
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
function findElements(textContent, selector = "*") { | |
const elements = document.querySelectorAll(selector); | |
return Array.prototype.slice | |
.call(elements) | |
.filter((el) => el.textContent === textContent); | |
} | |
function findElement(textContent, selector = "*") { | |
const elements = findElements(textContent, selector); | |
return elements[0]; | |
} | |
const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms)); | |
async function run() { | |
const channels = findElements( | |
"Subscribed", | |
"#notification-preference-button span.yt-core-attributed-string.yt-core-attributed-string--white-space-no-wrap", | |
); | |
console.log(`Channels found: ${channels.length}`); | |
for (let i = 0; i < channels.length; i++) { | |
console.log(`Unsubscribing from ${i + 1} of ${channels.length} channels`); | |
channels[i].click(); | |
await delay(100); | |
const unsubscribe = findElement("Unsubscribe"); | |
unsubscribe.click(); | |
await delay(500); | |
const confirm = findElement( | |
"Unsubscribe", | |
"button[aria-label=Unsubscribe]", | |
); | |
confirm.click(); | |
} | |
console.log("Done 🎉"); | |
} | |
run(); |
Author
bludnic
commented
Jan 5, 2024
- Go to the channels page https://www.youtube.com/feed/channels?app=desktop
- Scroll to very bottom of the page to load all channels
- Open DevTools
- Paste the code above
- Drink your ☕ until it's done
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment