0% found this document useful (0 votes)
33 views2 pages

Youtube Bulk Unsubsribe FN

This document contains a Javascript function that automates unsubscribing from multiple YouTube channels. It gets a list of channels on the page, clicks the unsubscribe button for each one, then clicks the confirm button in the dialog that appears, with a delay between each channel to mimic user behavior. The function is wrapped in an immediately invoked function expression (IIFE) for browser compatibility.

Uploaded by

Aqha C Thelay
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views2 pages

Youtube Bulk Unsubsribe FN

This document contains a Javascript function that automates unsubscribing from multiple YouTube channels. It gets a list of channels on the page, clicks the unsubscribe button for each one, then clicks the confirm button in the dialog that appears, with a delay between each channel to mimic user behavior. The function is wrapped in an immediately invoked function expression (IIFE) for browser compatibility.

Uploaded by

Aqha C Thelay
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

/**

* Youtube bulk unsubsribe fn.

* Wrapping this in an IIFE for browser compatibility.

*/

(async function iife() {

// This is the time delay after which the "unsubscribe" button is "clicked"; Tweak to your liking!

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 subsribe 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(`#confirm-button`)

// and "trigger" the click!

.click()

console.log(`Unsubsribed ${ctr + 1}/${channels.length}`)

ctr++

}, UNSUBSCRIBE_DELAY_TIME)

})()
/** * Youtube bulk unsubsribe fn. * Wrapping this in an IIFE for browser compatibility. */ (async
function iife() { // This is the time delay after which the "unsubscribe" button is "clicked"; Tweak
to your liking! 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 subsribe 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(`#confirm-button`) // and
"trigger" the click! .click() console.log(`Unsubsribed ${ctr + 1}/${channels.length}`) ctr++ },
UNSUBSCRIBE_DELAY_TIME) } })()

You might also like