Skip to content

Instantly share code, notes, and snippets.

@itsazzad
Last active March 10, 2024 13:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itsazzad/c1d86c5db86258ca129554a7b9ed92a7 to your computer and use it in GitHub Desktop.
Save itsazzad/c1d86c5db86258ca129554a7b9ed92a7 to your computer and use it in GitHub Desktop.
YouTube mass unsubscribe
// Go to the following link in your YouTube: https://www.youtube.com/feed/channels
// Scroll the page all the way down until you reach the very last subscribed channel in your list
const DELAY = 100;
const delay = ms => new Promise(res => setTimeout(res, ms));
const list = document.querySelectorAll("#grid-container > ytd-channel-renderer");
for (let index = 0; index < list.length; index++) {
console.log("")
console.log(index, list.length - index)
const sub = list[index];
sub.scrollIntoView();
console.log(sub.querySelector("ytd-channel-name").innerText);
console.log(sub.querySelector("#notification-preference-button").innerText);
const preferences = Array.from(sub.querySelectorAll("#notification-preference-button button"));
const subscribed = preferences.find(el => {
return el.textContent.includes("Subscribed");
});
if (subscribed) {
subscribed.click();
await delay(DELAY);
}
const services = Array.from(document.querySelectorAll("#items > ytd-menu-service-item-renderer"));
const unsubscribe = services.find(el => {
return el.textContent.includes("Unsubscribe");
});
if (unsubscribe) {
unsubscribe.click();
await delay(DELAY);
}
const confirm = document.querySelector("#confirm-button button");
if (confirm) {
confirm.click();
await delay(DELAY);
}
console.log(sub.querySelector("#subscribe-button").innerText)
}
@matteoscaringi
Copy link

i like how my chrome just gets locked up when running it

@itsazzad
Copy link
Author

i like how my chrome just gets locked up when running it

It should not be locked

@Ahmad-b1995
Copy link

thanks for the script,
on line 23, I replaced "#confirm-button > a" with "#confirm-button button" and it worked.

@itsazzad
Copy link
Author

thanks for the script, on line 23, I replaced "#confirm-button > a" with "#confirm-button button" and it worked.

Thanks, I have updated the code.

@fahamjv
Copy link

fahamjv commented Mar 10, 2024

Note:
Type 'allow pasting' before entering the script to disable paste protection in Chrome dev tools.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment