Bulk delete your tweets from the JavaScript console

Posted by Jen Tong on October 12, 2018

I’m a big fan of cleaning up after myself on the Internet. I even wrote some blog posts about it in the past.

One of the hard parts about cleaning up is deleting old content, like Tweets. It often requires time consuming manual deletion, or tinkering around with an API that changes each time you use it. There are websites that provide this service for Twitter, but they all require very aggressive OAuth permission grants, or (worse yet) your Twitter login credentials. I didn’t feel comfortable with either of those options.

So, inspired Norberth’s 2015 answer to a Quora question, I hacked up some JavaScript for deleting old Tweets from your console that works as of October 2018.

Tweet deletion hacky script in action!

Here’s how to use it:

  1. Read all of the code on this blog post. Understand it before you paste it into your console. Pasting random stuff into your console is very dangerous!
  2. Fix the script, since it likely broke
  3. Go to your twitter profile page.
  4. Scroll down until there aren’t any more tweets to load.
  5. Paste this JS into your web browser’s JavaScript console.

     // get all the buttons
     var buttons = $('.js-actionDelete button'); 
        
     // don't delete most recent 50
     buttonsOfTweetsToDelete = buttons.slice(50);
        
     function deleteTweet(tweets) {
     // exit if there's nothing to do
     if(tweets.length == 0) {
       return;
     }
        
     // grab a tweet
     tweet = tweets[0];
     // slice off the one we got
     tweets = tweets.slice(1);
        
     // push the delete button
     tweet.click();
     // wait 1000ms, hit modal button
     setTimeout(function() {
       $('.delete-action').click();
       // delete next one after 500ms
       setTimeout(function() {
         deleteTweet(tweets);
       }, 500);
     }, 1000);
     }
        
     // run the deletion function
     deleteTweet(buttonsOfTweetsToDelete);
    
  6. Enjoy your tidy Twitter profile!
  7. If you fixed the script, tell me how and I’ll update this post.