{"id":215,"date":"2019-07-22T10:06:45","date_gmt":"2019-07-22T10:06:45","guid":{"rendered":"http:\/\/joanalbamaldonado.com\/blog\/?p=215"},"modified":"2019-08-10T11:18:26","modified_gmt":"2019-08-10T11:18:26","slug":"unfollow-non-followers-on-twitter","status":"publish","type":"post","link":"https:\/\/joanalbamaldonado.com\/blog\/2019\/07\/22\/unfollow-non-followers-on-twitter\/","title":{"rendered":"Unfollow non-followers on Twitter (or unfollow everyone)"},"content":{"rendered":"\n<p>Here is a JavaScript code to stop following those ones who are not following you back (of unfollow everyone, if you want to) on Twitter and keeping those you want: <a rel=\"noreferrer noopener\" aria-label=\"https:\/\/gist.github.com\/jalbam\/d7678c32b6f029c602c0bfb2a72e0c26 (opens in a new tab)\" href=\"https:\/\/gist.github.com\/jalbam\/d7678c32b6f029c602c0bfb2a72e0c26\" target=\"_blank\">https:\/\/gist.github.com\/jalbam\/d7678c32b6f029c602c0bfb2a72e0c26<\/a><\/p>\n\n\n\n<p>This will work for new Twitter web site code structure (it was changed from July 2019, causing other unfollow-scripts to stop working).<\/p>\n\n\n\n<p>Instructions:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li> The code may need to be modified depending on the language of your Twitter web site:<ul><li>For English language web site, no modification needed.<\/li><li>For Spanish language web site, remember to set the \u2018<em>LANGUAGE<\/em>\u2019 variable to <em>\u201cES\u201d<\/em>.<\/li><li>For another language, remember to set the \u2018<em>LANGUAGE<\/em>\u2019 variable to  that language and modify the \u2018<em>WORDS<\/em>\u2019 object to add the words in that  language.<\/li><\/ul><\/li><li>Optionally, you can edit the \u2018<em>SKIP_USERS<\/em>\u2019 array to insert those users  that you do not want to unfollow (even if they are not following you  back).<\/li><li> If you want to follow everyone (except the users in &#8216;<em>SKIP_USERS<\/em>&#8216;), including those who are following you, just set the &#8216;<em>UNFOLLOW_FOLLOWERS<\/em>&#8216; variable to <em>true<\/em>.<\/li><li>You can set the milliseconds per cycle (each call to the &#8216;<em>performUnfollow<\/em>&#8216; function) by modifying the &#8216;<em>MS_PER_CYCLE<\/em>&#8216; variable.<\/li><li> If desired, set a number to the &#8216;<em>MAXIMUM_UNFOLLOW_ACTIONS_PER_CYCLE<\/em>&#8216;  variable to establish a maximum of unfollow actions to perform for each  cycle (each call to the &#8216;performUnfollow&#8217; function). Set to <em>null<\/em> to have no limit.<\/li><li>If desired, set a number to the &#8216;<em>MAXIMUM_UNFOLLOW_ACTIONS_TOTAL<\/em>&#8216;  variable to establish a maximum of unfollow actions to perform in total  for all cycles (all calls to the &#8216;performUnfollow&#8217; function). Set to <em>null<\/em> to have no limit. <\/li><li>When the code is fine, on Twitter web site, go to the section where  it shows all the people you are following  (<em>https:\/\/twitter.com\/YOUR_USERNAME_HERE\/following<\/em>).<\/li><li>Once there, open the JavaScript console (<em>F12 <\/em>key, normally), paste all the code there and press enter.<\/li><li> If something goes wrong or some users were not unfollowed, reload the page and repeat from the step 8 again.<\/li><\/ol>\n\n\n\n<p>NOTE: <strong>STILL NOT SURE ABOUT THE TEXT IN THE CONFIRMATION BUTTON FOR ENGLISH LANGUAGE. LET ME KNOW OR MODIFY IT BY YOURSELF TO THE CORRECT ONE IF NEEDED!<\/strong><\/p>\n\n\n\n<p>Gist by Joan Alba Maldonado: <a rel=\"noreferrer noopener\" aria-label=\"https:\/\/gist.github.com\/jalbam\/d7678c32b6f029c602c0bfb2a72e0c26 (opens in a new tab)\" href=\"https:\/\/gist.github.com\/jalbam\/d7678c32b6f029c602c0bfb2a72e0c26\" target=\"_blank\">https:\/\/gist.github.com\/jalbam\/d7678c32b6f029c602c0bfb2a72e0c26<\/a><\/p>\n\n\n\n<p>Code:<\/p>\n\n\n\n<p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"js\">\/*\n\tUnfollow (stop following) those people who are not following you back on Twitter (or unfollow everyone if desired).\n\t\n\tThis will work for new Twitter web site code structure (it was changed from July 2019, causing other unfollow-scripts to stop working).\n\t\n\tInstructions:\n\t1) The code may need to be modified depending on the language of your Twitter web site:\n\t\t* For English language web site, no modification needed.\n\t\t* For Spanish language web site, remember to set the 'LANGUAGE' variable to \"ES\".\n\t\t* For another language, remember to set the 'LANGUAGE' variable to that language and modify the 'WORDS' object to add the words in that language.\n\t2) 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).\n\t3) If you want to follow everyone (except the users in 'SKIP_USERS'), including those who are following you, just set the 'UNFOLLOW_FOLLOWERS' variable to 'true'.\n\t4) You can set the milliseconds per cycle (each call to the 'performUnfollow' function) by modifying the 'MS_PER_CYCLE' variable.\n\t5) If desired, set a number to the 'MAXIMUM_UNFOLLOW_ACTIONS_PER_CYCLE' variable to establish a maximum of unfollow actions to perform for each cycle (each call to the 'performUnfollow' function). Set to null to have no limit.\n\t6) If desired, set a number to the 'MAXIMUM_UNFOLLOW_ACTIONS_TOTAL' variable to establish a maximum of unfollow actions to perform in total for all cycles (all calls to the 'performUnfollow' function). Set to null to have no limit.\n\t7) 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).\n\t8) Once there, open the JavaScript console (F12 key, normally), paste all the code there and press enter.\n\t9) Wait until you see it has finished. If something goes wrong or some users were not unfollowed, reload the page and repeat from the step 8 again.\n\t\n\t* Gist by Joan Alba Maldonado: https:\/\/gist.github.com\/jalbam\/d7678c32b6f029c602c0bfb2a72e0c26\n*\/\n\n\nvar LANGUAGE = \"EN\"; \/\/NOTE: change it to use your language!\nvar WORDS =\n{\n\t\/\/English language:\n\tEN:\n\t{\n\t\tfollowsYouText: \"Follows you\", \/\/Text that informs that follows you.\n\t\tfollowingButtonText: \"Following\", \/\/Text of the \"Following\" button.\n\t\tconfirmationButtonText: \"Unfollow\" \/\/Text of the confirmation button. I am not totally sure.\n\t},\n\t\/\/Spanish language:\n\tES:\n\t{\n\t\tfollowsYouText: \"Te sigue\", \/\/Text that informs that follows you.\n\t\tfollowingButtonText: \"Siguiendo\", \/\/Text of the \"Following\" button.\n\t\tconfirmationButtonText: \"Dejar de seguir\" \/\/Text of the confirmation button. I am not totally sure.\n\t}\n\t\/\/NOTE: if needed, add your language here...\n}\nvar UNFOLLOW_FOLLOWERS = false; \/\/If set to true, it will also remove followers (unless they are skipped).\nvar MS_PER_CYCLE = 10; \/\/Milliseconds per cycle (each call to 'performUnfollow').\nvar MAXIMUM_UNFOLLOW_ACTIONS_PER_CYCLE = null; \/\/Maximum of unfollow actions to perform, per cycle (each call to 'performUnfollow'). Set to 'null' to have no limit.\nvar MAXIMUM_UNFOLLOW_ACTIONS_TOTAL = null; \/\/Maximum of unfollow actions to perform, in total (among all calls to 'performUnfollow'). Set to 'null' to have no limit.\nvar SKIP_USERS = \/\/Users that we do not want to unfollow (even if they are not following you back):\n[\n\t\/\/Place the user names that you want to skip here (they will not be unfollowed):\n\t\"user_name_to_skip_example_1\",\n\t\"user_name_to_skip_example_2\",\n\t\"user_name_to_skip_example_3\"\n];\nSKIP_USERS.forEach(function(value, index) { SKIP_USERS[index] = value.toLowerCase(); }); \/\/Transforms all the user names to lower case as it will be case insensitive.\n\nvar _UNFOLLOWED_TOTAL = 0; \/\/Keeps the number of total unfollow actions performed. Read-only (do not modify).\n\n\/\/Function that unfollows non-followers on Twitter:\nvar performUnfollow = function(followsYouText, followingButtonText, confirmationButtonText, unfollowFollowers, maximumUnfollowActionsPerCycle, maximumUnfollowActionsTotal)\n{\n\tvar unfollowed = 0;\n\tfollowsYouText = followsYouText || WORDS.EN.followsYouText; \/\/Text that informs that follows you.\n\tfollowingButtonText = followingButtonText || WORDS.EN.followingButtonText; \/\/Text of the \"Following\" button.\n\tconfirmationButtonText = confirmationButtonText || WORDS.EN.confirmationButtonText; \/\/Text of the confirmation button.\n\tunfollowFollowers = typeof(unfollowFollowers) === \"undefined\" || unfollowFollowers === null ? UNFOLLOW_FOLLOWERS : unfollowFollowers;\n\tmaximumUnfollowActionsTotal = maximumUnfollowActionsTotal === null || !isNaN(parseInt(maximumUnfollowActionsTotal)) ? maximumUnfollowActionsTotal : MAXIMUM_UNFOLLOW_ACTIONS_TOTAL || null;\n\tmaximumUnfollowActionsTotal = !isNaN(parseInt(maximumUnfollowActionsTotal)) ? parseInt(maximumUnfollowActionsTotal) : null;\n\tmaximumUnfollowActionsPerCycle = maximumUnfollowActionsPerCycle === null || !isNaN(parseInt(maximumUnfollowActionsPerCycle)) ? maximumUnfollowActionsPerCycle : MAXIMUM_UNFOLLOW_ACTIONS_PER_CYCLE || null;\n\tmaximumUnfollowActionsPerCycle = !isNaN(parseInt(maximumUnfollowActionsPerCycle)) ? parseInt(maximumUnfollowActionsPerCycle) : null;\n\t\n\t\/\/Looks through all the containers of each user:\n\tvar totalLimitReached = false;\n\tvar localLimitReached = false;\n\tvar userContainers = document.querySelectorAll('[data-testid=UserCell]');\n\tArray.prototype.filter.call\n\t(\n\t\tuserContainers,\n\t\tfunction(userContainer)\n\t\t{\n\t\t\t\/\/If we have reached a limit previously, exits silently:\n\t\t\tif (totalLimitReached || localLimitReached) { return; }\n\t\t\t\/\/If we have reached the maximum desired number of total unfollow actions, exits:\n\t\t\telse if (maximumUnfollowActionsTotal !== null && _UNFOLLOWED_TOTAL >= maximumUnfollowActionsTotal) { console.log(\"Exiting! Limit of unfollow actions in total reached: \" + maximumUnfollowActionsTotal); totalLimitReached = true; return;  }\n\t\t\t\/\/...otherwise, if we have reached the maximum desired number of local unfollow actions, exits:\n\t\t\telse if (maximumUnfollowActionsPerCycle !== null && unfollowed >= maximumUnfollowActionsPerCycle) { console.log(\"Exiting! Limit of unfollow actions per cycle reached: \" + maximumUnfollowActionsPerCycle); localLimitReached = true; return;  }\n\t\t\t\n\t\t\t\/\/Checks whether the user is following you:\n\t\t\tif (!unfollowFollowers)\n\t\t\t{\n\t\t\t\tvar followsYou = false;\n\t\t\t\tArray.from(userContainer.querySelectorAll(\"*\")).find\n\t\t\t\t(\n\t\t\t\t\tfunction(element)\n\t\t\t\t\t{\n\t\t\t\t\t\tif (element.textContent === followsYouText) { followsYou = true; }\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t}\n\t\t\telse { followsYou = false; } \/\/If we want to also unfollow followers, we consider it is not a follower.\n\n\t\t\t\/\/If the user is not following you (or we also want to unfollow followers):\n\t\t\tif (!followsYou)\n\t\t\t{\n\t\t\t\t\/\/Finds the user name and checks whether we want to skip this user or not:\n\t\t\t\tvar skipUser = false;\n\t\t\t\tvar userName = \"\";\n\t\t\t\tArray.from(userContainer.querySelectorAll(\"[href^='\/']\")).find\n\t\t\t\t(\n\t\t\t\t\tfunction (element)\n\t\t\t\t\t{\n\t\t\t\t\t\tif (element.href.indexOf(\"search?q=\") !== -1 || element.href.indexOf(\"\/\") === -1) { return; }\n\t\t\t\t\t\tuserName = element.href.substring(element.href.lastIndexOf(\"\/\") + 1).toLowerCase();\n\t\t\t\t\t\tArray.from(element.querySelectorAll(\"*\")).find\n\t\t\t\t\t\t(\n\t\t\t\t\t\t\tfunction (subElement)\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tif (subElement.textContent.toLowerCase() === \"@\" + userName)\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tif (SKIP_USERS.indexOf(userName) !== -1)\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tconsole.log(\"We want to skip: \" + userName);\n\t\t\t\t\t\t\t\t\t\tskipUser = true;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t);\n\t\t\t\t\t\tif (skipUser) { return; }\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t\t\n\t\t\t\t\/\/If we do not want to skip the user:\n\t\t\t\tif (!skipUser)\n\t\t\t\t{\n\t\t\t\t\t\/\/Finds the unfollow button:\n\t\t\t\t\tArray.from(userContainer.querySelectorAll('[role=button]')).find\n\t\t\t\t\t(\n\t\t\t\t\t\tfunction(element)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\/\/If the unfollow button is found, clicks it:\n\t\t\t\t\t\t\tif (element.textContent === followingButtonText)\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tconsole.log(\"* Unfollowing: \" + userName);\n\t\t\t\t\t\t\t\telement.click();\n\t\t\t\t\t\t\t\tunfollowed++;\n\t\t\t\t\t\t\t\t_UNFOLLOWED_TOTAL++;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t);\n\t\n\t\/\/If there is a confirmation dialog, press it automatically:\n\tArray.from(document.querySelectorAll('[role=button]')).find \/\/Finds the confirmation button.\n\t(\n\t\tfunction(element)\n\t\t{\n\t\t\t\/\/If the confirmation button is found, clicks it:\n\t\t\tif (element.textContent === confirmationButtonText)\n\t\t\t{\n\t\t\t\telement.click();\n\t\t\t}\n\t\t}\n\t);\n\t\n\treturn totalLimitReached ? null : unfollowed; \/\/If the total limit has been reached, returns null. Otherwise, returns the number of unfollowed people.\n}\n\n\n\/\/Scrolls and unfollows non-followers, constantly:\nvar scrollAndUnfollow = function()\n{\n\twindow.scrollTo(0, document.body.scrollHeight);\n\tvar unfollowed = performUnfollow(WORDS[LANGUAGE].followsYouText, WORDS[LANGUAGE].followingButtonText, WORDS[LANGUAGE].confirmationButtonText, UNFOLLOW_FOLLOWERS, MAXIMUM_UNFOLLOW_ACTIONS_PER_CYCLE, MAXIMUM_UNFOLLOW_ACTIONS_TOTAL); \/\/For English, you can try to call it without parameters.\n\tif (unfollowed !== null) { setTimeout(scrollAndUnfollow, MS_PER_CYCLE); }\n\telse { console.log(\"Total desire of unfollow actions performed!\"); }\n};\nscrollAndUnfollow();<\/pre><\/p>\n\n\n\n<p>Thank you very much. Any comments are welcome.<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here is a JavaScript code to stop following those ones who are not following you back (of unfollow everyone, if you want to) on Twitter and keeping those you want: https:\/\/gist.github.com\/jalbam\/d7678c32b6f029c602c0bfb2a72e0c26 This will work for new Twitter web site code structure (it was changed from July 2019, causing other unfollow-scripts to stop working). Instructions: The &hellip; <a href=\"https:\/\/joanalbamaldonado.com\/blog\/2019\/07\/22\/unfollow-non-followers-on-twitter\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Unfollow non-followers on Twitter (or unfollow everyone)&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[50,145,9,74,1,75],"tags":[134,137,144,129,128,130,136,59,138,140,142,132,139,141,135,143,127,131,133],"class_list":["post-215","post","type-post","status-publish","format-standard","hentry","category-javascript","category-others","category-programming","category-tool","category-uncategorized","category-utility","tag-code","tag-console","tag-english","tag-follow","tag-followers","tag-following","tag-gist","tag-javascript","tag-js","tag-keep","tag-languages","tag-non-followers","tag-skip","tag-skipping","tag-snipet","tag-spanish","tag-twitter","tag-unfollow","tag-unfollowing"],"_links":{"self":[{"href":"https:\/\/joanalbamaldonado.com\/blog\/wp-json\/wp\/v2\/posts\/215","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/joanalbamaldonado.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/joanalbamaldonado.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/joanalbamaldonado.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/joanalbamaldonado.com\/blog\/wp-json\/wp\/v2\/comments?post=215"}],"version-history":[{"count":22,"href":"https:\/\/joanalbamaldonado.com\/blog\/wp-json\/wp\/v2\/posts\/215\/revisions"}],"predecessor-version":[{"id":249,"href":"https:\/\/joanalbamaldonado.com\/blog\/wp-json\/wp\/v2\/posts\/215\/revisions\/249"}],"wp:attachment":[{"href":"https:\/\/joanalbamaldonado.com\/blog\/wp-json\/wp\/v2\/media?parent=215"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/joanalbamaldonado.com\/blog\/wp-json\/wp\/v2\/categories?post=215"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/joanalbamaldonado.com\/blog\/wp-json\/wp\/v2\/tags?post=215"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}