-
-
Save Thyrst/673850cf5bc243b4011dc58e118c950e to your computer and use it in GitHub Desktop.
Unfollow everyone who doesn't follow back on twitter.com
This file contains 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 everyone on twitter.com, by Jamie Mason (https://twitter.com/fold_left) | |
// https://gist.github.com/JamieMason/7580315 | |
// | |
// 1. Go to https://twitter.com/YOUR_USER_NAME/following | |
// 2. Open the Developer Console. (COMMAND+ALT+I on Mac) | |
// 3. Paste this into the Developer Console and run it | |
// | |
// Last Updated: 21 March 2023 | |
(() => { | |
const followButtonQuery = '[data-testid$="-unfollow"]'; | |
const confirmButtonQuery = '[data-testid="confirmationSheetConfirm"]'; | |
const usersQuery = '[data-testid="UserCell"]'; | |
const retry = { | |
count: 0, | |
limit: 3, | |
}; | |
const scrollToTheBottom = () => window.scrollTo(0, document.body.scrollHeight); | |
const retryLimitReached = () => retry.count === retry.limit; | |
const addNewRetry = () => retry.count++; | |
const sleep = ({ seconds }) => | |
new Promise((proceed) => { | |
console.log(`WAITING FOR ${seconds} SECONDS...`); | |
setTimeout(proceed, seconds * 1000); | |
}); | |
const unfollowAll = async (followButtons) => { | |
console.log(`UNFOLLOWING ${followButtons.length} USERS...`); | |
await Promise.all( | |
followButtons.map(async (followButton) => { | |
followButton && followButton.click(); | |
await sleep({ seconds: 1 }); | |
const confirmButton = document.querySelector(confirmButtonQuery); | |
confirmButton && confirmButton.click(); | |
}) | |
); | |
}; | |
const nextBatch = async () => { | |
scrollToTheBottom(); | |
await sleep({ seconds: 1 }); | |
const users = Array.from(document.querySelectorAll(usersQuery)); | |
const usersWereFound = users.length > 0; | |
if (usersWereFound) { | |
const usersToUnfollow = users.filter((user) => user.children[0].children[1].children[0].children[0].children[0].children[1].childElementCount == 1); | |
if (usersToUnfollow.length > 0) { | |
const followButtons = usersToUnfollow.map((user) => user.querySelector(followButtonQuery)); | |
await unfollowAll(followButtons); | |
await sleep({ seconds: 2 }); | |
} | |
return nextBatch(); | |
} else { | |
addNewRetry(); | |
} | |
if (retryLimitReached()) { | |
console.log(`NO ACCOUNTS FOUND, SO I THINK WE'RE DONE`); | |
console.log(`RELOAD PAGE AND RE-RUN SCRIPT IF ANY WERE MISSED`); | |
} else { | |
await sleep({ seconds: 2 }); | |
return nextBatch(); | |
} | |
}; | |
nextBatch(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment