Skip to content

Instantly share code, notes, and snippets.

@ScottMaclure
Last active May 9, 2024 14:58
Show Gist options
  • Save ScottMaclure/80adda47040b039965248289c37cfe8b to your computer and use it in GitHub Desktop.
Save ScottMaclure/80adda47040b039965248289c37cfe8b to your computer and use it in GitHub Desktop.
Slack Draft Deleter
// Remove all drafts from your drafts view
// Navigate to drafts
// F12 to raise dev console
// Paste the below
(async function(x) {
for (let e = document.querySelector('[type="trash"]'); e != null; e = document.querySelector('[type="trash"]')) {
e.click();
await new Promise(resolve => setTimeout(resolve, 500))
document.querySelector('[data-qa="drafts_page_draft_delete_confirm"]').click();
await new Promise(resolve => setTimeout(resolve, 1500))
}
})();
@yiblet
Copy link

yiblet commented Sep 6, 2023

not all drafts are loaded on the screen at one time so you have modify the code like so:

(async function(x) {
    for (let e = document.querySelector('[type="trash"]'); e != null; e = document.querySelector('[type="trash"]')) {
        e.click(); 
        await new Promise(resolve => setTimeout(resolve, 500))
        document.querySelector('[data-qa="drafts_page_draft_delete_confirm"]').click();
        await new Promise(resolve => setTimeout(resolve, 1500))
    }
})();

Instead of using the iterator, we run the selector again in every loop so we catch the new elements as they load in.

@ScottMaclure
Copy link
Author

Updated OP with yiblet's improvement.

@frisch1
Copy link

frisch1 commented Oct 25, 2023

Don't know if just me (I'm awful at JS) but I was getting a Uncaught SyntaxError: Unexpected identifier 'document' when I tried to run it. Since I stink at JS (see previous), I asked GPT and it said the semicolons were missing from both setTimeouts.

Again, could be I had something set wrong in my Chrome console (on Mac Chrome), but like an obedient servant to my robot overlords, I put the semicolors in, tried again and, boom! worked.

Here's what I ran, only delta is the two semi-colons:

(async function(x) { 
  for (let e = document.querySelector('[type="trash"]'); e != null; e = document.querySelector('[type="trash"]')) { 
    e.click(); await new Promise(resolve => setTimeout(resolve, 500));
    document.querySelector('[data-qa="drafts_page_draft_delete_confirm"]').click(); 
    await new Promise(resolve => setTimeout(resolve, 1500));
  } 
})();

If I'm stating something obvious to everyone, my apologies. Intentions were pure. JS knowledge, not so much.

Thank you to everyone who contributed. I'd built up 110 drafts in Slack and it was going to drive me crazy clearing 'em out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment