Skip to content

Instantly share code, notes, and snippets.

@Frenchcooc
Created July 21, 2023 19:24
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 Frenchcooc/f17fb69fe55ec6db0a989331ab9ff3bc to your computer and use it in GitHub Desktop.
Save Frenchcooc/f17fb69fe55ec6db0a989331ab9ff3bc to your computer and use it in GitHub Desktop.
// Unfollow in batch
async function unfollow() {
// Retrieve all followings
window.following = document.querySelectorAll("[role='button'] .css-901oao.css-16my406.r-poiln3.r-bcqeeo.r-qvutc0")
window.waitFor = function (ms) { return new Promise(function(resolve) { setTimeout(resolve, ms) } ) }
let counter = 0;
// Loop through followings
for (let i = 0; i < following.length; i++) {
let follow = following[i]
if (follow.innerText === 'Following') {
// Start unfollow process
follow.click()
// Wait for the unfollow confirmation modal to show
await waitFor(1500);
// Confirm unfollow
confirmUnfollow()
}
counter++
}
console.log(`Unfollowed ${counter}`)
}
// Twitter shows a confirmation modal to unfollow
// This functions will confirm unfollow
function confirmUnfollow () {
const button = document.querySelector('[data-testid="confirmationSheetDialog"] [role="button"] span.r-qvutc0')
console.log(`Button: ${button}`)
if (button && button.innerText === "Unfollow") button.click()
}
// Unfollow every seconds
window.setInterval(unfollow,1000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment