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