Skip to content

Instantly share code, notes, and snippets.

@ThiefMaster
Last active December 15, 2015 11:48
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save ThiefMaster/1bed4d2f96c5bafbf1c8 to your computer and use it in GitHub Desktop.
function deleteComments(ids) {
var DELAY = 250;
function deleteComment(id) {
return $.ajax({
url: '/posts/comments/' + id + '/vote/10',
type: 'POST',
data: {
fkey: StackExchange.options.user.fkey
},
dataType: 'text'
});
}
function deleteNextComment() {
window.RESUME = resumeNoop;
var pct = ((total - ids.length) / total * 100).toFixed(1);
if(!ids.length) {
console.log('[' + pct + '%] All done!');
delete window.RESUME;
delete window.REMAINING;
return;
}
var id = ids.pop();
deleteComment(id).then(function(data) {
console.log('[' + pct + '%] Deleted ' + id + ' ' + data);
setTimeout(deleteNextComment, DELAY);
}, function(xhr, textStatus) {
console.log('Failed ' + id + ' ' + textStatus);
console.log('Call RESUME() to continue deleting');
console.log('Remaining IDs are stored in REMAINING');
window.RESUME = deleteNextComment;
window.REMAINING = ids;
ids.push(id);
});
}
function resumeNoop() {
console.log('Nothing to resume!');
}
var total = ids.length;
console.log('Going to delete ' + total + ' comments. This will take at least ' + (total * DELAY / 60000).toFixed(1) + ' minutes');
window.RESUME = resumeNoop;
deleteNextComment();
};
deleteComments([/* paste comma-separated ID list here */]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment