Skip to content

Instantly share code, notes, and snippets.

@aelphias
Last active July 1, 2025 11:22
Show Gist options
  • Save aelphias/ed954aaae88ee631acbfbfa505aa6aae to your computer and use it in GitHub Desktop.
Save aelphias/ed954aaae88ee631acbfbfa505aa6aae to your computer and use it in GitHub Desktop.
This **JavaScript snippet** runs in your browser and safely unfollows users one by one from your **Following** list, imitating natural scrolling and clicking behavior to avoid detection.

πŸ” X.com (Twitter) "Unfollow All" Script for Google Chrome

X (formerly Twitter) removed the "Unfollow All" button β€” this script brings it back.

This JavaScript snippet runs in your browser and safely unfollows users one by one from your Following list, imitating natural scrolling and clicking behavior to avoid detection.


βš™οΈ Requirements

  • βœ… Google Chrome browser (desktop)
  • βœ… Logged into your x.com account
  • βœ… A little patience

πŸš€ How to Use

  1. Open your Following page:
    Go to: https://x.com/YOUR_USERNAME/following

  2. Open the Developer Console:

    • Windows/Linux: Ctrl + Shift + J
    • macOS: Cmd + Option + J
  3. Paste the entire script into the console and press Enter.

// Paste this in Chrome DevTools on your Following page

window.STOP_UNFOLLOW = false;
let unfollowedCount = 0;
const MAX_UNFOLLOWS = 400;

async function sleep(ms) {
  return new Promise(resolve => setTimeout(resolve, ms));
}

async function unfollowAll() {
  const scrollContainer = document.querySelector('[data-testid="primaryColumn"]');
  let lastHeight = 0;

  while (!window.STOP_UNFOLLOW && unfollowedCount < MAX_UNFOLLOWS) {
    const buttons = [...document.querySelectorAll('div[role="button"]')]
      .filter(btn => btn.innerText === "Following" || btn.getAttribute('aria-label')?.includes("Following"));

    for (const btn of buttons) {
      if (window.STOP_UNFOLLOW || unfollowedCount >= MAX_UNFOLLOWS) break;
      btn.click();
      await sleep(500 + Math.random() * 1000);

      const confirmBtn = document.querySelector('div[role="button"][data-testid="confirmationSheetConfirm"]');
      if (confirmBtn) {
        confirmBtn.click();
        unfollowedCount++;
        console.log(`βœ… Unfollowed ${unfollowedCount}`);
        await sleep(1000 + Math.random() * 2000);
      } else {
        console.warn("⚠️ Confirm button not found. Skipping.");
      }
    }

    scrollContainer.scrollBy(0, 2000);
    await sleep(2000 + Math.random() * 2000);

    if (scrollContainer.scrollHeight === lastHeight) break;
    lastHeight = scrollContainer.scrollHeight;
  }

  console.log("πŸ›‘ Done. Total unfollowed:", unfollowedCount);
}

unfollowAll(); 
  1. The script will:
    • Scroll the page to load more followed users
    • Click each "Following" button
    • Confirm the Unfollow action
    • Repeat until limit is reached or manually stopped

⏸️ To Pause or Stop

Paste this into the console anytime:

window.STOP_UNFOLLOW = true;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment