Skip to content

Instantly share code, notes, and snippets.

@michaelv
Created April 21, 2014 15:00
Show Gist options
  • Star 42 You must be signed in to star a gist
  • Fork 30 You must be signed in to fork a gist
  • Save michaelv/11145168 to your computer and use it in GitHub Desktop.
Save michaelv/11145168 to your computer and use it in GitHub Desktop.
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();
@mskian
Copy link

mskian commented Dec 23, 2015

thanks it works for me

@Ikrm
Copy link

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
Copy link

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

@DonBaronFactory
Copy link

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

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

@gaurav99t
Copy link

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

@hendisantika
Copy link

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

@umartechboy
Copy link

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
Copy link

@umartechboy
Thank you so much

@Ferin29
Copy link

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
Copy link

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)?

Copy link

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
Copy link

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
Copy link

yahia23 commented Nov 11, 2017

-_-

@garmfield2017
Copy link

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

@maci1011
Copy link

@MarkAlmarez
Copy link

I DIDNT GET

@MarkAlmarez
Copy link

Didn't work

@johanna1965
Copy link

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

@poteto
Copy link

poteto commented Feb 17, 2018

@kencarino
Copy link

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

Copy link

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
Copy link

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
Copy link

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

@jesper12345
Copy link

Dont work

@shadkawa
Copy link

@nikhil455
Copy link

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

@zoljaxity
Copy link

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

@AlessandroGIovannoli
Copy link

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

@skphantom
Copy link

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
Copy link

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