Skip to content

Instantly share code, notes, and snippets.

@renestalder
Last active May 3, 2024 14:08
Show Gist options
  • Save renestalder/c5b77635bfbec8f94d28 to your computer and use it in GitHub Desktop.
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! ');
@arrio3107
Copy link

arrio3107 commented Jun 20, 2023

@mdnayemhossain Which browser you are using?. Check that you are on the right page, as I mentioned earlier, you should be doing this on your following page where all your followings are showing.

@mdnayemhossain
Copy link

mdnayemhossain commented Jun 20, 2023

@arrio3107 I'm using the google chrome browser and yeah I was on the following page that you've mentioned but it showed me the above-mentioned error, unfortunately. Thanks in advance...

@fettou
Copy link

fettou commented Jul 14, 2023

any working way to unfollow all list in this page https://www.facebook.com/YourUserName/following i tried everything in thread and non worked with me please any new way ?

@fettou
Copy link

fettou commented Jul 14, 2023

**Hello, this script is completely functional; also added auto scroll after every unfollow. the code isn't perfect, but it gets the job done. ❤️ 1 - Goto https://www.facebook.com/YourUserName/following 2 - Scroll down a bit and you'll be able to see all your followings. 3 - press CMND + OPTION + C to open console(for macbook), paste the code. and see magic.

**

`

let intervalId = setInterval(function () {
let manageButtons = document.querySelectorAll('div[aria-label="Manage"]');
let manageButton = manageButtons[0];
if (manageButton) {

    setTimeout(() => {

        manageButton.click();
    }, 800);
    let unfollowInterval = setInterval(function () {

        setTimeout(() => {

            var unfollowButtons = document.querySelector('div[role="menuitem"]');
            unfollowButtons.click();
            window.scrollBy(0, 60);
        }, 500);
        clearInterval(unfollowInterval);
    }, 500);
    setTimeout(() => {

        manageButton.remove();
        unfollowButtons.click();
    }, 1000);
} else {
}
}, 500);

`

doesn't work for me

@jcarroll
Copy link

jcarroll commented Aug 6, 2023

Thank you so much! I was able to modify the above code; I created a fork with code that worked for me:

https://gist.github.com/jcarroll/cc3e0880316e0dfad6f2dd37fdc25cc8

Note you'll need to update the class for the unlikeBtn

@fettou
Copy link

fettou commented Aug 14, 2023

Thank you so much! I was able to modify the above code; I created a fork with code that worked for me:

https://gist.github.com/jcarroll/cc3e0880316e0dfad6f2dd37fdc25cc8

Note you'll need to update the class for the unlikeBtn

good job can u make a working method to unfollow all people on following list ?

@jcarroll
Copy link

can u make a working method to unfollow all people on following list ?

Are you asking about "unfollowing" a "friend"? Or, are you asking about "unfriending" a "friend"?

For the latter, I used L.O.C. browser extension with good results, which includes a "Friends Remover: find and remove friends with ease."

It gave me a list of all my friends, and I was able to check one box to mark 100 at a time and then click once to remove all 100. I had 400-600 friends, so it only took about 15 clicks to "unfriend" all of them. Note it did take a few minutes to process each batch of 100, so total time was several minutes, but effort was very low.

For the former (un_following_ other people), no, that I'm not familiar with.

@farukborann
Copy link

farukborann commented Sep 18, 2023

@COFFEEHOLIC47 @pgbnguyen @kevindashgit I wrote a new script that unlike pages/users (unfollow will take another script, hopefully someone else does it). To use it:

  1. Open Facebook > Open your profile (https://www.facebook.com/{username})
  2. On the right-hand side, click the "..." button > Activity Log
  3. Go to Connections > Pages, page likes and interests
  4. Scroll down as far down as you can (this ensures the script unlikes everything)

The benefit of using the Activity Log is you can unlike deleted/inactive pages, which you can't do in https://www.facebook.com/{username}/following

Then run this script (I can make it much more performant later):

(async () => {
    var logs = document.querySelectorAll(selectors().log);
    for (let i = 0; i < logs.length; i++) {
        try {
            const logElement = logs[i];
            logElement.querySelector(selectors().moreActions).click();
            await wait(1500);
            document
                .querySelector(selectors().unlikeBtn)
                .firstChild.firstChild.click();
            await wait(500);
            i--;
        }
        catch (error) {
            console.log(error);
        }
    }
})();
function selectors() {
    return {
        log: `[class="om3e55n1 jl2a5g8c alzwoclg"]`,
        moreActions: `[aria-label="Action options"]`,
        unlikeBtn: `[role="menu"] [class="alzwoclg cqf1kptm cgu29s5g om3e55n1"]`,
    };
}
function wait(milliseconds) {
    return new Promise((resolve) => {
        setTimeout(() => {
            resolve(null);
        }, milliseconds);
    });
}
//# sourceMappingURL=index.js.map

Happy Coding!

I just updated the selectors :

function selectors() {
    return {
        log: '[class="xdj266r x2bj2ny x1lq5wgf xgqcy7u x30kzoy x9jhf4c x1yztbdb xwib8y2"]',
        moreActions: '[aria-label="Action options"]',
        unlikeBtn: '[role="menu"] [class*="x1i10hfl xjbqb8w x6umtig"]',
    };
}

Its working for me, thanks.

@COFFEEHOLIC47
Copy link

Thank you so much! I was able to modify the above code; I created a fork with code that worked for me:
https://gist.github.com/jcarroll/cc3e0880316e0dfad6f2dd37fdc25cc8
Note you'll need to update the class for the unlikeBtn

good job can u make a working method to unfollow all people on following list ?

Hi fettou,

Firstly, Thank you for your work.
It works for jcarroll

As you read below, # kept rolling to '19453' after I entered the code you provided on July 14, which also indicated 'Promise {; undefined}.

Turns out that the long list of "Following" I am following is still there.

image

@muhammadwaqasmbd
Copy link

muhammadwaqasmbd commented Oct 5, 2023

I have modified this script to handle errors. It is working perfectly fine now.
Just go to your following page https://www.facebook.com/YourUserName/following and run the script.

let intervalId = setInterval(function () {
let manageButtons = document.querySelectorAll('div[aria-label="Manage"]');
let manageButton = manageButtons[0];
if (manageButton) {

    setTimeout(() => {

        manageButton.click();
    }, 800);
    var unfollowButtons = null;
    let unfollowInterval = setInterval(function () {

        setTimeout(() => {

            unfollowButtons = document.querySelector('div[role="menuitem"]');
            if(unfollowButtons){
                unfollowButtons.click();
                window.scrollBy(0, 60);
            }
        }, 500);
        clearInterval(unfollowInterval);
    }, 500);
    setTimeout(() => {

        manageButton.remove();
        if(unfollowButtons){
            unfollowButtons.click();
        }
    }, 1000);
} else {
}
}, 500);

@jcarroll
Copy link

good job can u make a working method to unfollow all people on following list ?
Turns out that the long list of "Following" I am following is still there.

@COFFEEHOLIC47 and @fettou, others:

The following code worked for me to "unfollow" all Friends, Groups, and Pages:
https://gist.github.com/jcarroll/1b97f5f81c4668bf3dfdb97b0ac0eb02

@naruepanart
Copy link

I have modified this script to handle errors. It is working perfectly fine now. Just go to your following page https://www.facebook.com/YourUserName/following and run the script.

let intervalId = setInterval(function () {
let manageButtons = document.querySelectorAll('div[aria-label="Manage"]');
let manageButton = manageButtons[0];
if (manageButton) {

    setTimeout(() => {

        manageButton.click();
    }, 800);
    var unfollowButtons = null;
    let unfollowInterval = setInterval(function () {

        setTimeout(() => {

            unfollowButtons = document.querySelector('div[role="menuitem"]');
            if(unfollowButtons){
                unfollowButtons.click();
                window.scrollBy(0, 60);
            }
        }, 500);
        clearInterval(unfollowInterval);
    }, 500);
    setTimeout(() => {

        manageButton.remove();
        if(unfollowButtons){
            unfollowButtons.click();
        }
    }, 1000);
} else {
}
}, 500);

20 Dec 2023 is working.

@Mahmoud-Wagihh
Copy link

Mahmoud-Wagihh commented Dec 21, 2023

I have modified this script to handle errors. It is working perfectly fine now. Just go to your following page https://www.facebook.com/YourUserName/following and run the script.

let intervalId = setInterval(function () {
let manageButtons = document.querySelectorAll('div[aria-label="Manage"]');
let manageButton = manageButtons[0];
if (manageButton) {

    setTimeout(() => {

        manageButton.click();
    }, 800);
    var unfollowButtons = null;
    let unfollowInterval = setInterval(function () {

        setTimeout(() => {

            unfollowButtons = document.querySelector('div[role="menuitem"]');
            if(unfollowButtons){
                unfollowButtons.click();
                window.scrollBy(0, 60);
            }
        }, 500);
        clearInterval(unfollowInterval);
    }, 500);
    setTimeout(() => {

        manageButton.remove();
        if(unfollowButtons){
            unfollowButtons.click();
        }
    }, 1000);
} else {
}
}, 500);

20 Dec 2023 is working.

Untitled

hi, i tried this code and it's not working, it takes sometime and then gives me this error messages, i can't reach the bottom of the following page because because i have 5k followings i'am frustrated :(

@l1ack0der
Copy link

21 march 2024

Its not working for me. Hope there will be some solution soon.

@biologeek
Copy link

biologeek commented Apr 22, 2024

Sorry for the ugly code that follows. It work for both pages and groups (the second part is for groups). Basically selects all by their aria-label (here in French, up to you to fit to your language). Thanks to previous (and next) participants, fun challenge !

let intervalId = setInterval(function () {
    let manageButtons = document.querySelectorAll('div[aria-label="**J’aime déjà**"]');
    let manageButton = manageButtons[0];
    if (manageButton) {
        setTimeout(() => {
            manageButton.click();
        }, 800);
        var unfollowButtons = null;
        let unfollowInterval = setInterval(function () {
            setTimeout(() => {
                unfollowButtons = document.querySelector('input[aria-label="**Annuler la mention J’aime**"]');
                console.log(unfollowButtons)
                if(unfollowButtons){
                    // Page
                    unfollowButtons.click();
                   unfollowUpdate = document.querySelector('div[aria-label="**Mettre à jour**"]');
                    unfollowUpdate.click();
                } 
            }, 500);
            clearInterval(unfollowInterval);
        }, 500);
        setTimeout(() => {
            manageButton.remove();
            if(unfollowButtons){
                unfollowButtons.click();
            }
        }, 1000);
    } else {
    }
}, 500);
let intervalGroupId = setInterval(function () {
    let mangeButtons = document.querySelectorAll('div[aria-label="**Abonnée**"]');
    let mangeButton = mangeButtons[0];
    if (mangeButton) {
        setTimeout(() => {
            mangeButton.click();
        }, 800);
        var unflwButtons = null;
        let unflwInterval = setInterval(function () {
            setTimeout(() => {
    // Group with subscription
                var radio = document.querySelectorAll('div[role="radio"]')[2];
                if (radio){
                    radio.click();
                                setTimeout(() => {
                    unflwUpdate = document.querySelector('div[aria-label="**Mettre à jour**"]');
                    unflwUpdate.click();
}, 200);                    
                }
            }, 500);
            clearInterval(unflwInterval);
        }, 500);
        setTimeout(() => {
            mangeButton.remove();
            if(unflwButtons){
                unflwButtons.click();
            }
        }, 1000);
    } else {
    }
}, 500);

@yulose9
Copy link

yulose9 commented Apr 25, 2024

let intervalId = setInterval(function () {
let manageButtons = document.querySelectorAll('div[aria-label="J’aime déjà"]');
let manageButton = manageButtons[0];
if (manageButton) {
setTimeout(() => {
manageButton.click();
}, 800);
var unfollowButtons = null;
let unfollowInterval = setInterval(function () {
setTimeout(() => {
unfollowButtons = document.querySelector('input[aria-label="Annuler la mention J’aime"]');
console.log(unfollowButtons)
if(unfollowButtons){
// Page
unfollowButtons.click();
unfollowUpdate = document.querySelector('div[aria-label="Mettre à jour"]');
unfollowUpdate.click();
}
}, 500);
clearInterval(unfollowInterval);
}, 500);
setTimeout(() => {
manageButton.remove();
if(unfollowButtons){
unfollowButtons.click();
}
}, 1000);
} else {
}
}, 500);
let intervalGroupId = setInterval(function () {
let mangeButtons = document.querySelectorAll('div[aria-label="Abonnée"]');
let mangeButton = mangeButtons[0];
if (mangeButton) {
setTimeout(() => {
mangeButton.click();
}, 800);
var unflwButtons = null;
let unflwInterval = setInterval(function () {
setTimeout(() => {
// Group with subscription
var radio = document.querySelectorAll('div[role="radio"]')[2];
if (radio){
radio.click();
setTimeout(() => {
unflwUpdate = document.querySelector('div[aria-label="Mettre à jour"]');
unflwUpdate.click();
}, 200);
}
}, 500);
clearInterval(unflwInterval);
}, 500);
setTimeout(() => {
mangeButton.remove();
if(unflwButtons){
unflwButtons.click();
}
}, 1000);
} else {
}
}, 500);

well this is still working, thanks!!!

@ITz-SaGaR
Copy link

Anyone can provide the latest version of Script which will work with EN? Since now Unfollow comes after hovering on the Picture of the list.

@HVR88
Copy link

HVR88 commented May 3, 2024

Not going to happen. The changes to the page make it impossible to target the links the way the previous script employed.

Did anyone else come looking because of the news surrounding the "Unfollow Everything 2.0" lawsuit? That's going to fail. No extension or script will ever work for longer than a short period as Facebook are constantly changing their source and layouts. And no sourt can compell FB to not change their layout.

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