Skip to content

Instantly share code, notes, and snippets.

@dexhunter
Last active December 1, 2024 10:54
Show Gist options
  • Save dexhunter/69f244771c1d238449dd58f9ece4380d to your computer and use it in GitHub Desktop.
Save dexhunter/69f244771c1d238449dd58f9ece4380d to your computer and use it in GitHub Desktop.
do it at chrome console
/**
* YouTube bulk unsubscribe fn.
* Wrapping this in an IIFE for browser compatibility.
*/
(async function iife() {
// This is the time delay after which the "unsubscribe" button is "clicked"; Change it as per your need!
var UNSUBSCRIBE_DELAY_TIME = 2000
/**
* Delay runner. Wraps `setTimeout` so it can be `await`ed on.
* @param {Function} fn
* @param {number} delay
*/
var runAfterDelay = (fn, delay) => new Promise((resolve, reject) => {
setTimeout(() => {
fn()
resolve()
}, delay)
})
// Get the channel list; this can be considered a row in the page.
var channels = Array.from(document.getElementsByTagName(`ytd-channel-renderer`))
console.log(`${channels.length} channels found.`)
var ctr = 0
for (const channel of channels) {
// Get the subscribe button and trigger a "click"
channel.querySelector(`[aria-label^='Unsubscribe from']`).click()
await runAfterDelay(() => {
// Get the dialog container...
document.getElementsByTagName(`yt-confirm-dialog-renderer`)[0]
// and find the confirm button...
.querySelector(`[aria-label^='Unsubscribe']`).click()
console.log(`Unsubsribed ${ctr + 1}/${channels.length}`)
ctr++
}, UNSUBSCRIBE_DELAY_TIME)
}
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment