Last active
November 10, 2024 15:54
-
-
Save glsignal/d86c34ff0dab239f8e9925971f69c170 to your computer and use it in GitHub Desktop.
twitter-unfollow.js
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
| function asyncSleep(timeout) { | |
| return new Promise(function (resolve) { | |
| setTimeout(function () { | |
| resolve(); | |
| }, timeout + Math.random() * 300 /* jitter */); | |
| }); | |
| } | |
| async function removeFollows() { | |
| console.log("Looking for targets"); | |
| const targets = Array.from( | |
| $x('//div[@aria-label="Timeline: Following"]//span[text()="Following"]') | |
| ); | |
| if (targets.length > 0) { | |
| console.log(`Found ${targets.length} targets`, { targets }); | |
| } else { | |
| console.log("No targets: exiting"); | |
| return; | |
| } | |
| for (let target of targets) { | |
| target.click(); | |
| await asyncSleep(300); | |
| const unfollow = $x('//span[text()="Unfollow"]')[0]; | |
| unfollow.click(); | |
| await asyncSleep(1000); | |
| } | |
| removeFollows(); | |
| } | |
| async function removeFollowers() { | |
| console.log("Looking for targets"); | |
| // filter by "Following" text | |
| const targets = Array.from( | |
| $x( | |
| '//div[@aria-label="Timeline: Followers"]//div[@data-testid="userFollowIndicator"]//ancestor-or-self::button[@data-testid="UserCell"]//button[@aria-label="More"]' | |
| ) | |
| ); | |
| if (targets.length > 0) { | |
| console.log(`Found ${targets.length} targets`, { targets }); | |
| } else { | |
| console.log("No targets: exiting"); | |
| return; | |
| } | |
| for (let target of targets) { | |
| target.scrollIntoView(); | |
| target.click(); | |
| await asyncSleep(300); | |
| const removeFollower = $x( | |
| '//div[@role="menuitem"]//span[text()="Remove this follower"]' | |
| )[0]; | |
| removeFollower.click(); | |
| await asyncSleep(300); | |
| const confirmation = $x( | |
| '//div[@role="alertdialog"]//button//.[text()="Remove"]' | |
| )[0]; | |
| confirmation.click(); | |
| await asyncSleep(1000); | |
| } | |
| removeFollowers(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment