Skip to content

Instantly share code, notes, and snippets.

@frarredondo
Created January 5, 2025 23:30
Show Gist options
  • Save frarredondo/1af703c0c4c47868e809f7eb0d16801e to your computer and use it in GitHub Desktop.
Save frarredondo/1af703c0c4c47868e809f7eb0d16801e to your computer and use it in GitHub Desktop.
Script to unsubscribe from all from all YouTube channels
// Usage Instructions
// Note: YouTube often updates it's DOM structure, so you may need to udpate the DOM query selectors.
// 1. Open the Manage Subscriptions page: https://www.youtube.com/feed/channels.
// 2. Open the browser's developer tools (Ctrl+Shift+I or Cmd+Option+I on Mac) and navigate to the Console tab.
// 3. Paste the script and press Enter.
// 4. Let the script run until it completes.
(async () => {
const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
// Step 1: Scroll to load all subscriptions
console.log("Scrolling to load all subscriptions...");
let lastHeight = 0;
let currentHeight = document.documentElement.scrollHeight;
while (currentHeight !== lastHeight) {
window.scrollTo(0, currentHeight);
await delay(15000); // Wait for content to load
lastHeight = currentHeight;
currentHeight = document.documentElement.scrollHeight;
}
console.log("All subscriptions loaded.");
// Step 2: Find all "Unsubscribe" buttons
const unsubscribeButtons = Array.from(
document.querySelectorAll(
'ytd-subscribe-button-renderer yt-button-shape button[aria-label^="Unsubscribe"]'
)
);
console.log(`Found ${unsubscribeButtons.length} subscriptions.`);
// Step 3: Unsubscribe from each channel
for (let i = 0; i < unsubscribeButtons.length; i++) {
const button = unsubscribeButtons[i];
if (button) {
console.log(`Unsubscribing from channel ${i + 1} of ${unsubscribeButtons.length}`);
button.click();
await delay(2000); // Wait for confirmation dialog
// Step 4: Handle the confirmation dialog
const confirmDialog = document.querySelector('yt-confirm-dialog-renderer');
if (confirmDialog) {
const confirmButton = confirmDialog.querySelector(
'yt-button-renderer#confirm-button button'
);
if (confirmButton) {
confirmButton.click();
console.log(`Confirmed unsubscription from channel ${i + 1}`);
await delay(2000); // Wait for the action to complete
} else {
console.warn(`Confirm button not found for channel ${i + 1}`);
}
} else {
console.warn(`Confirmation dialog not found for channel ${i + 1}`);
}
}
}
console.log("Unsubscription process completed.");
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment