Automatically Unfollow Twitter Users who don’t Follow You Back

Have you followed users on Twitter and weren’t bothered if they followed you back or not?

That is until one day you look at your stats and find you have been following lots of users for whatever reason but very few users followed you back and you realise you now have a negative follow ratio and it can take a lot of time fix by removing non followers.


RealSocialSEO Software Tip-off

Unfollow Twitter

SocialBee is one of the widely popular social media management tools. This tool is mostly used by professionals to manage their social media accounts and Twitter accounts.


 

Please note that Twitter does not permit any automated or bulk following or unfollowing behavior!

Do read Twitters own ‘Following rules and best practices

The following method allows you to automatically & indiscriminately unfollow twitter followers who haven’t followed you back that are either inactive, can’t be bothered following you or likely to be fake.




REMEMBER THIS METHOD IS INDISCRIMINATE and will remove all non followers, plus you could get a slap on the wrist from Twitter.

It does not cost you nor do you have to sign-up to a premium service or tool.

The instructions to open JS Console is for Google Chrome users

The method is to use a little java script & the JS Console in DevTools. Don’t worry its not too difficult.

If you are unfamiliar with JS Console see here for JS Console tutorial

Steps

 

*Update 06/08/2019

The new Twitter layout is affects how the code works, so this is a new code, with the scroll incorporated into it.

Follow the steps below:

  1. Open your twitter profile in your browser and go to followers: https://twitter.com/following
  2. Then on your keyboard click ‘CTRL+SHIFT+J’ which open the JS Console in DevTools
  3. Paste the following code into the JS Console

Please do add a comment at the end of the page if it works or not for you

/*
  Unfollow (stop following) those people who are not following you back on Twitter.
  
  This will work for new Twitter web site code structure (it was changed from July 2019, causing other unfollow-scripts to stop working).
  
  Instructions:
  1) The code may need to be modified depending on the language of your Twitter web site:
    * For English language web site, no modification needed.
    * For Spanish language web site, remember to set the variable 'LANGUAGE' to "ES".
    * For another language, remember to set the variable 'LANGUAGE' to that language and modify the 'WORDS' object to add the words in that language.
  2) Optionally, you can edit the 'SKIP_USERS' array to insert those users that you do not want to unfollow (even if they are not following you back).
  3) When the code is fine, on Twitter web site, go to the section where it shows all the people you are following (https://twitter.com/YOUR_USERNAME_HERE/following).
  4) Once there, open the JavaScript console (F12 key, normally), paste all the code there and press enter.
  5) Wait until you see it has finished. If something goes wrong, reload the page and repeat from the step 3 again.
  
  * Gist by Joan Alba Maldonado: https://gist.github.com/jalbam/d7678c32b6f029c602c0bfb2a72e0c26
*/


var LANGUAGE = "EN"; //NOTE: change it to use your language!
var WORDS =
{
  //English language:
  EN:
  {
    followsYouText: "Follows you", //Text that informs that follows you.
    followingButtonText: "Following", //Text of the "Following" button.
    confirmationButtonText: "Unfollow" //Text of the confirmation button. I am not totally sure.
  },
  //Spanish language:
  ES:
  {
    followsYouText: "Te sigue", //Text that informs that follows you.
    followingButtonText: "Siguiendo", //Text of the "Following" button.
    confirmationButtonText: "Dejar de seguir" //Text of the confirmation button. I am not totally sure.
  }
  //NOTE: if needed, add your language here...
}
var SKIP_USERS = //Users that we do not want to unfollow (even if they are not following you back):
[
  //Place the user names that you want to skip here (they will not be unfollowed):
  "user_name_to_skip_example_1",
  "user_name_to_skip_example_2",
  "user_name_to_skip_example_3"
];
SKIP_USERS.forEach(function(value, index) { SKIP_USERS[index] = value.toLowerCase(); }); //Transforms all the user names to lower case as it will be case insensitive.


//Function that unfollows non-followers on Twitter:
var usersFollowingMe = function(followsYouText, followingButtonText, confirmationButtonText)
{
  var nonFollowers = 0;
  followsYouText = followsYouText || WORDS.EN.followsYouText; //Text that informs that follows you.
  followingButtonText = followingButtonText || WORDS.EN.followingButtonText; //Text of the "Following" button.
  confirmationButtonText = confirmationButtonText || WORDS.EN.confirmationButtonText; //Text of the confirmation button.
  
  //Looks through all the containers of each user:
  var userContainers = document.querySelectorAll('[data-testid=UserCell]');
  Array.prototype.filter.call
  (
    userContainers,
    function(userContainer)
    {
      //Checks whether the user is following you:
      var followsYou = false;
      Array.from(userContainer.querySelectorAll("*")).find
      (
        function(element)
        {
          if (element.textContent === followsYouText) { followsYou = true; }
        }
      );

      //If the user is not following you:
      if (!followsYou)
      {
        //Finds the user name and checks whether we want to skip this user or not:
        var skipUser = false;
        Array.from(userContainer.querySelectorAll("[href^='/']")).find
        (
          function (element)
          {
            if (element.href.indexOf("search?q=") !== -1 || element.href.indexOf("/") === -1) { return; }
            var userName = element.href.substring(element.href.lastIndexOf("/") + 1).toLowerCase();
            Array.from(element.querySelectorAll("*")).find
            (
              function (subElement)
              {
                if (subElement.textContent.toLowerCase() === "@" + userName)
                {
                  if (SKIP_USERS.indexOf(userName) !== -1)
                  {
                    console.log("We want to skip: " + userName);
                    skipUser = true;
                  }
                }
              }
            )
          }
        );
        
        //If we do not want to skip the user:
        if (!skipUser)
        {
          //Finds the unfollow button:
          Array.from(userContainer.querySelectorAll('[role=button]')).find
          (
            function(element)
            {
              //If the unfollow button is found, clicks it:
              if (element.textContent === followingButtonText)
              {
                element.click();
                nonFollowers++;
              }
            }
          );
        }
      }
    }
  );
  
  //If there is a confirmation dialog, press it automatically:
  Array.from(document.querySelectorAll('[role=button]')).find //Finds the confirmation button.
  (
    function(element)
    {
      //If the confirmation button is found, clicks it:
      if (element.textContent === confirmationButtonText)
      {
        element.click();
      }
    }
  );
  
  return nonFollowers; //Returns the number of non-followers.
}


//Scrolls and unfollows non-followers, constantly:
var scrollAndUnfollow = function()
{
  window.scrollTo(0, document.body.scrollHeight);
  usersFollowingMe(WORDS[LANGUAGE].followsYouText, WORDS[LANGUAGE].followingButtonText, WORDS[LANGUAGE].confirmationButtonText); //For English, you can try to call it without parameters.
  setTimeout(scrollAndUnfollow, 10);
};
scrollAndUnfollow();

This will take some time to run as the autoscroll function is now included in the script.

—-OLD OBSOLETE CODES BELOW—–

You will then need to scroll down to the very last profile in your followers list.

This can take some time but you can use the auto-scroll java script below to automatically do it for you

Auto-Scroll Code

To auto-scroll to the bottom of the page, copy & paste the code below into the JS Console and hit enter.

Wait till it reaches the bottom of the page before continuing.

 

setInterval(function() { window.scrollTo(0, document.body.scrollHeight); }, 2000);

 

Unfollow ALL Non Followers Code

Copy & paste the code below and hit enter to unfollow everyone who is not following you.

Update 20/01/2018 – This code works 

 

$('.ProfileCard-content').each(function(){
var status = $(this).find('.FollowStatus').text();
var unfollowButton = $(this).find('.user-actions-follow-button');
if(!status){unfollowButton.click();
}});

 

The code below, no longer works

$(‘.ProfileCard-content’).each(function(){var status = $(this).find(‘.FollowStatus’).text();var unfollowButton = $(this).find(‘.user-actions-follow-button’);if(status != ‘follows you’){unfollowButton.click();}});

 

 

It may seem the code is not doing anything .. but leave it run for some time and then refresh your twitter account to see the number of user you are following has decreased.

Need API or developer access to Twitter?

I believe in synergy skills for creating quicker, more efficient experiences in technology and workflows I am a Photo Restoration artist & SEO consultant specialising in small business and start-ups.

Leave a Comment

  1. Reply

    100% worked

    • fia
    • August 6, 2019
    Reply

    twitter won’t let change layout even if you go to directory! how do we see our followers in the old layout then? please help

    • Reply

      Hi, Twitter have now disabled all current workarounds. But I justed added a new script for the new layout.

    • felix
    • September 24, 2018
    Reply

    how can i following all following of an account?

  2. Reply

    Thank you very much! This solution is AWESOME. I was not even aware of JS Tools in Chrome… and I’m a software dev. From now on, I’m solving all my problems in the JS Tools console! Thanks again, best post I’ve seen in a LONG time.

  3. Reply

    Wow! Thanks so much for this. It’s a shame Twitter doesn’t provide a service to do this easily as it would be really useful.

    • Reply

      Thanks Paul, I have a similar code for Instagram…I should have it posted in a few days

    • Mike
    • August 20, 2018
    Reply

    Hello Neil, I have been using your code and it works amazingly well. Thank you. It seems I cannot access it anymore. I have liked your Facebook, but still locked. Suggestions?

    • Michael
    • July 5, 2018
    Reply

    I receive a “Uncaught SyntaxError: Invalid or unexpected token” each time I have tried. Is the new code no longer working?

    • Reply

      Hi Michael, still works, there might have been a little jibberish in the code due to an issue with a plugin I removed but it the code is clean now if you try copy and paste again