Skip to content

Instantly share code, notes, and snippets.

@JamieMason
Last active September 27, 2023 10:51
Star You must be signed in to star a gist
Embed
What would you like to do?
Unfollow everyone on twitter.com
// 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();
})();
@JamieMason
Copy link
Author

The last update was 09 April 2020, glad to hear it is still working alright. Maybe @isinguard and @UWReserves are both using a particular browser where it is not working right at the moment, or have a particular browser extension installed which might clash with it, I don't know.

@fayssalElAnsari
Copy link

thanks, still working 👍

@yusufpapurcu
Copy link

Legend.

@evelinas
Copy link

Thank you so much! Do you happen to have a script to remove all followers?

@AppFull
Copy link

AppFull commented Jan 31, 2022

Also looking for modified script to "remove all followers" because the menu hid under "..." menu

@JamieMason
Copy link
Author

Thank you so much! Do you happen to have a script to remove all followers?
@evelinas

You're welcome, thanks. I just have this one script to remove follows.

Also looking for modified script to "remove all followers" because the menu hid under "..." menu
@AppFull

Quite a few people have asked about this too, I hope you all find one 🤞. Thanks.

@Natsusomekeishi
Copy link

2022.3.18 可用,但是有BUG,存在部分上面的关注者无法取关

@ykavi
Copy link

ykavi commented Apr 24, 2022

great 🎉

@Sarievo
Copy link

Sarievo commented May 24, 2022

Wow

@benedlore
Copy link

Worked for about 22K of the 40K followings I was trying to remove in one go, but then started to think it was all done and needed to be restarted a few times on a refreshed page. Still better than any others I've tried.

@JamieMason
Copy link
Author

@benedlore glad it mostly worked out, 40K is a lot.

@isinguard
Copy link

@benedlore glad it mostly worked out, 40K is a lot.

It’s not that it stopped working, twitter usually puts ur acc on cooldown if you perform and action like following/unfollowing/like/unlike.. etc excessively. Just let the account rest a while, refresh the “following” page and paste the code again, then resume the unfollowing. Same thing goes with the unliking script ..

@speakingpen
Copy link

This is pretty much helpful

@roy-heinrich
Copy link

Still works damn.

@faisal-ansarii
Copy link

can you write code for removing followers on Twitter in the same way

@umitcanakci
Copy link

still working, awesome. thanks.

@JamieMason
Copy link
Author

can you write code for removing followers on Twitter in the same way
@faisal-ansarii

See comment on Jan 31 🤞

@rodcisal
Copy link

rodcisal commented Oct 1, 2022

still working thanks !

@hodunov
Copy link

hodunov commented Oct 7, 2022

nice one, thanks

@CacheMoneyPlaya
Copy link

works November 2022

@DealsBeam
Copy link

Works as of December 2022, it would be amazing if you could make one that would mass delete tweets and dislike liked tweets

@miguelgargallo
Copy link

Still working, amazing

@asdrubalivan
Copy link

It works here

@faderzz
Copy link

faderzz commented Jan 15, 2023

great

@saamhanza
Copy link

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

@JamieMason
Copy link
Author

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

@saamhanza
Copy link

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
Copy link
Author

JamieMason commented Jan 24, 2023

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

@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
Author

you're welcome, good luck learning the Web

@gthomson31
Copy link

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

@sunderee
Copy link

Legend, thank you so much!

@Articul8Madn3ss
Copy link

Articul8Madn3ss commented Jun 28, 2023

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.

@K1same17
Copy link

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

@JamieMason
Copy link
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.

@charles0830
Copy link

I am not sure how can I use this.
Plz provide kind answers.
Thanks

@isinguard
Copy link

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.

@charles0830
Copy link

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

@isinguard
Copy link

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

Script only for Twitter

@darraghoriordan
Copy link

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

@JamieMason
Copy link
Author

Nice, @darraghoriordan 👍

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