Skip to content

Instantly share code, notes, and snippets.

@renestalder
Last active April 29, 2026 23:50
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! ');
@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.");
})();

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