Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save nirgeier/7c3950db8f23e67b155a to your computer and use it in GitHub Desktop.
Save nirgeier/7c3950db8f23e67b155a to your computer and use it in GitHub Desktop.
Delete all facebook group members on a given page. Usage: Copy this script, open developers console (F12) in chrome (win) and paste this script. The script will delete all the members that you can see in the given page. Once the script is done you should see a blank members page,
/**
* This script will delete all group members which are displayed in a given page.
*
* @author: Nir Geier
*
* Usage:
* Load as many users as you need, then open console and paste this script in teh console.
* Once the script finished executing you will be see blank members page, reload the next
* page and start the process again.
*
* !!! Important
* Sometimes after opening teh confirm dialog the page look "freeze" for a while
* Its OK and it takes time to remove all users.
*
* If the page doen not return the members list page after few minutes, refresh the page and execute the script again
*/
var FBClearGroup = function() {
// Get all the Admins settings buttons
var memberSettings, removeLinks, timer;
/**
* This function will click on all the uses admin settings buttons to add the remove link to the page dom
*/
function exposeRemoveLinks() {
memberSettings = Array.prototype.slice.call(document.querySelectorAll('.adminActions [role="button"]'));
// Expose all the remove users links
memberSettings.forEach(function(item) {
item.click();
});
// continue with the delete flow
timer = setTimeout(openRemoveDialog, 1000);
}
/**
* This function will display the remove dialog
*/
function openRemoveDialog() {
clearTimeout(timer);
// Grab all the remove links
removeLinks = Array.prototype.slice.call(document.querySelectorAll("a[href*='remove.php']"));
// Verify that the previous step has completed
// The -1 is the number of the admins in the gorup.
if (removeLinks.length < memberSettings.length-1) {
// wait for previous step to complete
timer = setTimeout(openRemoveDialog, 1000);
} else {
// Open all the remove dialog
removeLinks.forEach(function(item) {
item.click();
});
// delete the users
timer = setTimeout(removeUsers, 1000);
}
}
/**
* This method will click on the remove user and will remove the user form group
*/
function removeUsers() {
// Grab all the confirm buttons
var confirmButton = Array.prototype.slice.call(document.querySelectorAll('.layerConfirm.uiOverlayButton[type="submit"]'));
// Verify that the previous step has completed
if (confirmButton.length < memberSettings.length) {
timer = setTimeout(removeUsers, 1000);
} else {
// Click on the remove confirm button
confirmButton.forEach(function(item) {
item.click();
});
}
}
exposeRemoveLinks();
}();
@L0garithmic
Copy link

Thanks a ton for this, works perfectly!

@TheMultiYoshi
Copy link

The script opens all the 'Remove?' dialogs just fine, but it doesn't seem to be selecting the Confirm buttons. Update please?

@Copyright09
Copy link

TheMultiYoshi, I have also faced the same problems you.

@Yukihana
Copy link

Great code, but having removeUsers(){} run on timer inside a try-catch block without confirmation of completion of the previous step would actually help clean memory alongside open up new links.
otherwise it would only bloat up the web UI with confirmations till it's finally done selecting.

@rafa-munoz
Copy link

Your code is not working at the moment maybe because Facebook changes. I forked your code with a solution that is working for me:
https://gist.github.com/Menda/c9ce5745105a3548fe41

@kencarino
Copy link

Above solutions doesn't work as of the moment. I forked your code to make the solution working:
https://gist.github.com/kencarino/3be7c5ee0bec39da99a05639c0fc2673

@poohgoil
Copy link

poohgoil commented Sep 12, 2018

@kencarino, your solution isn't working for me anymore, either. :(

@nikhil455
Copy link

not working as of 25 may 2019. please update it. thanks :)

@crisdelcasp1098
Copy link

new script?????

@crisdelcasp1098
Copy link

??

@AlessandroGIovannoli
Copy link

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

@skphantom
Copy link

Hello thank you for this.
Can you customize the script we can delete only the inactive facebook group members?
Cheers

@skphantom
Copy link

Above solutions doesn't work as of the moment. I forked your code to make the solution working:
https://gist.github.com/kencarino/3be7c5ee0bec39da99a05639c0fc2673

Hello Kencarino, would you be able to adapt the code in unavailable member section of a group, all the disabled members can be deleted automatically? I would be happy to give you some money for that.

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