Last active
January 15, 2018 19:07
-
-
Save fatimaburke/43341e4201da739a36ebbc8b5f92d3fb to your computer and use it in GitHub Desktop.
Mass Removes Members from your Facebook Group. *Working as of Jan 2018*. In order to delete a group, Facebook requires that the group have no members. So for larger groups, this is definitely needed!
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
// Tweaked version of @michaelv's gist | |
// 1 - Go in the group members page and scroll to load 200/300 members | |
// 2 - Paste this in the console and wait. Be patient between groups of 10 - 30 | |
// 3 - Reload the page and do it again | |
var FBGMR = (function() { | |
var FBGroupMembersRemover = {}, | |
_id; | |
// Place IDs as Strings below for members you don't want to remove (For example Admins) | |
// Find a user's Facebook ID at https://findmyfbid.com/ | |
var fbIds = ['12345', '67890'], | |
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('Begin Removing Last Members'); | |
removingLasts = true; | |
removeLastsLoop(); | |
} | |
function removeLastsLoop() { | |
var confirmButtons = getConfirmButtons(); | |
var min = play ? dialogs_windows : 0; | |
if (confirmButtons.length <= min) { | |
console.debug('Removing Remaining Members Complete'); | |
// 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('Removing Users Completed'); | |
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('Begin 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 Remaining Members: ' + 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(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
All i get is a result that says "true", nothing happens. Did Facebook update again?