-
-
Save svpn/657b0c59989843d2157cfe76b5771b3c to your computer and use it in GitHub Desktop.
Code to stop following those ones who are not following you back on Twitter and keeping those you want or follow anyone you want, with certain filters (working in July 2019)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| Unfollow (stop following) those people who is 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) On Twitter web site, go to the section where it shows all the people you are following. | |
| 2) Once there, open the JavaScript console (F12 key), paste all the code there and press enter. | |
| IMPORTANT: before pressing enter, remember to change the three parameters to adapt it to your language. | |
| 3) Wait until you see it has finished. | |
| * Gist by Joan Alba Maldonado: https://gist.github.com/jalbam/d7678c32b6f029c602c0bfb2a72e0c26 | |
| */ | |
| /* | |
| Note: | |
| * For English language web site, remember to change "Te sigue" for "Follows you", "Siguiendo" for "Following" and "Dejar de seguir" for "Unfollow" (I am not totally sure about this one). | |
| * For another languages, change those three parameters to your language. | |
| */ | |
| var followsYouText = "Te sigue"; //English: "Follows you". | |
| var followingButtonText = "Siguiendo"; //English: "Following". | |
| var confirmationButtonText = "Dejar de seguir"; //English: "Unfollow" (I am not totally sure). | |
| //Function that unfollows non-followers on Twitter: | |
| var usersFollowingMe = function(followsYouText, followingButtonText, confirmationButtonText) | |
| { | |
| var nonFollowers = 0; | |
| followsYouText = followsYouText || "Follows you"; //Text that informs that follows you. Spanish: "Te sigue". | |
| followingButtonText = followingButtonText || "Following"; //Text of the "Following" button. Spanish: "Following". | |
| confirmationButtonText = confirmationButtonText || "Unfollow" //Text of the confirmation button. Spanish: "Dejar de seguir". TODO: confirm real text in English! | |
| //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 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: | |
| if (nonFollowers > 0) | |
| { | |
| //Finds the confirmation button: | |
| Array.from(document.querySelectorAll('[role=button]')).find | |
| ( | |
| 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(followsYouText, followingButtonText, confirmationButtonText); //For english, you can try to call it without parameters. | |
| setTimeout(scrollAndUnfollow, 10); | |
| }; | |
| scrollAndUnfollow(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment