Skip to content

Instantly share code, notes, and snippets.

@phixion
Created April 6, 2026 20:38
Show Gist options
  • Select an option

  • Save phixion/2d220971778879b56923bbd3da387029 to your computer and use it in GitHub Desktop.

Select an option

Save phixion/2d220971778879b56923bbd3da387029 to your computer and use it in GitHub Desktop.
delete all reddit comments from browser console
// --- REDDIT COMMENT DELETER MACRO (OLD REDDIT) ---
// Adjust the 'delayBetweenDeletes' value if you encounter "Too Many Requests" (Error 429).
// A higher number is safer but slower. 1000ms (1 second) is often a good starting point.
const delayBetweenDeletes = 1000; // Delay in milliseconds (1000ms = 1 second)
let deleteCount = 0;
function deleteComments() {
const deleteLinks = document.querySelectorAll(
'a.togglebutton[data-event-action="delete"]',
);
if (deleteLinks.length === 0) {
console.log("No more delete buttons found on this page.");
// Check for "next" button to go to the next page of comments
const nextButton = document.querySelector(".next-button a");
if (nextButton) {
console.log("Navigating to the next page...");
nextButton.click();
// Wait a few seconds for the new page to load before restarting the process
setTimeout(() => {
console.log(
"Restarting script on new page. You may need to run the macro again if it does not auto-start.",
);
deleteComments(); // Recursively call to continue on the next page
}, 5000);
} else {
console.log('Finished all pages or "next" button not found.');
alert(
"Comment deletion finished! Total comments deleted this session: " +
deleteCount,
);
}
return;
}
// Process one comment at a time to manage rate-limiting
const currentDeleteLink = deleteLinks[0];
// 1. Click the "delete" link
console.log("Clicking delete link for comment...");
currentDeleteLink.click();
// Wait a short time for the "yes / no" confirmation prompt to appear
setTimeout(() => {
// 2. Click the "yes" confirmation button
// On old Reddit, the 'yes' link is often found with class 'yes' and an onclick handler
const confirmButton = document.querySelector(
"span.option.error.active > a.yes",
);
if (confirmButton) {
console.log("Confirming deletion...");
confirmButton.click();
deleteCount++;
console.log("Comment deleted. Total deleted: " + deleteCount);
} else {
// Fallback for an alternative selector if the primary one fails
const confirmFallback = document.querySelector(
'a.yes[onclick*="change_state"]',
);
if (confirmFallback) {
console.log("Confirming deletion (fallback)...");
confirmFallback.click();
deleteCount++;
console.log("Comment deleted. Total deleted: " + deleteCount);
} else {
console.error(
'Could not find the confirmation "yes" button for the current comment.',
);
}
}
// Wait the defined delay before processing the next comment
setTimeout(deleteComments, delayBetweenDeletes);
}, 300); // Short delay (300ms) to ensure the confirmation dialog is rendered
}
console.log("--- Starting Reddit Comment Deletion Script ---");
deleteComments();
@phixion

phixion commented Apr 6, 2026

Copy link
Copy Markdown
Author

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