Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save AaronRM/78b215f705e3211f8f17 to your computer and use it in GitHub Desktop.

Select an option

Save AaronRM/78b215f705e3211f8f17 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.parentNode.parentNode.parentNode.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();
@dizzyval

Copy link
Copy Markdown

man this is dope.
thanks dude 👍
working great like a charm 🐙

@Mte90

Mte90 commented Dec 28, 2015

Copy link
Copy Markdown

+1

@Cryptid

Cryptid commented Jan 19, 2016

Copy link
Copy Markdown

Works great on Chrome, but still removes the Admin from group even after inputting my fbid to exclude.

@carloslopez1990

Copy link
Copy Markdown

i make the same thing but using ajax requests with only 18 lines of code...
https://gist.github.com/carloslopez1990/319824904639e31221e3

@VRosser

VRosser commented Mar 29, 2016

Copy link
Copy Markdown

Having a problem with the excluded FBID's . Even when I enter the string with the ID's, it still deleted them. Can't seem to get this to work without that bug. (Can someone give me advice, I have 8 admins I want to keep)

@vinnyamp

Copy link
Copy Markdown

Thanks, this version is working perfectly with the new facebook layout.

@dongemus

Copy link
Copy Markdown

Thanks, worked like a charm :)

@forresthopkinsa

Copy link
Copy Markdown

Works beautifully, thanks!

@marianberry

Copy link
Copy Markdown

the script stop code is returning an error of "undefined." Any help?

@marianberry

Copy link
Copy Markdown

I have even cleared the console but yet it runs

@Chris-Pr

Copy link
Copy Markdown

Could this be modified to remove blocks from groups?

@mrooney

mrooney commented Nov 15, 2016

Copy link
Copy Markdown

@carloslopez1990 looks like that gist isn't available any more. Would it be possible to share it again?

@briann12

Copy link
Copy Markdown

Hi AaronRM,

Is it anyway to modify this script to unblock all members from the block lists?

Thanks

@agkurniawan

Copy link
Copy Markdown

This works buddy, thanks
1/7/2017

@AdamFi

AdamFi commented Jan 23, 2017

Copy link
Copy Markdown

Having issues with this where it will only remove half of the member list. It goes down the left or right hand column only.

@Dannisgaard

Copy link
Copy Markdown

Thanks :-) This script save me hours of work.

@pp014

pp014 commented Feb 25, 2017

Copy link
Copy Markdown

I have hundreds of IDs to exclude, but the
var excludedFbIds = ['1234','11223344']
portion has a limit on the string.
Please suggest a modification.
thank you

@RobertAppleton

Copy link
Copy Markdown

still works flawlessly, many thanks...

@danny007spain

Copy link
Copy Markdown

Extremely useful. I removed a group of 6.500 users with the script.
Only, i have had to restart chrome several times as it was collapsed.
To search the facebook ID i used that link: Search my facebook ID

@briansipsy

Copy link
Copy Markdown

Is there a way to modify this script to delete hidden members that do not show up on the member list? I've got only a few I need to delete, and can put their id in, but don't want to enter 100k+ ids to exclude.

@hendisantika

Copy link
Copy Markdown

It does not work for me?
Why?
Any other suggestions?
Thanks

@kencarino

Copy link
Copy Markdown

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