๐Ÿ  Community Management

๐ŸŽ‰ XActions is 100% Free & Open Source Star on GitHub โญ

๐Ÿšช Leave All Communities

Mass leave all X communities you've joined with one script. Useful for cleaning up your account or starting fresh.

Step 1: Go to your Communities page

Navigate to x.com/YOUR_USERNAME/communities or click Communities in the sidebar on X.

Step 2: Open Developer Console

Press F12 (Windows) or Cmd+Option+J (Mac) and click the Console tab.

Step 3: Paste the Leave All Communities script

leaveAllCommunities.js
// Leave All X Communities - by nichxbt
// https://github.com/nirholas/XActions
// Go to x.com/YOUR_USERNAME/communities and paste this script

(() => {
  const $communityLinks = 'a[href^="/i/communities/"]';
  const $joinedButton = 'button[aria-label^="Joined"]';
  const $confirmButton = '[data-testid="confirmationSheetConfirm"]';
  const $communitiesNav = 'a[aria-label="Communities"]';

  // Track communities we've left (persists during page navigation)
  const getLeftCommunities = () => {
    try {
      return JSON.parse(sessionStorage.getItem('xactions_left_ids') || '[]');
    } catch { return []; }
  };
  
  const markAsLeft = (id) => {
    const left = getLeftCommunities();
    if (!left.includes(id)) {
      left.push(id);
      sessionStorage.setItem('xactions_left_ids', JSON.stringify(left));
    }
  };

  const sleep = (ms) => new Promise(r => setTimeout(r, ms));

  const getCommunityId = () => {
    const leftAlready = getLeftCommunities();
    const links = document.querySelectorAll($communityLinks);
    
    for (const link of links) {
      const match = link.href.match(/\/i\/communities\/(\d+)/);
      if (match && !leftAlready.includes(match[1])) {
        return { id: match[1], element: link };
      }
    }
    return null;
  };

  const run = async () => {
    const leftCount = getLeftCommunities().length;
    console.log(`๐Ÿš€ LEAVE ALL COMMUNITIES (Left so far: ${leftCount})`);
    console.log(`๐Ÿ“‹ Already processed: ${getLeftCommunities().join(', ') || 'none'}`);
    
    await sleep(1500);
    
    // Check if we're inside a community (has "Joined" button)
    const joinedBtn = document.querySelector($joinedButton);
    
    if (joinedBtn) {
      // Get current community ID from URL
      const urlMatch = window.location.href.match(/\/i\/communities\/(\d+)/);
      const currentId = urlMatch ? urlMatch[1] : null;
      
      console.log(`๐Ÿ“ Inside community ${currentId}, clicking "Joined"...`);
      joinedBtn.click();
      await sleep(1000);
      
      const confirmBtn = document.querySelector($confirmButton);
      if (confirmBtn) {
        console.log('โœ… Confirming leave...');
        confirmBtn.click();
        
        if (currentId) {
          markAsLeft(currentId);
          console.log(`๐Ÿ“ Marked ${currentId} as left`);
        }
        
        await sleep(1500);
      }
      
      // Go back to communities list
      const communitiesLink = document.querySelector($communitiesNav);
      if (communitiesLink) {
        console.log('โฌ…๏ธ Going back to communities...');
        communitiesLink.click();
        await sleep(2500);
        return run();
      }
    }
    
    // We're on communities list - find next community to leave
    const community = getCommunityId();
    
    if (community) {
      console.log(`๐Ÿ  Entering community ${community.id}...`);
      community.element.click();
      await sleep(2500);
      return run();
    } else {
      // No more communities
      const total = getLeftCommunities().length;
      console.log(`\n๐ŸŽ‰ DONE! Left ${total} communities total`);
      console.log(`So long, and thanks for all the communities! ๐Ÿฌ`);
      console.log(`IDs: ${getLeftCommunities().join(', ')}`);
      sessionStorage.removeItem('xactions_left_ids');
    }
  };

  run();
})();

โš™๏ธ How It Works

๐Ÿ”„ Navigation Flow

The script handles page navigation intelligently:

  1. Starts from your Communities list page
  2. Finds the first community link not yet processed
  3. Clicks to enter the community
  4. Finds and clicks the "Joined" button
  5. Confirms the leave action
  6. Navigates back to the Communities list
  7. Repeats until all communities are left

๐Ÿ’พ State Persistence

Uses sessionStorage to track which communities have been left. This prevents infinite loops and allows the script to resume if interrupted. The storage is automatically cleared when the script completes.

๐ŸŽฏ Key Selectors Used

a[href^="/i/communities/"]Community links
button[aria-label^="Joined"]Joined/Leave button
[data-testid="confirmationSheetConfirm"]Confirmation button
a[aria-label="Communities"]Back to Communities nav

๐Ÿ”ง Troubleshooting

โš ๏ธ Common Issues

  • Script stops early: Scroll down on the Communities page to load more communities, then run again
  • Community not found: Make sure you're on x.com/YOUR_USERNAME/communities
  • Stuck in a community: Manually click the back button and run the script again - it will skip already-left communities
  • Rate limited: Wait a few minutes and run again - the script tracks progress

๐Ÿ’ก Pro Tips

  • If you have many communities, run the script multiple times
  • Keep the browser tab focused while the script runs
  • Don't navigate away or refresh the page during execution
  • Check the console for progress updates

Reset Progress (if needed)

If you need to start fresh, clear the session storage:

Reset tracking
sessionStorage.removeItem('xactions_left_ids');