Skip to content

Instantly share code, notes, and snippets.

@laughingclouds
Created December 8, 2021 20:49
Show Gist options
  • Save laughingclouds/ccb32a706a70f5f68756d956e54ab4dc to your computer and use it in GitHub Desktop.
Save laughingclouds/ccb32a706a70f5f68756d956e54ab4dc to your computer and use it in GitHub Desktop.
Purge all your comments from reddit
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
function clickDeleteFromSelection(selectedNode) {
for (let childNode of selectedNode.anchorNode.childNodes) {
if (childNode.innerText == "Delete") {
childNode.click();
}
}
}
function clickDeleteConfirmation() {
let btnList = Array.from(document.getElementsByTagName("button"));
for (let btn of btnList) {
if (btn.innerText == "Delete") {
btn.click();
break;
}
}
}
let optionDotCollection = document.getElementsByClassName("_38GxRFSqSC-Z2VLi5Xzkjy icon icon-overflow_horizontal");
let optionBtnList = Array.from(optionDotCollection, element => element.parentElement);
let total = optionBtnList.length;
let count = 0;
let isRunning = false;
async function clickAllButtons() {
isRunning = true;
for (let optionBtn of optionBtnList) {
optionBtn.click();
await sleep(500);
let selectedNode = document.getSelection();
clickDeleteFromSelection(selectedNode);
await sleep(500);
clickDeleteConfirmation();
count++;
console.log(`Deleted ${count} comments...`, `\n${total - count} left...`);
await sleep(500);
}
isRunning = false;
}
clickAllButtons();
function sleep(ms: number) {
return new Promise(resolve => setTimeout(resolve, ms));
}
function clickDeleteFromSelection(selectedNode: Selection) {
for (let childNode of selectedNode.anchorNode.childNodes) {
if (childNode.innerText == "Delete") {
childNode.click();
}
}
}
function clickDeleteConfirmation() {
let btnList = Array.from(document.getElementsByTagName("button"));
for (let btn of btnList) {
if (btn.innerText == "Delete") {
btn.click();
break;
}
}
}
let optionDotCollection = document.getElementsByClassName("_38GxRFSqSC-Z2VLi5Xzkjy icon icon-overflow_horizontal");
let optionBtnList = Array.from(optionDotCollection, element => element.parentElement);
let total = optionBtnList.length;
let count = 0;
let isRunning = false;
async function clickAllButtons() {
isRunning = true;
for (let optionBtn of optionBtnList) {
optionBtn.click();
await sleep(500);
let selectedNode = document.getSelection();
clickDeleteFromSelection(selectedNode);
await sleep(500);
clickDeleteConfirmation();
count++;
console.log(`Deleted ${count} comments...`,
`\n${total - count} left...`);
await sleep(500);
}
isRunning = false;
}
clickAllButtons();
@laughingclouds
Copy link
Author

laughingclouds commented Dec 8, 2021

I wrote it in typescript, and then compiled to js.
For some reason it wouldn't work properly in Vivaldi 5.0.2497.24 stable; OS: linux mint 20.1 x86_64.

HOW TO RUN
Navigate to either
[replace YOUR_USER_NAME with...well...your user name]
https://www.reddit.com/user/YOUR_USER_NAME/comments/
or
https://www.reddit.com/user/YOUR_USER_NAME
[More preferably the former]

Then copy code from selfPurge.js and simply run it in the console.

There's another issue; namely, lazy loading. Since all comment/post data won't be loaded; quite reasonably, all comments/posts won't be deleted.
You'll have to scroll down, and call clickAllButtons() again.
Anyways, at least it works (I was able to delete more than 150 comments/posts under 5 minutes) (I think...didn't count).

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