Skip to content

Instantly share code, notes, and snippets.

@maci1011
Last active February 22, 2023 10:52
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save maci1011/30100bc2704f2ae40d3cff93144046ae to your computer and use it in GitHub Desktop.
Facebook js script for removing all group members
// 1 - Go in the group members page and load 200/300 members
// 2 - Paste this in the console and wait
// 3 - Reload the page and do it again
var FBGMR = (function() {
var FBGroupMembersRemover = {},
_id;
var fbIds = ['12345', '67890'], // Put here the ids to jump
menuButtons = [],
links = [],
links_index = 0,
menus_index = 0,
removed_index = 0,
skipped_dialogs = 0,
skipped_buttons = 0,
dialogs_windows = 10,
retry_number = 4,
loaded_menus = 30,
removingLasts = false,
play = false,
tried = 0,
i = 0;
function _guid() {
function s4() {
return Math.floor((1 + Math.random()) * 0x10000)
.toString(16)
.substring(1);
}
return s4() + s4() + s4() + s4() + s4() + s4() + s4() + s4();
}
function checkFBIds(item) {
if (item.getAttribute('href') == null) return true;
fbIds.forEach(function(id) {
if (item.getAttribute('href').indexOf(id) != -1) return true;
});
return false;
}
function getConfirmButtons() {
var confirmButtons = Array.prototype.slice.call(document.querySelectorAll('.layerConfirm.uiOverlayButton[type="submit"]'));
confirmButtons = confirmButtons.filter(function(el) {
return (el.getAttribute('fbgmremover-clicked') != 'clicked');
});
return confirmButtons;
}
function removeItem(item) {
if (item.getAttribute('fbgmremover-clicked') != 'clicked') {
item.setAttribute('fbgmremover-clicked', 'clicked');
item.click();
removed_index++;
console.debug('Removed Users: ' + removed_index);
}
}
function removeLasts() {
if (removingLasts) {
return;
}
console.debug('Start Removing Lasts');
removingLasts = true;
removeLastsLoop();
}
function removeLastsLoop() {
var confirmButtons = getConfirmButtons();
var min = play ? dialogs_windows : 0;
if (confirmButtons.length <= min) {
console.debug('End Removing Lasts');
// console.debug('No More Confirm Buttons.');
removingLasts = false;
return;
}
removeItem(confirmButtons[0]);
setTimeout(function() {
removeLastsLoop();
}, 1000);
}
function removeUsers() {
if (!play) {
removeLasts();
return;
}
loadMenus();
if (!(links_index < menuButtons.length)) {
play = false;
removeLasts();
console.debug('End Removing Users');
FBGroupMembersRemover.debug();
return;
}
openConfirmDialogs();
setTimeout(function() {
var confirmButtons = getConfirmButtons();
if (confirmButtons.length == 0) {
if (tried < retry_number) {
tried++;
removeUsers();
} else if (i < menuButtons.length) {
console.debug('Tring with the next!');
tried = 0;
i++;
removeUsers();
} else {
console.debug('Zero confirmButtons!');
}
return;
}
tried = 0;
removeItem(confirmButtons[0]);
i++;
removeUsers();
if (2 * dialogs_windows < confirmButtons.length) {
removeLasts();
}
}, 2000);
}
function openConfirmDialogs() {
var len = links.length;
links = Array.prototype.slice.call(document.querySelectorAll('a._54nc[href*="remove.php"]'));
if (links.length == 0) {
console.debug('Zero links!');
return;
}
var max = i + dialogs_windows;
max = max < links.length ? max : links.length;
var diff = max - links_index;
if (links_index < links.length && dialogs_windows - 1 < diff) {
console.debug('Opening Confirm Dialogs from ' + links_index + ' to ' + max);
for (var j = links_index; j < max ; j++) {
var item = links[j];
if (item.getAttribute('fbgmremover-id') == _id) {
continue;
}
console.debug(checkFBIds(item));
if (checkFBIds(item)) {
console.debug('Skipped link: ' + j);
// console.debug(item);
skipped_dialogs++;
continue;
}
item.setAttribute('fbgmremover-id',_id);
// console.debug('Loaded link: ' + j);
// console.debug(item);
item.click();
}
links_index = max;
}
}
function loadMenus() {
var len = menuButtons.length;
menuButtons = Array.prototype.slice.call(document.querySelectorAll('button[data-testid*="admin_action_menu_button"]'));
if (menuButtons.length == 0) {
console.debug('Zero menuButtons!');
FBGMR.debug();
return;
}
var max = i + loaded_menus;
max = max < menuButtons.length ? max : menuButtons.length;
var diff = max - menus_index;
if (menus_index < menuButtons.length && loaded_menus - 1 < diff) {
FBGroupMembersRemover.debug();
console.debug('Loading menuButtons from ' + menus_index + ' to ' + max);
for (var j = menus_index; j < max; j++) {
var item = menuButtons[j];
// if (true) {
// console.debug('Skipped menuButtons Index: ' + j);
// console.debug(item);
// skipped_buttons++;
// continue;
//}
//console.debug('click!');
item.click();
}
menus_index = max;
}
}
FBGroupMembersRemover.start = function() {
if (play) {
return;
}
play = true;
setTimeout(function() {
console.debug('Start Removing Users');
removeUsers();
}, 500);
return true;
}
FBGroupMembersRemover.stop = function () {
console.debug('Stopped!');
play = false;
removeLasts();
return true;
}
FBGroupMembersRemover.debug = function() {
var dbg;
console.debug('Length of menuButtons: ' + menuButtons.length);
console.debug('Length of links: ' + links.length);
dbg = Array.prototype.slice.call(document.querySelectorAll('button[data-testid*="admin_action_menu_button"]'));
console.debug('Current Length of menuButtons: ' + dbg.length);
dbg = Array.prototype.slice.call(document.querySelectorAll('a._54nc[href*="remove.php"]'));
console.debug('Current Length of links: ' + dbg.length);
dbg = getConfirmButtons();
console.debug('Current Length of confirmButtons: ' + dbg.length);
console.debug('Is Playing: ' + play);
console.debug('Is Removing Lasts: ' + removingLasts);
console.debug('Skipped Dialogs: ' + skipped_dialogs);
console.debug('Skipped Buttons: ' + skipped_buttons);
console.debug('Tried: ' + tried);
console.debug('Links Index: ' + links_index);
console.debug('Index: ' + i);
return true;
}
_id = _guid();
return FBGroupMembersRemover;
})();
FBGMR.start();
// FBGMR.debug();
// FBGMR.stop();
@FedericoHeichou
Copy link

Alla riga 220 ti è partita una "((" invece di "//"

Comunque a me (chrome) non funziona molto bene, se clicco manualmente sui "..." vicino all'utente e faccio "Rimuovi dal gruppo" lo script fa automaticamente la conferma, però per l'appunto devo manualmente cliccare io sui pallini e fare il "rimuovi", non lo fa da solo. A te funziona?

@MarkAlmarez
Copy link

WHY WE ARE

@KristerV
Copy link

KristerV commented Jan 1, 2018

Uncaught SyntaxError: Unexpected token continue

Looked in the code and there's a "continue" in a function. No loop to "continue".

@fatimaburke
Copy link

Remember to correctly comment out line 220.

@maci1011
Copy link
Author

Just corrected the line 220

...I used it in firefox, don't tested in other browsers

@sjenny
Copy link

sjenny commented Jan 24, 2018

Will this also remove admins? (I don’t want it to remove me and 2 other people.)

@djtrillian
Copy link

djtrillian commented Feb 12, 2018

I am getting what appears to be an error message (and no members are being deleted): (this is in Firefox, does not seem to do anything in Chrome)
Start Removing Users debugger eval code:239:10
Zero links!
debugger eval code:162:10
Tring with the next! debugger eval code:130:12
Zero links!

@mikez2333
Copy link

mikez2333 commented Feb 22, 2023

"Put here the ids to jump"

What??????

@KristerV
Copy link

KristerV commented Feb 22, 2023 via email

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