Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rafa-munoz/c9ce5745105a3548fe41 to your computer and use it in GitHub Desktop.
Save rafa-munoz/c9ce5745105a3548fe41 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 window will reload when it's finished
/**
* This script will remove all group members displayed.
*
* @author: Nir Geier
*
* Usage:
* Load as many users as you need, then open console and paste this script in the
* console.
*
* Once the script finished executing, the page will autoreload.
*
* If looking the console doesn't give any feedback of what's happening, reload the
* page and repeat again. Take into account that it will delete one user per second,
* so it may take a while.
*/
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 except the first one, which is the admin
console.debug('Getting all remove links...')
var i = 0;
memberSettings.forEach(function(item) {
i = i + 1;
if (i == 1) {
return;
}
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']"));
removeLinks.forEach(function(item) {
item.click();
});
// Remove 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 + 1 < memberSettings.length) {
timer = setTimeout(removeUsers, 1000);
} else {
// Click on the remove confirm button
console.debug('Starting removing users')
var i = 1;
confirmButton.forEach(function(item) {
setTimeout(function() {
item.click();
console.debug('Removed user');
}, i * 1000);
i = i + 1;
});
// Reload the page after everything is finished + 7 seconds
setTimeout(function() {
window.location.reload(false);
}, (i + 7) * 1000);
}
}
exposeRemoveLinks();
}();
Copy link

ghost commented Jun 10, 2017

Hi, having a problem. It only seems to delete a single user?

@kerenbe4
Copy link

kerenbe4 commented Mar 10, 2018

Hi man!
Thanks a lot for this one!!
I hade to change 2 selectors, maybe due to ui changes, after that worked like a charm. Forked it up here:
https://gist.github.com/kerenbe4/a4117b2d560bd54af466f0e4991b1526

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