Skip to content

Instantly share code, notes, and snippets.

Last active January 24, 2023 20:33
What would you like to do?
// Unfollow everyone on, by Jamie Mason
// (
// Commented version of
// 1. Go to
// 2. Open the Developer Console. (COMMAND+ALT+I on Mac)
// 3. Paste this into the Developer Console and run it
// Last Updated: 24 January 2023
(() => {
// CSS Selector to find the unfollow buttons
const $followButtons = '[data-testid$="-unfollow"]';
// CSS Selector to find the confirm button in the popup
const $confirmButton = '[data-testid="confirmationSheetConfirm"]';
const retry = {
// Keep track of how many times the script has failed
count: 0,
// Set how many times the script can fail and try again before we give up
limit: 3,
// we begin here by going to `function nextBatch`
async function nextBatch() {
// scroll down the page so that more users are loaded
// allow some time for Twitter/your Browser to load the next set of users
await sleep({ seconds: 1 });
// get all the unfollow buttons which are currently on screen
const followButtons = Array.from(document.querySelectorAll($followButtons));
// count how many unfollow buttons were found
const followButtonsWereFound = followButtons.length > 0;
// if unfollow buttons were found
if (followButtonsWereFound) {
// then we can go and click them one by one
await unfollowAll(followButtons);
// then allow some time for Twitter/your Browser to unfollow those users
await sleep({ seconds: 2 });
// now we can repeat what we just did to see if there are more users
return nextBatch();
} else {
// if NO unfollow buttons were found, keep trying for a while just incase
// if we ran out of attempts to try again, either we've finished and there
// are no more users to unfollow, or something went wrong
if (retryLimitReached()) {
} else {
// otherwise we have more attempts to try again, so we'll give
// Twitter/your Browser some time first...
await sleep({ seconds: 2 });
// ..and then repeat what we just did to see if there are more users
return nextBatch();
// scroll down the page so that more users are loaded
function scrollToTheBottom() {
return window.scrollTo(0, document.body.scrollHeight);
// don't do anything for the given number `seconds`, then carry on
function sleep({ seconds }) {
return new Promise((proceed) => {
console.log(`WAITING FOR ${seconds} SECONDS...`);
setTimeout(proceed, seconds * 1000);
// compare how many times we've retried with the maximum amount we've set
// ourselves to retry before we quit
function retryLimitReached() {
return retry.count === retry.limit;
// add one to the number we're tracking of how many times we've tried again
function addNewRetry() {
return retry.count++;
// click each one of these unfollow buttons
async function unfollowAll(followButtons) {
console.log(`UNFOLLOWING ${followButtons.length} USERS...`);
// don't continue until we've finished unfollowing each user
await Promise.all(
// repeat the steps inside the {}s once for every button (followButton) => {
// if the button exists, click it
followButton &&;
// allow some time for Twitter/your Browser
await sleep({ seconds: 1 });
// look for the "confirm" button in the popup that appears
const confirmButton = document.querySelector($confirmButton);
// if we found it, click it to unfollow the user
confirmButton &&;
// now we'll repeat with the next unfollow button in the list
// this wrapper is known as an "IIFE"
Copy link

Now it is working just fine. I wasn't on the page

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