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! ');
@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