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();
})();
@benedlore
Copy link

benedlore commented May 29, 2022

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

JamieMason commented May 29, 2022

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

@isinguard
Copy link

isinguard commented May 29, 2022

@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

speakingpen commented Jun 6, 2022

This is pretty much helpful

@roy-heinrich
Copy link

roy-heinrich commented Jun 16, 2022

Still works damn.

@faisal-ansarii
Copy link

faisal-ansarii commented Aug 28, 2022

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

@rkytie
Copy link

rkytie commented Aug 29, 2022

still working, awesome. thanks.

@JamieMason
Copy link
Author

JamieMason commented Aug 30, 2022

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

See comment on Jan 31 🤞

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