Skip to content

Instantly share code, notes, and snippets.

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();
})();
@alyraz

This comment has been minimized.

Copy link

@alyraz alyraz commented Jan 17, 2014

HEY!!! you are AMAZING for writing this. but I need to make one edit for it to work:

29 July 2019: Script no longer works

@alyraz

This comment has been minimized.

Copy link

@alyraz alyraz commented Jan 17, 2014

THANK YOU!

@JamieMason

This comment has been minimized.

Copy link
Owner Author

@JamieMason JamieMason commented Jul 16, 2014

Updated @alyraz, thank you.

@JamieMason

This comment has been minimized.

Copy link
Owner Author

@JamieMason JamieMason commented Sep 2, 2014

Ahh, nice spot @b44rd.

@opyate

This comment has been minimized.

Copy link

@opyate opyate commented Nov 15, 2015

Haha, marvellous.

@OrganicChem

This comment has been minimized.

Copy link

@OrganicChem OrganicChem commented Jan 18, 2016

Anything to unfollow users whom I follow but don't follow me back?

@brandondossantos

This comment has been minimized.

Copy link

@brandondossantos brandondossantos commented Jun 29, 2016

Wow peejaypaul13 good stuff!

You just answered exactly what I was about to ask.

Thanks!

@sudipchatterjee23

This comment has been minimized.

Copy link

@sudipchatterjee23 sudipchatterjee23 commented Sep 29, 2016

THANK YOU!

@mandaputtra

This comment has been minimized.

Copy link

@mandaputtra mandaputtra commented Jan 17, 2017

EXTREMELY GREAT, how to know the site is use jQuery?

@luckykidtay

This comment has been minimized.

Copy link

@luckykidtay luckykidtay commented Jan 23, 2017

is there a way to remove all of my followers from my twitter page?

@japracool

This comment has been minimized.

Copy link

@japracool japracool commented Feb 6, 2017

Thank you @JamieMason

@Ousret

This comment has been minimized.

Copy link

@Ousret Ousret commented Feb 17, 2017

Thank you!! @JamieMason

@auntyarts

This comment has been minimized.

Copy link

@auntyarts auntyarts commented Apr 13, 2017

Is it possible to unfollow all who are following you back at a single click

@StatsRhian

This comment has been minimized.

Copy link

@StatsRhian StatsRhian commented Aug 2, 2017

Thank you!! @JamieMason

@Zibokwe

This comment has been minimized.

Copy link

@Zibokwe Zibokwe commented Oct 17, 2017

i find this kinda thing freezes my entire chrome and makes no progress... is that just the problem with having followed 5000 people?

@Shimza-Morgans

This comment has been minimized.

Copy link

@Shimza-Morgans Shimza-Morgans commented Apr 14, 2018

Wow this is great! stricly amazing..

@mahipalsaran1

This comment has been minimized.

Copy link

@mahipalsaran1 mahipalsaran1 commented Apr 29, 2018

how do i mute all the accounts i'm following?

@mehakaggarwal1918

This comment has been minimized.

Copy link

@mehakaggarwal1918 mehakaggarwal1918 commented Jul 4, 2018

How to loop through all one by one with a random delay in between....So that it doesn't look like a bot...

Thanks

@Mogadishko

This comment has been minimized.

Copy link

@Mogadishko Mogadishko commented Jul 11, 2018

Great! Love it!

@JamieMason

This comment has been minimized.

Copy link
Owner Author

@JamieMason JamieMason commented Jul 23, 2019

Hi all, the original Script has been updated to work with the redesigned Twitter.com.

@jeffkward

This comment has been minimized.

Copy link

@jeffkward jeffkward commented Aug 22, 2019

Adding this at the top of nextBatch will auto-scroll the page so you can set it and forget it:

window.scrollTo(0,document.body.scrollHeight);
await sleep({ seconds: 1 });

@JamieMason

This comment has been minimized.

Copy link
Owner Author

@JamieMason JamieMason commented Aug 22, 2019

Thanks @jeffkward I'll update that now 👍

@vic2pal

This comment has been minimized.

Copy link

@vic2pal vic2pal commented Aug 25, 2019

Great tool.. works very nice & smooth
Any possibility to use it in TamperMonky or an independent extension?

@AdrianMai

This comment has been minimized.

Copy link

@AdrianMai AdrianMai commented Sep 4, 2019

Gj dude thx

@AdrianMai

This comment has been minimized.

Copy link

@AdrianMai AdrianMai commented Sep 4, 2019

Can you make a code to unfollow just the ppl who didn`t follow me but i follow them ?! :D

@vic2pal

This comment has been minimized.

Copy link

@vic2pal vic2pal commented Sep 4, 2019

Hi..
It stops automatically after around 100 unfollows.. why?

@gpupo

This comment has been minimized.

Copy link

@gpupo gpupo commented Oct 9, 2019

Thanks @JamieMason !

@JamieMason

This comment has been minimized.

Copy link
Owner Author

@JamieMason JamieMason commented Oct 9, 2019

Any possibility to use it in TamperMonky or an independent extension?
@vic2pal

I've not used those extensions but I imagine so, it is just JavaScript so it should be quite compatible.

It stops automatically after around 100 unfollows.. why?
@vic2pal

I'm not sure unfortunately, I know others are using this and don't seem to have that issue.

Can you make a code to unfollow just the ppl who didn`t follow me but i follow them ?! :D
@AdrianMai

A script like that is surely possible for someone to make if they would like to

Thanks @JamieMason !
@gpupo

You're welcome

@xBioDreadx

This comment has been minimized.

Copy link

@xBioDreadx xBioDreadx commented Oct 21, 2019

Worked like a charm.
Thank you!

@FrknKoseoglu

This comment has been minimized.

Copy link

@FrknKoseoglu FrknKoseoglu commented Nov 15, 2019

it's working.

@Tobi5000

This comment has been minimized.

Copy link

@Tobi5000 Tobi5000 commented Nov 17, 2019

great thank you

@ghost

This comment has been minimized.

Copy link

@ghost ghost commented Dec 4, 2019

Works perfectly!

@JoseCage

This comment has been minimized.

Copy link

@JoseCage JoseCage commented Dec 12, 2019

Thanks

@jamesbhott

This comment has been minimized.

Copy link

@jamesbhott jamesbhott commented Jan 23, 2020

it keeps getting snagged on this:

VM233:29 Uncaught (in promise) TypeError: Cannot read property 'click' of null
at :29:23
at async Promise.all (index 14)
at async nextBatch (:24:5)

Thoughts?

@serajahmed

This comment has been minimized.

Copy link

@serajahmed serajahmed commented Jan 24, 2020

thanks buddy for this script... :)

@MateoCerquetella

This comment has been minimized.

Copy link

@MateoCerquetella MateoCerquetella commented Feb 1, 2020

Thanks for the script!

@michaeljones

This comment has been minimized.

Copy link

@michaeljones michaeljones commented Feb 9, 2020

As jamesbhott found, it seems that confirmButton is sometimes null. Not sure what might lead to that. I changed the line to if (confirmButton) confirmButton.click(); and that keeps it going a bit longer.

Excellent script. Did the job brilliantly. Much better than granting some third party service complete access to my twitter account. Thanks!

@jwsky

This comment has been minimized.

Copy link

@jwsky jwsky commented Feb 13, 2020

works really good for me

@gonzaloalfaro

This comment has been minimized.

Copy link

@gonzaloalfaro gonzaloalfaro commented Mar 17, 2020

Works fine! Thank you!

@imtbl

This comment has been minimized.

Copy link

@imtbl imtbl commented Apr 7, 2020

Works well, good job!

@JamieMason

This comment has been minimized.

Copy link
Owner Author

@JamieMason JamieMason commented Apr 9, 2020

it keeps getting snagged on this:

VM233:29 Uncaught (in promise) TypeError: Cannot read property 'click' of null
at :29:23
at async Promise.all (index 14)
at async nextBatch (:24:5)

Thoughts?
@jamesbhott

As @jamesbhott found, it seems that confirmButton is sometimes null. Not sure what might lead to that. I changed the line to if (confirmButton) confirmButton.click(); and that keeps it going a bit longer.

Excellent script. Did the job brilliantly. Much better than granting some third party service complete access to my twitter account. Thanks!
@michaeljones

Thanks @michaeljones and @jamesbhott, that should be fixed now 🤞

@wombat26

This comment has been minimized.

Copy link

@wombat26 wombat26 commented Apr 29, 2020

Boom, it worked perfectly for me, I ran the script on April 24th, 2020.
Thank you so much. :)

@techgame2247

This comment has been minimized.

Copy link

@techgame2247 techgame2247 commented Apr 30, 2020

Thanks, worked like a charm

@KRKNUK

This comment has been minimized.

Copy link

@KRKNUK KRKNUK commented Jun 6, 2020

Amazing thank you.

@jpruiz114

This comment has been minimized.

Copy link

@jpruiz114 jpruiz114 commented Aug 21, 2020

2020 and still working. Thanks a lot for sharing.

@Vista-Git

This comment has been minimized.

Copy link

@Vista-Git Vista-Git commented Aug 27, 2020

Wonderful..

@Allofsimeon

This comment has been minimized.

Copy link

@Allofsimeon Allofsimeon commented Sep 24, 2020

Still working well, thanks

@marktrobinson

This comment has been minimized.

Copy link

@marktrobinson marktrobinson commented Sep 28, 2020

Legend

@MinisterFister

This comment has been minimized.

Copy link

@MinisterFister MinisterFister commented Nov 7, 2020

Good shit

@kulalsk2

This comment has been minimized.

Copy link

@kulalsk2 kulalsk2 commented Dec 23, 2020

Can anyone please give me a github link which will post a tweet automatically

@slyoneau

This comment has been minimized.

Copy link

@slyoneau slyoneau commented Jan 5, 2021

thank you for building and sharing, this worked on the latest chrome build and big sur, date 6th Jan 2021.

@SnigdhaRoy

This comment has been minimized.

Copy link

@SnigdhaRoy SnigdhaRoy commented Jan 25, 2021

Hey everyone, as of now, the script isn't working -- I tried testing it a couple times through multiple browsers and it's not working. Can anyone see what's up w/ this? Thanks so much! :-)

(Jan 25, 2021)

@20201020049

This comment has been minimized.

Copy link

@20201020049 20201020049 commented Jan 29, 2021

te amo wapooooooooo funciono

@angryahmed

This comment has been minimized.

Copy link

@angryahmed angryahmed commented Feb 17, 2021

Nice, but why there is limit for 20-30 unfollow at once ? Need to refresh pages few times and use code again

@angryahmed

This comment has been minimized.

Copy link

@angryahmed angryahmed commented Feb 17, 2021

Hey everyone, as of now, the script isn't working -- I tried testing it a couple times through multiple browsers and it's not working. Can anyone see what's up w/ this? Thanks so much! :-)

(Jan 25, 2021)

Turn off adblock

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