Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Some javascript code that allows you to automatically delete all members from a facebook group.
// first go to https://www.facebook.com/groups/XXXX/members/
// then paste this in the javascript console
deleteAll = [];
deleteAll.elms = [];
deleteAll.canClick = function (el) {
return (typeof el != 'undefined') && (typeof el.click != 'undefined');
}
deleteAll.load = function() {
deleteAll.elms = document.getElementsByClassName("uiPopoverButton _p uiButton uiButtonSuppressed uiButtonNoText");
if (i < deleteAll.elms.length - 5 && !more[0].hasChildNodes()) {
setTimeout(deleteAll.getMore, 1000);
} else {
setTimeout(deleteAll.go, 2000);
}
}
deleteAll.getMore = function() {
more = document.getElementsByClassName("pam uiBoxLightblue uiMorePagerPrimary");
if (typeof more != 'undefined' && deleteAll.canClick(more[0])) {
more[0].click();
setTimeout(deleteAll.load, 2000);
} else {
setTimeout(deleteAll.load, 100);
}
}
deleteAll.go = function() {
try {
deleteAll.doClick(1);
} catch(e) {
setTimeout(deleteAll.load, 1000);
} finally {
setTimeout(deleteAll.load, 500000);
}
}
deleteAll.doClick = function(i) {
deleteAll.elms[i].click();
setTimeout(function(){deleteAll.doClick2(i)}, 1000);
}
deleteAll.doClick2 = function(i) {
document.getElementsByClassName("_54nc")[1].click()
setTimeout(function(){deleteAll.confirm(i)}, 1000);
}
deleteAll.confirm = function (i) {
remove_but = document.getElementsByClassName("_42ft _42fu layerConfirm uiOverlayButton selected _42g- _42gy")[0];
more = document.getElementsByClassName("pam uiBoxLightblue uiMorePagerPrimary");
if ((i < deleteAll.elms.length - 5 || !more[0].hasChildNodes()) && deleteAll.canClick(remove_but) && remove_but.value == "1") {
remove_but.click();
setTimeout(function(){deleteAll.confirm2(i)}, 1000);
} else {
setTimeout(deleteAll.getMore, 2000);
}
}
deleteAll.confirm2 = function(i) {
node = document.getElementsByClassName('uiContextualLayerPositioner uiLayer hidden_elem')[0];
node.parentNode.removeChild(node);
setTimeout(function(){deleteAll.doClick(i)}, 1000);
}
deleteAll.load();
@rafoo83
Copy link

rafoo83 commented Jan 1, 2014

THANK YOU!!! I was looking for this..!! :)
Good job!!

Can I find another similar script to delete all publications?

@tahmidxp96
Copy link

tahmidxp96 commented Jan 5, 2014

that was awesome dude ^_^
i just have extended timeout to avoid the "User is not a member of this group" loop in slow connections :D
u should check this out guys
deleteAll = [];
deleteAll.elms = [];

deleteAll.canClick = function (el) {
return (typeof el != 'undefined') && (typeof el.click != 'undefined');
}

deleteAll.load = function() {
deleteAll.elms = document.getElementsByClassName("uiPopoverButton _p uiButton uiButtonSuppressed uiButtonNoText");
if (i < deleteAll.elms.length - 5 && !more[0].hasChildNodes()) {
setTimeout(deleteAll.getMore, 2000);
} else {
setTimeout(deleteAll.go, 3000);
}
}

deleteAll.getMore = function() {
more = document.getElementsByClassName("pam uiBoxLightblue uiMorePagerPrimary");
if (typeof more != 'undefined' && deleteAll.canClick(more[0])) {
more[0].click();
setTimeout(deleteAll.load, 3000);
} else {
setTimeout(deleteAll.load, 200);
}
}

deleteAll.go = function() {
try {
deleteAll.doClick(1);
} catch(e) {
setTimeout(deleteAll.load, 2000);
} finally {
setTimeout(deleteAll.load, 500000);
}
}

deleteAll.doClick = function(i) {
deleteAll.elms[i].click();
setTimeout(function(){deleteAll.doClick2(i)}, 1000);
}

deleteAll.doClick2 = function(i) {
document.getElementsByClassName("_54nc")[1].click()
setTimeout(function(){deleteAll.confirm(i)}, 2000);
}

deleteAll.confirm = function (i) {
remove_but = document.getElementsByClassName("_42ft _42fu layerConfirm uiOverlayButton selected _42g- _42gy")[0];
more = document.getElementsByClassName("pam uiBoxLightblue uiMorePagerPrimary");

if ((i < deleteAll.elms.length - 5 || !more[0].hasChildNodes()) && deleteAll.canClick(remove_but) && remove_but.value == "1") {
remove_but.click();
setTimeout(function(){deleteAll.confirm2(i)}, 2000);
} else {
setTimeout(deleteAll.getMore, 3000);
}
}

deleteAll.confirm2 = function(i) {
node = document.getElementsByClassName('uiContextualLayerPositioner uiLayer hidden_elem')[0];
node.parentNode.removeChild(node);
setTimeout(function(){deleteAll.doClick(i)}, 2000);
}

deleteAll.load();

https://facebook.com/hello.world.96

@ramizaki
Copy link

ramizaki commented Jan 13, 2014

any update ? it isn't working help please
it just stuck at confirm deleting

@nckblink
Copy link

nckblink commented Jan 16, 2014

Any update? not working for me either and I have 4000 people to remove

@undrenic
Copy link

undrenic commented Mar 3, 2014

it didn't work for me,
"ReferenceError: i is not defined"
what is "i"?

@marcosfreitas
Copy link

marcosfreitas commented Mar 4, 2014

This code works! Facebook disabled the native console brownser, but if you install the "Firebug" extension and run this script, it will work for you!

This script does not delete the group, just all the other members and then terminates execution.

@marcosfreitas
Copy link

marcosfreitas commented Mar 4, 2014

IF YOU WANT NOT TO INSTALL THE FIREBUG EXTENSION, YOU CAN ACTIVATE THE USE OF THE CONSOLE HERE: https://www.facebook.com/selfxss

@michaelv
Copy link

michaelv commented Apr 21, 2014

I created a script that works with the new facebook layout: https://gist.github.com/michaelv/11145168
Enjoy!
Some pieces of the code were copied from this gist.

@ursaltydog
Copy link

ursaltydog commented Jul 29, 2014

Babrath, 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 member is messing with the current membership by deleting them, or blocking them indiscriminately.

@melissatt
Copy link

melissatt commented Sep 22, 2014

how do you run this on Mac Chrome?? Please help I need to delete two groups ASAP

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