Skip to content

Instantly share code, notes, and snippets.

@renestalder
Last active November 9, 2024 16:25
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! ');
Copy link

ghost commented Jun 15, 2023

+1

@kevindashgit
Copy link

The script I posted a while back still works, just run it from within chrome/firefox dev tools console.

document.querySelectorAll('[aria-label="Toggle to follow"]').forEach(i=>i.click())

This script assumes that you are using a web browser to access the social media platform, specifically revealing the list of people you wanna unfollow. You can execute this script by opening the developer console in your browser while on the social media website, and then pasting and running the code.

@arrio3107
Copy link

arrio3107 commented Jun 20, 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);

`

@mdnayemhossain
Copy link

@arrio3107 Here I am getting no response while I wad trying the code you provided earlier. Put the screen shot for your attention...

ddip

@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 :(

@l1ackoder
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.

@ixus36900
Copy link

Encontré una manera de obtener los todos los enlaces de las personas que alguna vez les envié invitación de amistad y por defecto las empecé a seguir, es decir todos los seguidos que no se muestran normalmente. Pero ahora no se como hacer sin necesidad de API, solo con script de consola, hacer para dejar de seguir y cancelar solicitud de amistad a cada uno de esos perfiles. alguien sabe como?

@jcarroll
Copy link

jcarroll commented Sep 29, 2024

@ixus36900 asked about retracting sent (outgoing) friend requests, saying he found a way to get a list of links to the profiles of those whom he previously offered a friend request, and he's looking for a way to cancel (retract) those offers (requests).

Work in progress:

  1. https://www.facebook.com/friends/requests
  2. "View sent Requests"
    image
  3. Use the "inspect" tool to find the html class of the "cancel request" button element (today it was "x6s0dn4 x78zum5 xl56j7k x1608yet xljgi0e x1e0frkt")
    image
  4. Use the code that worked to "unfollow" all Friends, Groups, and Pages...
    https://gist.github.com/jcarroll/1b97f5f81c4668bf3dfdb97b0ac0eb02
  5. Replace [class="x1b0d499 xi3auck"] with the class from #3, above.
  6. Run code in console:

Results: It did cancel all outgoing request requests for me. However, it also accepted all incoming friend requests also.

To cancel outgoing requests and not accept incoming requests, I would next look for an htnl class that is shared by the "cancel request" elements that is not part of the accept request elements.

Unfortunately, since I just accepted all incoming friend requests, I don't have any of those elements to inspect.

I'll be very interested to see progress on this, especially anyone with steps to get it working.

-jFc

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