Skip to content

Instantly share code, notes, and snippets.

@mauvieira
Created January 24, 2024 01:05
Show Gist options
  • Save mauvieira/a34597fd8aa68ecf3a2bdb217e3ce555 to your computer and use it in GitHub Desktop.
Save mauvieira/a34597fd8aa68ecf3a2bdb217e3ce555 to your computer and use it in GitHub Desktop.
YouTube Bulk Unsubscribe
// go to https://www.youtube.com/feed/channels
// paste the code and hit enter
(async () => {
const UNSUBSCRIBE_DELAY_TIME = 2000;
const runAfterDelay = (fn, delay) =>
new Promise((resolve) => setTimeout(() => resolve(fn()), delay));
const channels = Array.from(document.querySelectorAll('ytd-channel-renderer'));
console.log(`${channels.length} channels found.`);
let ctr = 0;
for (const channel of channels) {
const unsubscribeButton = channel.querySelector('[aria-label^="Unsubscribe from"]');
if (unsubscribeButton) {
unsubscribeButton.click();
await runAfterDelay(() => {
const confirmDialog = document.querySelector('yt-confirm-dialog-renderer');
const confirmButton = confirmDialog?.querySelector('[aria-label^="Unsubscribe"]');
if (confirmButton) {
confirmButton.click();
console.log(`Unsubscribed ${++ctr}/${channels.length}`);
}
}, UNSUBSCRIBE_DELAY_TIME);
}
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment