Skip to content

Instantly share code, notes, and snippets.

@thehig
Created July 26, 2016 18:14
Show Gist options
  • Save thehig/70e35ce23b4277df92ba87fcde14600c to your computer and use it in GitHub Desktop.
Save thehig/70e35ce23b4277df92ba87fcde14600c to your computer and use it in GitHub Desktop.
js: Automate slack message deletion
/*Works on Slack Archive Page*/
function delNext(delay, cb){
console.log("Starting delete");
/*Click Delete*/
document.querySelector('#batch_delete_link').click();
setTimeout(function(){
/*Click All*/
document.querySelector('#batch_delete_div > p:nth-child(3) > a:nth-child(2)').click();
setTimeout(function(){
/*Click Delete*/
document.querySelector('#batch_delete_button').click();
setTimeout(function(){
/*Click Yes*/
document.querySelector('#generic_dialog > div.modal-footer > a.btn.dialog_go.btn_danger').click();
cb();
}, delay);
}, delay);
}, delay);
}
var manualAbort = false;
function poll(interval, cb){
if(manualAbort) return;
console.log("Poll");
var popup = document.querySelector('#generic_dialog');
if(popup === null) {
console.log("Poll Complete");
cb();
return;
}
setTimeout(function(){
poll(interval, cb);
}, interval);
}
function delLoop(){
delNext(500, function(){
console.log("Deleting");
poll(2000, function(){
console.log("Done deleting");
});
});
}
delLoop();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment