Forked from michaelv/facebook-mass-delete-group-members.js
Last active
August 29, 2015 14:07
-
-
Save TamerShlash/6ae696be193ebc1cdc9d to your computer and use it in GitHub Desktop.
This JavaScript removes a specified set of Facebook group members. Tested with Google Chrome on 10/10/2014. PLEASE READ the Usage section in the file. Known issues: 1) When Facebook responds slowly, the script might experience hickups 2) Occasionally, the error 'this user is not a member of the group' pops up.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Slightly customized version of https://gist.github.com/michaelv/11145168 | |
Usage: | |
1. Put the IDs you want to remove in the globalToBeRemoved array, and make sure | |
they are strings | |
2. Go to the group's members page (https://www.facebook.com/groups/GID/members/) | |
3. Paste the code (after adding the IDs to globalToBeRemoved) In the Javascript | |
console, and then wait until the work is done. It takes a reasonable time. | |
*/ | |
var globalToBeRemoved = ["10000152515xxxx","10000152515xxxx"]; | |
var deleteAllGroupMembers = (function () { | |
var deleteAllGroupMembers = {}; | |
var toBeRemoved = globalToBeRemoved; | |
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'); | |
for(var i=0; i<adminActions.length; i++) { | |
var gearWheelIconDiv = adminActions[i]; | |
var fbMemberId = gearWheelIconDiv.parentNode.parentNode.id.replace('member_',''); | |
if (toBeRemoved.indexOf(fbMemberId) != -1) { | |
usersToDeleteQueue.push({'memberId': fbMemberId, 'gearWheelIconDiv': gearWheelIconDiv}); | |
} else { continue; } | |
} | |
} | |
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); | |
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 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(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
May you please make a version for "http://touch.facebook.com" ? I think will be a lot faster. Thank you very much!