Created
January 24, 2024 01:05
-
-
Save mauvieira/a34597fd8aa68ecf3a2bdb217e3ce555 to your computer and use it in GitHub Desktop.
YouTube Bulk Unsubscribe
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
// 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