Skip to content

Instantly share code, notes, and snippets.

@ealvesss
Created January 17, 2024 19:36
Show Gist options
  • Save ealvesss/6030951ef7643a6945771dfb5ed93e17 to your computer and use it in GitHub Desktop.
Save ealvesss/6030951ef7643a6945771dfb5ed93e17 to your computer and use it in GitHub Desktop.
Youtube Channel Unsubscriber
(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 awaited on.
* @param {number} delay
*/
var wait = (delay) => new Promise((resolve) => setTimeout(resolve, delay));
/**
* Scroll down the page to load more content.
*/
async function scrollPage() {
window.scrollBy(0, window.innerHeight);
await wait(1000); // Adjust this delay as needed to allow content to load
}
// Keep track of the total number of channels unsubscribed
var totalUnsubscribed = 0;
async function unsubscribeFromChannels() {
try {
// Get the channel list; this can be considered a row in the page.
var channels = Array.from(
document.querySelectorAll(
"ytd-subscription-notification-toggle-button-renderer-next > yt-button-shape > button"
)
);
if (channels.length === 0) {
console.log("No more channels to unsubscribe.");
return;
}
for (const channel of channels) {
// Get the subscribe button and trigger a "click"
channel.click();
await wait(100);
document
.querySelector("#items > ytd-menu-service-item-renderer:nth-child(2)")
.click();
await wait(800);
document
.querySelector("#confirm-button > yt-button-shape > button > yt-touch-feedback-shape")
.click();
await wait(UNSUBSCRIBE_DELAY_TIME);
totalUnsubscribed++;
}
// Scroll to load more channels
await scrollPage();
unsubscribeFromChannels();
} catch (e) {
console.error(e);
}
}
// Start the unsubscribe process
unsubscribeFromChannels();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment