// 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(); | |
})(); |
Still works damn.
can you write code for removing followers on Twitter in the same way
still working, awesome. thanks.
can you write code for removing followers on Twitter in the same way
@faisal-ansarii
See comment on Jan 31
still working thanks !
nice one, thanks
works November 2022
Works as of December 2022, it would be amazing if you could make one that would mass delete tweets and dislike liked tweets
Still working, amazing
It works here
great
can anyone point me in the right direction of understanding how a script like this is put together?
in what respect @saamhanza? like what each line does?
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.
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 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!
you're welcome, good luck learning the Web
this is beautiful! did exactly as it says on the tin
Legend, thank you so much!
Here is a little mod to keep it ticking over - I had to keep refreshing the page so I wrote this also I commented out a log as I want to only see accounts unfollowed:
Expand to see the code 👀
(() => {
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();
}
};
const runEveryOneSecond = () => {
setTimeout(() => {
nextBatch();
runEveryThreeSeconds();
}, 1000);
};
runEveryOneSecond();
})();
Thanks a lot @benjaminthedev, can you tell me a bit more about what you were seeing and what this does to fix it? I see some setTimeouts in there. Thanks for contributing.
This is pretty much helpful