Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save StubbornlyDesigned/99f4e02219027704fd98 to your computer and use it in GitHub Desktop.
Save StubbornlyDesigned/99f4e02219027704fd98 to your computer and use it in GitHub Desktop.
This script goes through and removes all members from a Facebook group. Replace the ID in the second line with your own Facebook ID!!! Then navigate to the members tab of your group and copy/paste the entire code into the javascript console. Script tested in Chrome. Removes 10 members a minute!
var deleteAllGroupMembers = (function () {
var excludedFbIds = ['100005315525880']; /*########## Replace number between single quotes with your own Facebook ID. DO NOT REMOVE THE SINGLE QUOTES! ##########*/
var deleteAllGroupMembers = {};
var usersToDeleteQueue = [];
var scriptEnabled = false;
var processing = false;
var memberCount = document.getElementsByClassName('_5bv4')[0].lastChild;
deleteAllGroupMembers.start = function() {
scriptEnabled = true;
deleteAll();
};
deleteAllGroupMembers.stop = function() {
scriptEnabled = false;
};
function deleteAll() {
if(scriptEnabled) {
queueMembersToDelete();
processQueue();
}
}
function queueMembersToDelete() {
var adminActions = document.getElementsByClassName('adminActions');
for(var i = 0; i < adminActions.length; i++) {
var gearWheelIconDiv = adminActions[i];
varhyperlinksInAdminDialog = gearWheelIconDiv.getElementsByTagName('a');
var fbMemberId = gearWheelIconDiv.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.id.replace('member_','');
var fbMemberName = gearWheelIconDiv.parentNode.parentNode.parentNode.getElementsByClassName('fcb')[0].textContent;
if(excludedFbIds.indexOf(fbMemberId) != -1) {
continue;
} else {
usersToDeleteQueue.push({'memberId': fbMemberId, 'memberName': fbMemberName, 'gearWheelIconDiv': gearWheelIconDiv});
}
}
}
function processQueue() {
if(!scriptEnabled) {
return;
}
if(usersToDeleteQueue.length > 0) {
removeMember();
setTimeout(function(){
processQueue();
}, 6000); /*########## Sets total time period between deletions in milliseconds. ##########*/
} else {
getMore();
}
}
function removeMember() {
if(processing) {
return;
}
var memberToDelete = usersToDeleteQueue.shift();
var gearWheelHref = memberToDelete.gearWheelIconDiv.getElementsByTagName('a')[0];
var memberCell = memberToDelete.gearWheelIconDiv.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;
processing = true;
gearWheelHref.click();
setTimeout(function() {
var popupRef = gearWheelHref.id;
var popupDiv = getElementByAttributeValue("data-ownerid", popupRef);
var popupLinks = popupDiv.getElementsByTagName('a');
for(var k = 0; k < popupLinks.length; k++) {
if(popupLinks[k].getAttribute('href').indexOf('remove.php') !== -1) {
popupLinks[k].click();
setTimeout(function() {
var confirmButton = document.getElementsByClassName('layerConfirm uiOverlayButton selected')[0];
if(confirmButton != null) {
confirmButton.click();
memberCell.parentNode.removeChild(memberCell);
var newMemberCount = parseInt(memberCount.innerText.replace(',', '')) - 1;
memberCount.innerText = newMemberCount.toLocaleString();
}
processing = false;
}, 2000); /*########## Sets time period in milliseconds to wait to click on 'Confirm.' ##########*/
}
}
}, 500); /*########## Sets time period in milliseconds to wait to hit 'Remove from Group.' ##########*/
}
function getMore() {
processing = true;
more = document.getElementsByClassName("pam uiBoxLightblue uiMorePagerPrimary");
if(typeof more != 'undefined') {
more[0].click();
setTimeout(function() {
processing = false;
deleteAll();
}, 5000); /*########## Sets time period in milliseconds for the next batch of members to load. ##########*/
} else {
deleteAllGroupMembers.stop();
}
}
function getElementByAttributeValue(attr, value) {
var elements = document.getElementsByTagName("div");
for (var j = 0; j < elements.length; j++) {
if (elements[j].hasAttribute(attr)) {
if (value) {
if (elements[j].getAttribute(attr) == value) {
return elements[j];
}
} else {
return elements[j];
}
}
}
return false;
};
return deleteAllGroupMembers;
})();
deleteAllGroupMembers.start();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment