Skip to content

Instantly share code, notes, and snippets.

@bludnic
Created January 5, 2024 05:49
Show Gist options
  • Save bludnic/69453d2bb951a8a3f5777ed49ebce444 to your computer and use it in GitHub Desktop.
Save bludnic/69453d2bb951a8a3f5777ed49ebce444 to your computer and use it in GitHub Desktop.
Unsubscribing from all YouTube channels
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();
@bludnic
Copy link
Author

bludnic commented Jan 5, 2024

  1. Go to the channels page https://www.youtube.com/feed/channels?app=desktop
  2. Scroll to very bottom of the page to load all channels
  3. Open DevTools
  4. Paste the code above
  5. Drink your ☕ until it's done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment