How to unsubscribe from all the Youtube channels at once
Code
-------
const controller = new AbortController();
const signal = controller.signal;
(async function iife() {
try {
var UNSUBSCRIBE_DELAY_TIME = 2000; // Adjust delay as needed
var runAfterDelay = (fn, delay) => new Promise((resolve) => {
setTimeout(() => {
if (!signal.aborted) fn();
resolve();
}, delay);
});
var channels = Array.from(document.getElementsByTagName(`ytd-channel-renderer`));
console.log(`${channels.length} channels found.`);
var ctr = 0;
for (const channel of channels) {
if (signal.aborted) break; // Stop loop if signal is aborted
const unsubscribeButton = channel.querySelector(`[aria-label^='Unsubscribe from']`);
if (unsubscribeButton) {
unsubscribeButton.click();
await runAfterDelay(() => {
const dialogContainer = document.getElementsByTagName(`yt-confirm-dialog-renderer`)[0];
if (dialogContainer) {
const confirmButton = dialogContainer.querySelector(`[aria-label^='Unsubscribe']`);
if (confirmButton) {
confirmButton.click();
console.log(`Unsubscribed ${ctr + 1}/${channels.length}`);
ctr++;
} else {
console.error("Confirm button not found.");
}
} else {
console.error("Dialog container not found.");
}
}, UNSUBSCRIBE_DELAY_TIME);
} else {
console.error("Unsubscribe button not found for a channel.");
}
}
} catch (e) {
if (signal.aborted) {
console.log("Script aborted.");
} else {
console.error(e);
}
}
})();
---
Not Working i guess
----
var i = 0;
var myVar = setInterval(myTimer, 3000);
function myTimer () {
var els = document.getElementById("grid-container").getElementsByClassName("ytd-expanded-shelf-contents-renderer");
if (i < els.length) {
els[i].querySelector("[aria-label^='Unsubscribe from']").click();
setTimeout(function () {
var unSubBtn = document.getElementById("confirm-button").click();
}, 2000);
setTimeout(function () {
els[i].parentNode.removeChild(els[i]);
}, 2000);
}
i++;
console.log(i + " unsubscribed by YOGIE");
console.log(els.length + " remaining");
}
--
Step 1: Go to https://www.youtube.com/feed/channels and scroll to the bottom of the page to populate all items to the screen.
Step 2: Right-click anywhere on the page and click "Inspect Element" (or just "Inspect"), then click "Console", then copy–paste the below script, then hit return.
Comments
Post a Comment