Bulk Unsubscribe from YouTube Channels Using JavaScript
Chinmay R.
Software QA engineer @ Siemens Digital Industries Software | Experienced Product Development Engineer, CPU Performance Validation
Overview
If you've subscribed to many YouTube channels over time, bulk unsubscribing from channels can be time-consuming. This guide provides a JavaScript script to automate the bulk unsubscribe process directly from your browser's developer console. This script iterates through your subscriptions and automatically clicks the unsubscribe button on each channel.
Requirements
Disclaimer
Use this script responsibly, as bulk actions may lead to unexpected interactions with YouTube. Also, be aware that YouTube may limit certain automated actions or trigger temporary restrictions on your account.
Script Overview
Key Features
Code
Copy the following code into your browser's Developer Console to run the bulk unsubscribe operation:
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);
}
}
})();
Here is a Demo:
Right click and click "Inspect"
Click on Console:
and then enter the above code in the terminal
领英推荐
How to Stop the Script
This script includes an AbortController for safely stopping execution without closing your browser tab. To stop the script, type the following command into the Developer Console:
controller.abort();
Usage Instructions
Troubleshooting
Common Issues
Error Handling
The script checks for each critical element (unsubscribe button and confirm button) before attempting to interact with them. If any element is missing, an error message will be logged to the console, and the script will continue.
Adjusting the Delay
The UNSUBSCRIBE_DELAY_TIME variable sets the delay (in milliseconds) between each unsubscribe action. You can increase or decrease this value as needed:
var UNSUBSCRIBE_DELAY_TIME = 2000; // Default is 2000ms (2 seconds)
A longer delay reduces the chance of triggering YouTube’s rate limits, but it will take longer to complete.
Safety and Responsibility
YouTube may restrict accounts that perform rapid bulk actions. Adjust the delay time or take breaks between script executions to avoid triggering restrictions.
Note: This script is intended for educational purposes. Use responsibly and be aware of YouTube’s policies regarding automated actions.
This documentation provides the steps and code necessary for bulk unsubscribing from YouTube channels safely and efficiently, along with options for troubleshooting and stopping the script as needed. Enjoy a cleaner subscription feed!
Web Development
2 周helpful