Skip to content

Instantly share code, notes, and snippets.

@renestalder
Last active May 11, 2026 09:28
Show Gist options
  • Select an option

  • Save renestalder/c5b77635bfbec8f94d28 to your computer and use it in GitHub Desktop.

Select an option

Save renestalder/c5b77635bfbec8f94d28 to your computer and use it in GitHub Desktop.
Unfollow all on Facebook

Facebook: Unfollow people and pages

See comments section for more up-to-date versions of the script. The original script is from 2014 and will not work as is.

  1. Open news feed preferences on your Facebook menu (browser)
  2. Click people or pages
  3. Scroll down (or click see more) until your full list is loaded
  4. Run the script in your browser console

Facebook will block this feature for you while you use it, depending on how much entities you try to unfollow. It automatically unblocks in a couple of hours and you will be able to continue.

var unfollowButtons = document.querySelectorAll('[data-followed="1"]'); for(var i=0;i<unfollowButtons.length;i++){ unfollowButtons[i].click(); } alert(unfollowButtons.length+' people are now unfollowed! ');
@daokethinh-tech
Copy link
Copy Markdown

ảnh Tôi gặp lỗi này làm thế nào để giải quyết nó?

  1. Internet của bạn có tốt không? Thử tăng HOVER_WAIT_TIMEOUT
  2. Bộ chọn của bạn đã được thiết lập chưa? Đọc một ở trên. nên giống như div.XXXXX.XXXXX.XXXX.XXXXX > div

My internet is 100mb/s very good, has set the filter on Tampermonkey. Can you support me with Teamview or Ultraview? Thank you very much!
image

@matsyui
Copy link
Copy Markdown

matsyui commented Nov 6, 2025

ảnh Tôi gặp lỗi này làm thế nào để giải quyết nó?

  1. Internet của bạn có tốt không? Thử tăng HOVER_WAIT_TIMEOUT
  2. Bộ chọn của bạn đã được thiết lập chưa? Đọc một ở trên. nên giống như div.XXXXX.XXXXX.XXXX.XXXXX > div

My internet is 100mb/s very good, has set the filter on Tampermonkey. Can you support me with Teamview or Ultraview? Thank you very much! image

Do the step 2, after that paste the script in the console.

I dont do remote view

@jcarroll
Copy link
Copy Markdown

jcarroll commented Jan 12, 2026

image I am getting this error how to solve it?

@daokethinh-tech, Are you still looking for a solution? Looks like you're trying to use maysyui's excellent auto-unfriend script; is that correct?

@matsyui
Copy link
Copy Markdown

matsyui commented Jan 12, 2026

image I am getting this error how to solve it?

@daokethinh-tech, Are you still looking for a solution? Looks like you're trying to use maysyui's excellent auto-unfriend script; is that correct?

If this script and my script doesn't work...

Try this UI version (browser extension)

https://chromewebstore.google.com/detail/loc/eojdckfcadamkapabechhbnkleligand
https://loc.dev/

@cystec
Copy link
Copy Markdown

cystec commented Apr 3, 2026

**In 2026:

This will work on** https://www.facebook.com/pages/?category=liked&ref=bookmarks

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

  let stop = false;
  window.stopFbUnfollow = () => {
    stop = true;
    console.log("Stopping after current action...");
  };

  async function autoScroll() {
    let lastHeight = 0;
    let stableRounds = 0;

    while (!stop && stableRounds < 5) {
      window.scrollTo(0, document.body.scrollHeight);
      await sleep(1500);

      const newHeight = document.body.scrollHeight;
      if (newHeight === lastHeight) {
        stableRounds++;
      } else {
        stableRounds = 0;
        lastHeight = newHeight;
      }
    }
  }

  async function clickAll(selector, label) {
    while (!stop) {
      const buttons = [...document.querySelectorAll(selector)]
        .filter(el => el.offsetParent !== null);

      if (!buttons.length) {
        console.log(`No more ${label} buttons found.`);
        break;
      }

      console.log(`Found ${buttons.length} ${label} button(s).`);

      for (const btn of buttons) {
        if (stop) break;

        try {
          btn.click();
          console.log(`Clicked ${label}`);
        } catch (e) {
          console.log(`Failed clicking ${label}`, e);
        }

        await sleep(900);
      }

      await sleep(1200);
    }
  }

  console.log("Step 1: loading more pages...");
  await autoScroll();

  console.log("Step 2: unfollowing pages...");
  await clickAll('[aria-label="Following"]', 'Following');

  console.log("Step 3: unliking pages...");
  await clickAll('[aria-label="Liked"]', 'Liked');

  console.log("Done. Run stopFbUnfollow() to stop early next time.");
})();

@BayLak-Egypt
Copy link
Copy Markdown

  • FACEBOOK Unfollow Script - Specialized Version
  • Developed by: BayLak
  • Description: Automated script to handle Facebook unfollowing process via DOM manipulation.
    Usage: Run this in the browser console on the 'Following' page.
    IN 2026/5/9
    https://www.facebook.com/YourUserName/following and run the script.

console.log("%c [!] Script Started... Developed by BayLak.", "color: #00FF00; font-weight: bold;");

let intervalId = setInterval(function () {
    // Select all "More options" buttons dynamically
    let moreButtons = document.querySelectorAll('div[role="button"][aria-label*="More options"]');
    
    if (moreButtons.length > 0) {
        let currentBtn = moreButtons[0];
        currentBtn.click();
        setTimeout(() => {
            // 2. Identify the Unfollow option by role and text content
            let menuItems = document.querySelectorAll('div[role="menuitem"]');
            let unfollowBtn = Array.from(menuItems).find(item => 
                item.innerText.includes('Unfollow') || item.innerText.includes('إلغاء المتابعة')
            );

            if (unfollowBtn) {
                unfollowBtn.click();
                console.log("%c [+] Target Unfollowed.", "color: #00FF00");
            }

            let container = currentBtn.closest('div.x1gefphp');
            if (container) {
                container.remove();
            }
            window.scrollBy(0, 150);
        }, 700);

    } else {
        // Scroll down to fetch and render more items
        window.scrollBy(0, 500);
        console.log("Scanning for more targets...");
    }
}, 1800); 

@BayLak-Egypt
Copy link
Copy Markdown

  • Facebook Advanced Unfollow Bot - Stealth Version
  • Developed by: BayLak
  • Features: Auto-counting, Stealth scrolling, and Batch processing.

2026/5/9
https://www.facebook.com/YourUserName/following and run the script.


(function() {
    let unfollowCount = 0;
    const targetLimit = 100; // Set your limit here to avoid bans
    
    console.log("%c [!] BayLak Stealth Engine Activated.", "color: #FFA500; font-weight: bold;");

    async function startProcess() {
        // 1. Get all available follow buttons on the screen
        let moreButtons = document.querySelectorAll('div[role="button"][aria-label*="More options"]');
        console.log(`%c [i] Found ${moreButtons.length} accounts in current view.`, "color: #00FFFF");

        for (let btn of moreButtons) {
            if (unfollowCount >= targetLimit) {
                console.log("%c [!] Target limit reached. Stopping to stay safe.", "color: #FF0000");
                return;
            }

            // Click the more options
            btn.click();
            
            // Wait for DOM to update
            await new Promise(r => setTimeout(r, 600));

            let menuItems = document.querySelectorAll('div[role="menuitem"]');
            let unfollowBtn = Array.from(menuItems).find(item => 
                item.innerText.includes('Unfollow') || item.innerText.includes('إلغاء المتابعة')
            );

            if (unfollowBtn) {
                unfollowBtn.click();
                unfollowCount++;
                console.log(`%c [+] Unfollowed count: ${unfollowCount}`, "color: #00FF00");
            }

            // Clean up the DOM to free memory and avoid re-scanning
            btn.closest('div.x1gefphp')?.remove();

            // Dynamic delay to mimic human behavior (Randomized between 1-2 seconds)
            await new Promise(r => setTimeout(r, Math.random() * 1000 + 1000));
        }

        // 2. Scroll and repeat
        window.scrollBy({ top: 800, behavior: 'smooth' });
        console.log("%c [~] Scrolling for more...", "color: #BBBBBB");
        
        setTimeout(startProcess, 2000);
    }

    startProcess();
})();

@BayLak-Egypt
Copy link
Copy Markdown

  • FACEBOOK ATTACKER Unfollow + Live Analytics
  • Developed by: BayLak
  • Priority: Maximum Speed | Mode: Aggressive with Logging
    2026/5/9

https://www.facebook.com/YourUserName/following and run the script.


(function() {
    let totalUnfollowed = 0;
    let startTime = Date.now();

    console.clear();
    console.log(
        "%c" + 
        "██████╗  █████╗ ██╗   ██╗██╗      █████╗ ██╗  ██╗\n" +
        "██╔══██╗██╔══██╗╚██╗ ██╔╝██║     ██╔══██╗██║ ██╔╝\n" +
        "██████╔╝███████║ ╚████╔╝ ██║     ███████║█████╔╝ \n" +
        "██╔══██╗██╔══██║  ╚██╔╝  ██║     ██╔══██║██╔═██╗ \n" +
        "██████╔╝██║  ██║   ██║   ███████╗██║  ██║██║  ██╗\n" +
        "╚═════╝ ╚═╝  ╚═╝   ╚═╝   ╚══════╝╚═╝  ╚═╝╚═╝  ╚═╝\n" +
        "Developed by: Mohamed Hamada (BayLak Egypt)", 
        "color: #00FF00; font-weight: bold; font-family: monospace;"
    );

    console.log("%c [!] Hyper-Speed Engine Started. Monitoring Live...", "color: #FFFF00;");

    let hyperInterval = setInterval(() => {
        let buttons = document.querySelectorAll('div[role="button"][aria-label*="More options"]');
        
        if (buttons.length === 0) {
            window.scrollBy(0, 1000);
            return;
        }

        buttons.forEach((btn) => {
            btn.click();
            
            setTimeout(() => {
                let menuItems = document.querySelectorAll('div[role="menuitem"]');
                let found = false;
                
                menuItems.forEach((item) => {
                    if (item.innerText.includes('Unfollow') || item.innerText.includes('إلغاء المتابعة')) {
                        item.click();
                        found = true;
                    }
                });

                if (found) {
                    totalUnfollowed++;
                    let duration = ((Date.now() - startTime) / 1000).toFixed(1);
                    // Live Update in Console
                    console.log(
                        `%c [+] Unfollowed: ${totalUnfollowed} | Speed: ${(totalUnfollowed / duration).toFixed(2)} ops/sec | Time: ${duration}s`, 
                        "color: #00FF00; background: #000; border-left: 4px solid #00FF00; padding: 2px 10px;"
                    );
                }

                btn.closest('div.x1gefphp')?.remove();
            }, 5); // Near-zero delay for extreme speed
        });

        window.scrollBy(0, 600);

    }, 150); // Checks for new targets every 150ms

    // To stop the script and see final report
    window.stopBayLak = () => {
        clearInterval(hyperInterval);
        console.log(`%c [FINISH] Total Processed: ${totalUnfollowed} accounts.`, "color: #FF00FF; font-size: 16px; font-weight: bold;");
    };
})();

Screenshot from 2026-05-09 22-23-21

@reyhzer
Copy link
Copy Markdown

reyhzer commented May 11, 2026

anyone has working code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment