I'm not a developer or anything, but I encountered an issue. I attempted to unsubscribe following the instructions from a YouTube video titled 'How to unsubscribe from all your YouTube channels at once.' Despite following all the steps as instructed in the video, the code doesn't seem to work.
It says
{<rejected>: TypeError: Cannot read properties of null (reading 'click')
at iife (<anonymous>:25:58)
at …}[[Prototype]]: Promisecatch: ƒ catch()constructor: ƒ Promise()finally: ƒ finally()then: ƒ then()Symbol(Symbol.toStringTag): "Promise"[[Prototype]]: Object[[PromiseState]]: "rejected"[[PromiseResult]]: TypeError: Cannot read properties of null (reading 'click')
at iife (<anonymous>:25:58)
at <anonymous>:35:3args: [{…}]message: "Cannot read properties of null (reading 'click')"stack: "TypeError: Cannot read properties of null (reading 'click')\n at iife (<anonymous>:25:58)\n at <anonymous>:35:3"[[Prototype]]: Error
Code
/*
* 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);
}
})();
Can somebody assist please ?