Skip to content

Instantly share code, notes, and snippets.

@gugadev
Created December 9, 2022 00:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gugadev/3c382543ecb5b287ee7a992245f4691b to your computer and use it in GitHub Desktop.
Save gugadev/3c382543ecb5b287ee7a992245f4691b to your computer and use it in GitHub Desktop.
Tiny script to unfollow all people you're following. Just go to https://twitter.com/<youruser>/following, open the console and run the code (testing in responsive mode).
function unfollow() {
let count = 0
const buttons = document.querySelectorAll('[data-testid*="-unfollow"]')
if (!buttons.length) {
console.log(`${count} People unfollowed`)
return
}
const waitFor = (ms) => new Promise(resolve => setTimeout(resolve, ms))
const acceptModals = async (index = 0) => {
if (index === buttons.length - 1) {
return
}
const confirmBtn = document.querySelector('[data-testid*="confirmationSheetConfirm"]')
confirmBtn.click()
count += 1
await waitFor(150) // you can play with this timing if you don't have the desired results.
return acceptModals(index + 1)
}
for (const button of buttons) {
button.click()
}
acceptModals().then(unfollow, console.err)
}
unfollow()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment