How can I remove all my youtube comments without having to delete my entire Youtube channel?
1 Answer
I came across this problem when I wanted to delete all my Youtube Comments on other videos without removing my entire channel.
As far as I know there is no native way to delete them and they have to be deleted manually 1 by 1. Well, nothing has to be done manually in this time and age of automation, so here I would like to share my auto-remove JavaScript with you.
Step 1: Go to https://myactivity.google.com/page?hl=de&utm_medium=web&utm_source=youtube&page=youtube_comments
Step 2: Press F12 to open the Browser console and navigate to "Console" (in Firefox it is called like this, not sure about other browsers, but they all have this kind of debugging feature)
Step 3: Paste in this script and let it run. Sometimes the process gets stuck or falters, but it should work for quite a long time. You can increase the delays to make sure it keeps up with your internet speed and PC/Browser specs. If it stops working, simply refresh the page and paste the code again. Upon pasting it a first time, the browser might warn you and ask you to type something into the console to make sure you know what you're doing. If you want to be able to paste the script and execute it, you will have to follow this instructions.
CAUTION: Use on your own risk as some websites might have policy against automated actions like this!!!
Script:
(async function autoDeleteYouTubeComments() {
// Configuration
const DELETE_ARIA_LABEL = "Aktivitätselement löschen"; // Part of aria-label for delete buttons
const DELETE_DELAY_MIN = 50; // Minimum delay time in ms (0.05 seconds)
const DELETE_DELAY_MAX = 250; // Maximum delay time in ms (0.25 seconds)
const COMMENTS_BEFORE_PAUSE = 50; // Number of comments to delete before pausing
const PAUSE_TIME = 7500; // 5 seconds pause after deleting COMMENTS_BEFORE_PAUSE comments
const SCROLL_DELAY = 150; // Delay between scroll attempts to load new content (in ms)
const MAX_SCROLL_ATTEMPTS = 7; // Maximum number of scroll attempts
const MAX_NEARBY_ATTEMPTS = 5; // Maximum attempts to find a new nearby button
// Utility function to pause execution for a given time
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
// Function to scroll down until all content is loaded, with a limit of 5 attempts
async function scrollToEnd() {
let lastHeight = document.body.scrollHeight;
let attempts = 0;
console.log("Starting to scroll down to load all content...");
while (attempts < MAX_SCROLL_ATTEMPTS) {
window.scrollTo(0, document.body.scrollHeight);
await sleep(SCROLL_DELAY);
let newHeight = document.body.scrollHeight;
if (newHeight === lastHeight) {
attempts++;
console.log(`No new content loaded. Attempt ${attempts}/${MAX_SCROLL_ATTEMPTS}.`);
} else {
attempts = 0; // Reset the attempts if new content is loaded
lastHeight = newHeight;
console.log("New content loaded, continuing to scroll...");
}
}
console.log("Finished scrolling. All content should now be loaded.");
}
// Function to scroll back to the top of the page
async function scrollToTop() {
console.log("Scrolling back to the top...");
window.scrollTo(0, 0);
await sleep(1000); // Wait for the scroll to complete
console.log("Scrolled to the top.");
}
// Function to find the next delete button by checking the aria-label for "Aktivitätselement löschen"
function findDeleteButtons() {
const buttons = Array.from(document.querySelectorAll('button'));
const deleteButtons = buttons.filter(button => {
const ariaLabel = button.getAttribute('aria-label') || '';
const innerText = button.innerText || '';
const classList = button.classList || [];
// Ensure we do not select the revert button
const isRevertButton = innerText.includes("Abbrechen") || classList.contains("x95qze");
// Only return delete buttons that match this aria-label and are not revert buttons
return ariaLabel.startsWith(DELETE_ARIA_LABEL) && !isRevertButton;
});
return deleteButtons; // Return all delete buttons found
}
// Function to generate a random delay between DELETE_DELAY_MIN and DELETE_DELAY_MAX
function getRandomDeleteDelay() {
return Math.random() * (DELETE_DELAY_MAX - DELETE_DELAY_MIN) + DELETE_DELAY_MIN;
}
// Function to pick a nearby delete button
function pickNearbyDeleteButton(deleteButtons, currentIndex) {
const nearbyRange = 2; // Define the range of nearby buttons (±2 positions)
const startIndex = Math.max(0, currentIndex - nearbyRange); // Prevent going out of bounds
const endIndex = Math.min(deleteButtons.length - 1, currentIndex + nearbyRange); // Prevent going out of bounds
// Randomly select an index from the nearby range
const nearbyIndex = Math.floor(Math.random() * (endIndex - startIndex + 1)) + startIndex;
return deleteButtons[nearbyIndex];
}
// Function to pick a completely random delete button
function pickRandomDeleteButton(deleteButtons) {
const randomIndex = Math.floor(Math.random() * deleteButtons.length);
return deleteButtons[randomIndex];
}
// Main function to handle deletion
async function deleteComments() {
let deletedCount = 0; // Initialize a counter to track the number of deleted comments
let currentIndex = 0; // Keep track of the current delete button index
let deleteButtons = findDeleteButtons(); // Initially load the list of delete buttons
while (deleteButtons.length > 0) {
let deleteButton;
let attempts = 0;
// Try to find a "new" nearby delete button
while (attempts < MAX_NEARBY_ATTEMPTS) {
deleteButton = pickNearbyDeleteButton(deleteButtons, currentIndex);
break; // Always break since the button will never be a duplicate
}
// Scroll to the delete button to visualize the deletion
deleteButton.scrollIntoView({ behavior: 'smooth', block: 'center' });
console.log("Scrolling to the delete button...");
await sleep(1000); // Wait a moment to let the user see the scroll
// Click the delete button
deleteButton.click();
console.log("Delete button clicked.");
// Remove the clicked button from the list
deleteButtons = deleteButtons.filter(button => button !== deleteButton);
// Increment the deleted comment counter
deletedCount++;
console.log(`Deleted ${deletedCount} comment(s). Remaining delete buttons: ${deleteButtons.length}`);
// Update the current index (randomly choose a new nearby index)
currentIndex = deleteButtons.indexOf(deleteButton);
// Wait for the deletion to process with a random delay before the next action
const randomDelay = getRandomDeleteDelay();
console.log(`Waiting for ${randomDelay.toFixed(0)}ms before refreshing and checking for the next deletion.`);
await sleep(randomDelay);
// Pause for 7.5 seconds after every 50 deletions
if (deletedCount % COMMENTS_BEFORE_PAUSE === 0) {
console.log(`Pausing for ${PAUSE_TIME / 1000} seconds after deleting ${deletedCount} comments...`);
await sleep(PAUSE_TIME);
}
}
console.log("All deletions completed.");
}
// Execute the steps
await scrollToEnd(); // Scroll down to load all content
await scrollToTop(); // Scroll back to the top of the page
await deleteComments(); // Start deleting comments
})();
I deleted 3,000 comments this way and it only took one hour of keeping my browser open in the background.
This code does not only do what it should, it looks damn cool while doing it (the way it scrolls around to find buttons to delete in the vicinity just feels really snappy!)