Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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