-
-
Save ThiefMaster/1bed4d2f96c5bafbf1c8 to your computer and use it in GitHub Desktop.
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
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