Skip to content

Instantly share code, notes, and snippets.

@JamieMason
Last active June 29, 2026 05:20
Show Gist options
  • Select an option

  • Save JamieMason/7580315 to your computer and use it in GitHub Desktop.

Select an option

Save JamieMason/7580315 to your computer and use it in GitHub Desktop.
Unfollow everyone on twitter.com

Unfollow everyone on twitter.com

By @foldleft.bsky.social, see also Unfollow everyone on bsky.app.

  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
// 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: 30 October 2023
(() => {
  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();
})();

This script:

  • Is completely free and has been since 2013.
  • Doesn't try and get you to sign in or take your personal data.
  • Automates your web browser to make it click unfollow buttons, scroll down to reveal more, then do it again.
  • No tricks, all of the code is here so you can see exactly what it does.

If this script was useful and saved you time, maybe kick in for a Coffee to say thanks:

ko-fi

@saamhanza

Copy link
Copy Markdown

can anyone point me in the right direction of understanding how a script like this is put together?

@JamieMason

Copy link
Copy Markdown
Author

in what respect @saamhanza? like what each line does?

@saamhanza

Copy link
Copy Markdown

in what respect @saamhanza? like what each line does?

Thank you for getting back to me

Yes, or a video you could point me to that gives some sort of a walkthrough showing how I could replicate this for another site for example.

@JamieMason

JamieMason commented Jan 24, 2023

Copy link
Copy Markdown
Author

Yes, or a video you could point me to that gives some sort of a walkthrough showing how I could replicate this for another site for example.

@saamhanza here is a commented version of this script to help understand how it works. As far as replicating this process for other sites, a quick Google Search has come up with this Browser Automation With Javascript article which looks a good fit.

@saamhanza

Copy link
Copy Markdown

@saamhanza here is a commented version of this script to help understand how it works. As far as replicating this process for other sites, a quick Google Search has come up with this Browser Automation With Javascript article which looks a good fit.

Huge thank you for this Jamie!

@JamieMason

Copy link
Copy Markdown
Author

you're welcome, good luck learning the Web

@gthomson31

Copy link
Copy Markdown

this is beautiful! did exactly as it says on the tin 👍

@sunderee

Copy link
Copy Markdown

Legend, thank you so much!

@Articul8Madn3ss

Articul8Madn3ss commented Jun 28, 2023

Copy link
Copy Markdown

Hey JaimeMason. Do you have a script that can unfollow everybody but Twitter Blue users? I want to keep all my Blue users but unfollow the rest. With API gone its a pain. Thanks.

@darth-v1ader

Copy link
Copy Markdown

Hello. Is it possible to make such a script for bluesky?

@JamieMason

Copy link
Copy Markdown
Author

Hello. Is it possible to make such a script for bluesky?

I've never used bluesky but I would expect someone could do this, these kinds of scripts can be written for most kinds of web pages.

@isinguard

Copy link
Copy Markdown

Ctrl+Alt+J in chrome to open the Developer Tools console, then paste the code (ctrl+V) on the “following” page of your twitter account, and hit enter.

@isinguard

Copy link
Copy Markdown

@isinguard thanks but I don't mean twitter.
I meant github followings.
Thanks

Script only for Twitter

@darraghoriordan

Copy link
Copy Markdown

slight change so it only unfollows people who don't follow you back: https://gist.github.com/darraghoriordan/1f8ddff7b12a68c259a1f71bf4000c51

@JamieMason

Copy link
Copy Markdown
Author

Nice, @darraghoriordan 👍

@yemidavis

Copy link
Copy Markdown

Is there a way to get this not to unfollow private accounts?

@crimsoniv0j

Copy link
Copy Markdown

Thank you very much! I successfully unfollowed 1969 in my twitter/x account! I made a github acc just to thank you!

@JamieMason

Copy link
Copy Markdown
Author

You're welcome @crimsoniv0j, glad it worked out.

@niklas44f1

Copy link
Copy Markdown

Still works! Thank you so much. Is there a code to follow massively on Twitter?

@JamieMason

Copy link
Copy Markdown
Author

Great @niklas44f1. You could probably modify the script slightly so it works on someone's Following page for example, and clicks follow instead of unfollow or something. I'm not going to do it but it should be a fairly small job for someone.

@julienreszka

Copy link
Copy Markdown

still work thx

@GeekProgram007

GeekProgram007 commented Nov 8, 2023

Copy link
Copy Markdown

How to unfollow only unlocked (e.g. not private) accounts? The data id is data-testid="icon-lock"

@fortunefox

Copy link
Copy Markdown

Works. Thanks!

@bobby091983

Copy link
Copy Markdown

thank you very much , its working fine.

@imsaifulislam

Copy link
Copy Markdown

Thanks :) Its working FIne

@Mucenio

Mucenio commented Jan 25, 2024

Copy link
Copy Markdown

work

@Zeroexperiencelearner

Copy link
Copy Markdown

Still working, amazing!
Thank you!

@pkfrank

pkfrank commented Feb 19, 2024

Copy link
Copy Markdown

Thanks!

@Varunt016

Copy link
Copy Markdown

works thanks

@MetinSAYGIN

Copy link
Copy Markdown

Still works thanks

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