This article is more than two years old, the content may be outdated
Hello people, I am realising that the most effortless way for me to think on blog topics is to talk about relatively recent problems that I've had to solve. So that's what I'm gonna do today, well not today actually, because I write this articles in a course of days and not in a single day.
After this brief introductory paragraph about my thoughts I'm gonna start to relate how did I solve the problem stated in the title.
So as I said I recently had to manage a Twitter account and it had loads of people following. The previous guy that was taking care of this account was very sloppy about this subject, he actually followed back every account that followed this account and I also have reasons to believe that he intentionally followed inappropiate accounts. But this is not a rant article, although this information was necessary to build a base of the context.
As I have been put in charge of this account I started to cleaning up the profile, like username, name, biography, website url and all of that information that comes handy if a customer wants to get in touch with the company of the account. And also to make the profile prettier. Therefore I encountered the big problem: 2789 following people.
Solution: unfollow everyone except the proper people related to the account and other featured people.
How can you solve this problem in an easy way? Well, there are plenty of applications out there that claim to mass unfollow and all of that stuff, but the reality is that those application get advantage of your desesperation and throttle the number of people you can unfollow unless you subscribe or pay some amount of money to get "premium" features.
Staring at this little problem I went straight to the following page of the account and you can see that there are buttons that you have to click to unfollow an account, and I told myself: "why can't I open the developer tools and make a multiple click?" And I did so.
What did I do? Look for a button node that handles the unfollow event, and store a few of the buttons that are shown on the page (because the accounts are displayed paginated, so you have to scroll to unveil the rest). Let's go straigth to the code:
General way
// Select the buttons and store them in a variable, convert the node list to an array. var buttons = Array.from(document.querySelectorAll(".unfollow-text")); // Then fire the click event on each of those buttons buttons.forEach((button) => { button.click(); });
My way
// Select the buttons and store them in a variable, convert the node list to an array. var buttons = Array.from(document.querySelectorAll(".unfollow-text")); // Cause I wanted to keep the initial followed accounts // I sliced the array buttons = buttons.slice(0, buttons.length - 5); // Then fire the click event on each of those buttons buttons.forEach((button) => { button.click(); });
One liner
Array.from(document.querySelectorAll(".unfollow-text")) // get the buttons .slice(0, buttons.length - 5) // get a range of them .forEach((button) => { button.click(); // click every button });
Based on the executions I did there's a maximum number of people that you can unfollow in a period of time. It's around 550-600 accounts. Although I am not completely sure about it. I don't know exactly if it happens because I kept unfollowing a big amount of people in a short time (around 500 accounts four times in less than 5 minutes). However, it is not a big deal because you can keep doing this technique just waiting a few minutes. Anyways, this approach is much better than any other web application or doing it manually.
Important: Keep in mind that firing a click event 500 times consumes memory and may freeze the window a few seconds.