Maintaining Reciprocal Following To Followers Ratio On X

This revision is from 2024/03/04 19:51. You can Restore it.

Unfollow everyone on X (Formerly Twitter) who doesn't follow you back, by Nicholas Resendez (https://twitter.com/nichxbt)

Go to profile https://twitter.com/Immortality_IMT

Following: https://twitter.com/Immortality_IMT/following

Open the Developer Console. Mozilla Firefox: Ctrl + Shift + K or Ctrl + Shift + I

Paste code into the Developer Console and run it

(() => {
  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 });

    let followButtons = Array.from(document.querySelectorAll($followButtons));
    followButtons = followButtons.filter(b => b.parentElement?.parentElement?.querySelector('[data-testid="userFollowIndicator"]') === null)
    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();
})();

Here is another verison

const userField = document.getElementsByClassName("ProfileCard-userFields");
const input = window.prompt("Enter any usernames you want to continue following separated by a space.");
let inputMax = window.prompt("Enter maximum number of seconds to wait between actions. Must be greater than '2'.");
let i = 0;
let t = 0;
let inputFound = [];
let saveNames = input.split(" ");
let rand = Math.round(Math.random() * 10000);
let setMin = 2000;
let setMax = inputMax * 1000;
main();

function main(){
    if(inputMax > 2){
        randomIntFromInterval(setMin,setMax);
        unfollowLoop();
        findUsers();
    }else{
    	inputMax = window.prompt("Please enter a number great than 2");
    	setMax = inputMax * 1000;
        main();
    }
}


function findUsers(){
	if(t < userField.length){
		for(u = 0; u < saveNames.length; u++){
			if(userField[t].children[1].innerText.includes(saveNames[u])){
				inputFound[t] = true;
				break;
			}else{
				inputFound[t] = false;
			}
		}
		t++;
		if(t < userField.length){
			findUsers();
		}
	}
}

function randomIntFromInterval(min,max)
{
	rand = Math.floor(Math.random()*(max-min+1)+min);
	return rand;
}


function unfollowLoop(){
	let button = userField[i].previousElementSibling.children[0].children[0].children[0].children[1];
	let buttonText = button.innerText;
	let stat = userField[i].children[1].children[2];
	let follows = "";

	if(stat === undefined){
		follows = "";
	}else{

		follows = stat.innerText;
	}

	setTimeout(function(){
		if(follows.includes("Follows you") === false && inputFound[i] === false && buttonText.includes("Following") === true){
			button.click();
        }
		i++;
		if(i < userField.length){
				randomIntFromInterval(setMin,setMax);
				unfollowLoop();
		}else{
			window.alert("Unfollow Script Finished!");
		}
	}, rand);
}

  

📝 📜 ⏱️ ⬆️