Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
This javascript removes all users from a facebook group. It works with the new facebook layout. Paste this in the javascript console. Script tested in Firefox. Known issues: 1. when facebook responds slowly, the script might experience hickups.. 2. occasionially, the error 'this user is not a member of the group' pops up.. IMPORTANT: add your ow…
var deleteAllGroupMembers = (function () {
var deleteAllGroupMembers = {};
// the facebook ids of the users that will not be removed.
// IMPORTANT: add your own facebook id here so that the script will not remove yourself!
var excludedFbIds = ['1234','11223344']; // make sure each id is a string!
var usersToDeleteQueue = [];
var scriptEnabled = false;
var processing = false;
deleteAllGroupMembers.start = function() {
scriptEnabled = true;
deleteAll();
};
deleteAllGroupMembers.stop = function() {
scriptEnabled = false;
};
function deleteAll() {
if (scriptEnabled) {
queueMembersToDelete();
processQueue();
}
}
function queueMembersToDelete() {
var adminActions = document.getElementsByClassName('adminActions');
console.log(excludedFbIds);
for(var i=0; i<adminActions.length; i++) {
var gearWheelIconDiv = adminActions[i];
var hyperlinksInAdminDialog = gearWheelIconDiv.getElementsByTagName('a');
var fbMemberId = gearWheelIconDiv.parentNode.parentNode.id.replace('member_','');
var fbMemberName = getTextFromElement(gearWheelIconDiv.parentNode.parentNode.getElementsByClassName('fcb')[0]);
if (excludedFbIds.indexOf(fbMemberId) != -1) {
console.log("SKIPPING "+fbMemberName+' ('+fbMemberId+')');
continue;
} else {
usersToDeleteQueue.push({'memberId': fbMemberId, 'gearWheelIconDiv': gearWheelIconDiv});
}
}
}
function processQueue() {
if (!scriptEnabled) {
return;
}
if (usersToDeleteQueue.length > 0) {
removeNext();
setTimeout(function(){
processQueue();
},1000);
} else {
getMore();
}
}
function removeNext() {
if (!scriptEnabled) {
return;
}
if (usersToDeleteQueue.length > 0) {
var nextElement = usersToDeleteQueue.pop();
removeMember(nextElement.memberId, nextElement.gearWheelIconDiv);
}
}
function removeMember(memberId, gearWheelIconDiv) {
if (processing) {
return;
}
var gearWheelHref = gearWheelIconDiv.getElementsByTagName('a')[0];
gearWheelHref.click();
processing = true;
setTimeout(function(){
var popupRef = gearWheelHref.id;
var popupDiv = getElementByAttribute('data-ownerid',popupRef);
var popupLinks = popupDiv.getElementsByTagName('a');
for(var j=0; j<popupLinks.length; j++) {
if (popupLinks[j].getAttribute('href').indexOf('remove.php') !== -1) {
// this is the remove link
popupLinks[j].click();
setTimeout(function(){
var confirmButton = document.getElementsByClassName('layerConfirm uiOverlayButton selected')[0];
var errorDialog = getElementByAttribute('data-reactid','.4.0');
if (confirmButton != null) {
if (canClick(confirmButton)) {
confirmButton.click();
} else {
console.log('This should not happen memberid: '+memberId);
5/0;
console.log(gearWheelIconDiv);
}
}
if (errorDialog != null) {
console.log("Error while removing member "+memberId);
errorDialog.getElementsByClassName('selected layerCancel autofocus')[0].click();
}
processing = false;
},700);
continue;
}
}
},500);
}
function canClick(el) {
return (typeof el != 'undefined') && (typeof el.click != 'undefined');
}
function getMore() {
processing = true;
more = document.getElementsByClassName("pam uiBoxLightblue uiMorePagerPrimary");
if (typeof more != 'undefined' && canClick(more[0])) {
more[0].click();
setTimeout(function(){
deleteAll();
processing = false;
}, 2000);
} else {
deleteAllGroupMembers.stop();
}
}
function getTextFromElement(element) {
var text = element.textContent;
return text;
}
function getElementByAttribute(attr, value, root) {
root = root || document.body;
if(root.hasAttribute(attr) && root.getAttribute(attr) == value) {
return root;
}
var children = root.children,
element;
for(var i = children.length; i--; ) {
element = getElementByAttribute(attr, value, children[i]);
if(element) {
return element;
}
}
return null;
}
return deleteAllGroupMembers;
})();
deleteAllGroupMembers.start();
// stop the script by entering this in the console: deleteAllGroupMembers.stop();
@EdMarcus

This comment has been minimized.

Copy link

@EdMarcus EdMarcus commented Jun 5, 2014

Works! Thanks! hahaha

@HamdanFadh

This comment has been minimized.

Copy link

@HamdanFadh HamdanFadh commented Jun 20, 2014

thanks guys, it's work :D

@vinnyamp

This comment has been minimized.

Copy link

@vinnyamp vinnyamp commented Jun 24, 2014

thanks! it works :)

@kpeechan

This comment has been minimized.

Copy link

@kpeechan kpeechan commented Jul 23, 2014

Many thanks, I was found a few days.

@ursaltydog

This comment has been minimized.

Copy link

@ursaltydog ursaltydog commented Jul 29, 2014

Can this script be tailored to dump out the blocked list? I need to clean it out as it's over 9k, and we can't tell if a rogue admin is messing with the current membership by deleting them, or blocking them indiscriminately. Also, would the current admin ID numbers need to be placed if we're only wanting to do the "block list"?

@nakiaanderica

This comment has been minimized.

Copy link

@nakiaanderica nakiaanderica commented Aug 25, 2014

could someone please explain to me how you would add your name as a script so that i don't delete myself, prgramme works great, managaed to delete 1000's of people, but scared that i am about to delete myself... please help

@melissatt

This comment has been minimized.

Copy link

@melissatt melissatt commented Sep 22, 2014

How do I prevent it from not deleting me?? How do I find my user id?

@melissatt

This comment has been minimized.

Copy link

@melissatt melissatt commented Sep 22, 2014

@wira64

This comment has been minimized.

Copy link

@wira64 wira64 commented Oct 1, 2014

Hi, I had encounter this error:
["100000047850125", findIndex: function, find: function]0: "100000047850125"length: 1__proto__: Array[0]
Please help me...

@kpeechan

This comment has been minimized.

Copy link

@kpeechan kpeechan commented Nov 12, 2014

Cool, still works!

@farzam-parto

This comment has been minimized.

Copy link

@farzam-parto farzam-parto commented Jan 11, 2015

working like charm :)

@DarkDreth

This comment has been minimized.

Copy link

@DarkDreth DarkDreth commented Jan 14, 2015

Is there an easy way that I could change the whitelist to not remove people by name? I have a group of 1.5k people, but need to get rid of everyone but 200 people.

@AttiMM

This comment has been minimized.

Copy link

@AttiMM AttiMM commented Jan 29, 2015

Hi, same as DarkDreth: I wanna save cca. 300 members from 800.
var excludedFbIds is able to store 300 string elements delimited with comma?

THX!

UPDATE: YES, it can do it! Everything went fine, thank you!

@kbiviano

This comment has been minimized.

Copy link

@kbiviano kbiviano commented Jan 31, 2015

I tried using this, and I am getting the following code: unknown command: VAR, line 1 (Error code: 910)

Can you please help? I know nothing about iMacros unfortunately. I have a group with over 5,000 members on FB that I want to delete quickly. Any help you can provide would be great. Thank you!

@kbiviano

This comment has been minimized.

Copy link

@kbiviano kbiviano commented Jan 31, 2015

Got past the first error issue, and now I am getting this one: ReferenceError: document is not defined, line 23 (Error code: -991)

@nakorndev

This comment has been minimized.

Copy link

@nakorndev nakorndev commented Feb 12, 2015

It's also works on Google Chrome, Thanks!

@paulshaneallen

This comment has been minimized.

Copy link

@paulshaneallen paulshaneallen commented Mar 1, 2015

3/1/2015 - Works for me

@miketheinkman

This comment has been minimized.

Copy link

@miketheinkman miketheinkman commented Mar 1, 2015

Nice. I am working on a bash script that works in conjunction with fbcmd to grep for banned terms in my group with 40k members. It isolates the usernames and id's that I want to ban. I was trying to avoid js, but I can't ban from fbcmd, so I guess I can fork this, edit to only ban from list, script in the ids, and do it that way. I am a JS noob, so this is a lifesaver.

@xradio

This comment has been minimized.

Copy link

@xradio xradio commented Mar 13, 2015

3/13/15 - Chrome: This works! Thank you soooo much

Oh I noticed that after a few hours it just stops removing people, so you have to close the tab and start the script again. Nothing major, just something I noticed :)

@reidcooper

This comment has been minimized.

Copy link

@reidcooper reidcooper commented Mar 30, 2015

3/30/15 - Worked for Chrome :)

@thelexicondevil

This comment has been minimized.

Copy link

@thelexicondevil thelexicondevil commented Apr 8, 2015

Nice script seems to work fine.It does however appear to slow down a bit once I go through about 500 people but then again maybe it's my machine?
Still faster than doing each one myself.
Is there a way to check the 'block permanently' button also?

@sinrise

This comment has been minimized.

Copy link

@sinrise sinrise commented Apr 27, 2015

This works beautifully! Thanks so much. It's crazy we need stuff like this, though. Facebook makes it really cumbersome to remove friends, leave groups or manage members. I wonder why they don't put more into it.

@Saranga27

This comment has been minimized.

Copy link

@Saranga27 Saranga27 commented May 1, 2015

i want to remove 20000members from my 68k member group..plz help

@hollycunningham

This comment has been minimized.

Copy link

@hollycunningham hollycunningham commented May 5, 2015

Worked great, thanks! Saved me quite the headache.

@WalkingDead22

This comment has been minimized.

Copy link

@WalkingDead22 WalkingDead22 commented May 30, 2015

I saw another script that allowed for multiple tab running for deletion. Here is what it said...

Protip: as you seem to have a lot of people to delete I'd suggest running the script on multiple tabs on the same time. Just open a new tab, go to the same page, add the code, but before entering make a small change. On line number 31 in this script change "deleteAll.doClick(1);", if you put '100' in stead of '1' it'll start with deleting member number 100 in the group in stead of member number 1. So have a tab with a script started on 1, have one started on 100, one on 200, etc. and it'll go much faster. Of course once the tab started on 1 gets to 100 and finds that member deleted it'll stop working.

29 deleteAll.go = function() {
30 try {
31 deleteAll.doClick(2);
32 } catch(e) {
33 setTimeout(deleteAll.load, 1000);
34 } finally {
35 setTimeout(deleteAll.load, 500000);
36 }

Where and how would this be implemented on your script?

Thanks for any help you can offer.

@Blackglade

This comment has been minimized.

Copy link

@Blackglade Blackglade commented Jun 28, 2015

Worked like a charm on chrome!

@Copyright09

This comment has been minimized.

Copy link

@Copyright09 Copyright09 commented Aug 6, 2015

This script was working until Aug 05 2015 , but on Aug 06 2015, when the new layout for Facebook Groups was rolled out, it stopped working. I was able to use this script on Firefox, Chrome & Opera as well but now all the browsers are showing up the error copied below. [Error Copied AS IT IS]

TypeError: element is undefined
Array [ "1234", "11223344" ]

The same error was displayed when i replace the numbers with my user id.
Please Rework on the script to make this usable. Well Thanks for the Script as i was able to work with it.

mozilla

chrome

opera

@Copyright09

This comment has been minimized.

Copy link

@Copyright09 Copyright09 commented Aug 6, 2015

Dear "michaelv" this script from the link below works even now after change in the layout, but in partial as it selects to remove members but does NOT click the Confirm buttons. Looking forward towards your help.
https://gist.github.com/nirgeier/7c3950db8f23e67b155a

@kpatrzek

This comment has been minimized.

Copy link

@kpatrzek kpatrzek commented Aug 11, 2015

I delete 300 members with Chrome browser. Thanks !! 👍

@Copyright09

This comment has been minimized.

Copy link

@Copyright09 Copyright09 commented Aug 11, 2015

popovkov57 -- when did you deleted the members, & which code did you used, could you please share the link ?

@mayukojpn

This comment has been minimized.

Copy link

@mayukojpn mayukojpn commented Sep 6, 2015

https://gist.github.com/mayukojpn/9fb7ae60550311152443
It worked for me on 6/9/15.
I had to re-run the script maybe 20 times but I deleted 3000 member.

@aooz

This comment has been minimized.

Copy link

@aooz aooz commented Sep 11, 2015

Still working. Can this script be altered so it removes AND bans all group members?
Thanks.

@rgdoz

This comment has been minimized.

Copy link

@rgdoz rgdoz commented Oct 8, 2015

This is not working for me. I am getting "TypeError: element is undefined"

@AaronRM

This comment has been minimized.

Copy link

@AaronRM AaronRM commented Dec 19, 2015

Hey Folks, looks like Facebook made a slight change to the layout that broke this script. You can find my fixed version here: https://gist.github.com/AaronRM/78b215f705e3211f8f17. Note that you need to run this while on the "Members" page.

@mskian

This comment has been minimized.

Copy link

@mskian mskian commented Dec 23, 2015

thanks it works for me

@Ikrm

This comment has been minimized.

Copy link

@Ikrm Ikrm commented Aug 1, 2016

dear all how can i deleted all members in one click from group plz any body tell me..what am i do

@Chris-Pr

This comment has been minimized.

Copy link

@Chris-Pr Chris-Pr commented Oct 11, 2016

I need to unban 6000 uses from a group , does anyone know of a script that could help?

@cre8it

This comment has been minimized.

Copy link

@cre8it cre8it commented Nov 26, 2016

just in case you receive an error regarding "textContent"... replace line 32 with:

var fbMemberName = getTextFromElement(gearWheelIconDiv.parentNode.parentNode.parentNode.getElementsByClassName('fcb')[0]);

@gaurav99t

This comment has been minimized.

Copy link

@gaurav99t gaurav99t commented Jun 11, 2017

you must be an admin to run the script else you suck

@hendisantika

This comment has been minimized.

Copy link

@hendisantika hendisantika commented Jun 15, 2017

It does not work for me.
Any other suggestions please?
Thanks

@umartechboy

This comment has been minimized.

Copy link

@umartechboy umartechboy commented Jun 26, 2017

The Script needs some changes. The latest FB sources have changed some things around. I've edited the script [Jun 2017] and pasted it here. https://pastebin.com/YU6EUwRB. Kindly note that in the console, it may show wrong FBID of users being deleted (profile.php instead of ID). It doesn't matter, the delete works anyway.

@DanMossa

This comment has been minimized.

Copy link

@DanMossa DanMossa commented Jun 28, 2017

@umartechboy
Thank you so much

@Ferin29

This comment has been minimized.

Copy link

@Ferin29 Ferin29 commented Jul 3, 2017

@umartechboy hello, first thank you for your upgrade :) I try to use your script but it bans 2 members and then quit, i tried on chrome and edge ...

@howdy99

This comment has been minimized.

Copy link

@howdy99 howdy99 commented Jul 15, 2017

@umartechboy thank you for this :-) I have over 5000 members to remove in quite a few groups. Is there a way to operate this in multiple tabs so it moves a bit faster? Perhaps in a similar way as suggested by @WalkingDead22 (above)?

@ghost

This comment has been minimized.

Copy link

@ghost ghost commented Oct 12, 2017

Still no script for those who want to delete a fixed number of members, not all the members ?
Deleting 2.000 members from a groupe of 10.000 for example
like Saranga27's message

@poohgc

This comment has been minimized.

Copy link

@poohgc poohgc commented Nov 5, 2017

How do you know if its working? I just see Array [ "1234", "xxxxxxxxxxxx" ] over and over again. The first line I got was "undefined".

@yahia23

This comment has been minimized.

Copy link

@yahia23 yahia23 commented Nov 11, 2017

-_-

@garmfield2017

This comment has been minimized.

Copy link

@garmfield2017 garmfield2017 commented Dec 7, 2017

Does anyone have an updated script that works since Facebook updated the group member screen in November?

@maci1011

This comment has been minimized.

Copy link

@maci1011 maci1011 commented Dec 21, 2017

@MarkAlmarez

This comment has been minimized.

Copy link

@MarkAlmarez MarkAlmarez commented Dec 22, 2017

I DIDNT GET

@MarkAlmarez

This comment has been minimized.

Copy link

@MarkAlmarez MarkAlmarez commented Dec 22, 2017

Didn't work

@johanna1965

This comment has been minimized.

Copy link

@johanna1965 johanna1965 commented Dec 27, 2017

I am getting Syntax Error
Anyone know what I am doing wrong?

@poteto

This comment has been minimized.

Copy link

@poteto poteto commented Feb 17, 2018

@kencarino

This comment has been minimized.

Copy link

@kencarino kencarino commented Mar 23, 2018

Updated a new short solution, tested on chrome: https://gist.github.com/kencarino/3be7c5ee0bec39da99a05639c0fc2673

@ghost

This comment has been minimized.

Copy link

@ghost ghost commented Jul 17, 2018

Good job instead of taking the functions as increment you can the normal procedures, that will work like charm

@larisabeian

This comment has been minimized.

Copy link

@larisabeian larisabeian commented Jul 24, 2018

Does there exist a script after this ultimate facebook updates??? It is giving me a strange error and i am no able to identiffy it. Is something with a forcekey

@jesper12345

This comment has been minimized.

Copy link

@jesper12345 jesper12345 commented Aug 13, 2018

Where do i find fd id , and in to parts ?? "1234" "11223344"

@jesper12345

This comment has been minimized.

Copy link

@jesper12345 jesper12345 commented Aug 13, 2018

Dont work

@shadkawa

This comment has been minimized.

Copy link

@shadkawa shadkawa commented Aug 18, 2018

@nikhil455

This comment has been minimized.

Copy link

@nikhil455 nikhil455 commented May 25, 2019

its not working 23 may 2019...please update its a bit urgent,...thanks

@zoljaxity

This comment has been minimized.

Copy link

@zoljaxity zoljaxity commented Jul 26, 2019

How about removing let's say members without profile pic?

@AlessandroGIovannoli

This comment has been minimized.

Copy link

@AlessandroGIovannoli AlessandroGIovannoli commented Mar 17, 2020

hi, is still working? is there a way to load more than 200 members in the group?

@skphantom

This comment has been minimized.

Copy link

@skphantom skphantom commented Apr 26, 2020

my script remove all group members https://gist.github.com/shadkawa/03531f32d70227dedf4fb1c99cb19f1a

Hello Shadkawa,
What about removing only the unavailable member in a facebook group? That allow to multiply the reach * 10.
image

@Sallysheridan

This comment has been minimized.

Copy link

@Sallysheridan Sallysheridan commented May 23, 2020

HI --
I am runing as an admin on several groups, and in one we have detected and blocked 6700 Bulies, Fake accounts and trolls.
I have exported all these names to a CSV file, and want to place them on the other groups, as Blocked people.
How can I do that, in order to keep all these groups safe, like uploading the csv or copying the names ?

I really need urgent help on this !

Thanks Team !

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