Last active
April 13, 2023 14:26
-
-
Save ShetlandJ/ff6c16c57318b3012573af9e4b193967 to your computer and use it in GitHub Desktop.
Delete reddit comments on mass/bulk with javascript and Reddit Enhancement Suite
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// PLEASE NOTE: this assumes that you have Reddit Enhancement Suite installed and you're on https://old.reddit.com/user/{yourUserName}/comments/ | |
// This script will first grab all visible comments on the page, and then start deleting them. | |
// Eventually, once the list is exhausted, it will execute a scroll to event which will | |
// open up a new page of comments, and the deleteComments sequence will re-run. | |
// It also checks if the function has stopped running for any reason, and will attempt to re-run it. | |
const deleteComments = (() => { | |
const $domNodeToIterateOver = $('.del-button .option .yes'); | |
let currentTime = 0; | |
const timeInterval = 400; | |
let counter = 0; | |
let previousCounterValue = -1; | |
const checkIfFunctionIsRunning = () => { | |
if (counter === previousCounterValue) { | |
console.log('deleteComments has stopped running, rerunning...'); | |
deleteComments(); | |
} else { | |
previousCounterValue = counter; | |
setTimeout(checkIfFunctionIsRunning, 5000); | |
} | |
} | |
return () => { | |
counter++; | |
$domNodeToIterateOver.each(function () { | |
const $this = $(this); | |
currentTime += timeInterval; | |
setTimeout(() => { | |
$this.click(); | |
// If this is the last comment to be deleted, scroll to the bottom of the page | |
if ($this.is($domNodeToIterateOver.last())) { | |
setTimeout(() => { | |
window.scrollTo(0, document.body.scrollHeight); | |
// Wait for scrolling to finish before running deleteComments again | |
setTimeout(() => { | |
currentTime = 0; | |
checkIfFunctionIsRunning(); | |
}, 1500); | |
}, 1500); | |
} | |
}, currentTime); | |
}); | |
} | |
})(); | |
// Call the function to start deleting comments | |
deleteComments(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment