Skip to content

Instantly share code, notes, and snippets.

@Frenchcooc
Created July 21, 2023 19:24

Revisions

  1. Frenchcooc created this gist Jul 21, 2023.
    39 changes: 39 additions & 0 deletions Twitter mass unfollow.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,39 @@
    // 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)