How to bulk unfollow people on Twitter through your web browser
I wanted to do some cleanup for a couple of Twitter accounts I use last night as I'm following too many people. One account has thousands of them which would of course take a long time to do manually.
Normally, I'd just write a Python script and do it via the API but I decided to do a quick search to see if there's an easier way.
It turned out, there is! I found this nice little Javascript script to unfollow everyone that someone posted on GitHub. You can basically just open the Developer Console on your Chrome or Brave browser and paste the code in there and run.
Step 1: While logged in to Twitter, go to your Profile > Following (e.g. https://twitter.com/jcalazan/following), then right-click anywhere on the page and select Inspect (or press CTRL+SHIFT+I) to open the dev console.
Step 2: Click the Console tab.
Step 3: Paste the code below and hit enter.
// Unfollow everyone on twitter.com, by Jamie Mason (https://twitter.com/fold_left) // https://gist.github.com/JamieMason/7580315 // // 1. Go to https://twitter.com/YOUR_USER_NAME/following // 2. Open the Developer Console. (COMMAND+ALT+I on Mac) // 3. Paste this into the Developer Console and run it // // Last Updated: 09 April 2020 (() => { const $followButtons = '[data-testid$="-unfollow"]'; const $confirmButton = '[data-testid="confirmationSheetConfirm"]'; const retry = { count: 0, limit: 3, }; const scrollToTheBottom = () => window.scrollTo(0, document.body.scrollHeight); const retryLimitReached = () => retry.count === retry.limit; const addNewRetry = () => retry.count++; const sleep = ({ seconds }) => new Promise((proceed) => { console.log(`WAITING FOR ${seconds} SECONDS...`); setTimeout(proceed, seconds * 1000); }); const unfollowAll = async (followButtons) => { console.log(`UNFOLLOWING ${followButtons.length} USERS...`); await Promise.all( followButtons.map(async (followButton) => { followButton && followButton.click(); await sleep({ seconds: 1 }); const confirmButton = document.querySelector($confirmButton); confirmButton && confirmButton.click(); }) ); }; const nextBatch = async () => { scrollToTheBottom(); await sleep({ seconds: 1 }); const followButtons = Array.from(document.querySelectorAll($followButtons)); const followButtonsWereFound = followButtons.length > 0; if (followButtonsWereFound) { await unfollowAll(followButtons); await sleep({ seconds: 2 }); return nextBatch(); } else { addNewRetry(); } if (retryLimitReached()) { console.log(`NO ACCOUNTS FOUND, SO I THINK WE'RE DONE`); console.log(`RELOAD PAGE AND RE-RUN SCRIPT IF ANY WERE MISSED`); } else { await sleep({ seconds: 2 }); return nextBatch(); } }; nextBatch(); })();
That's it! Now just watch it run and wait. It will automatically scroll down and batch-unfollow Twitter profiles. You may need to run it a few times by pasting the code again as it might miss some people.
The GitHub page also seems to be getting updated regularly as well. It was originally posted in 2014 and still works today with the latest Twitter version. :)