SHARE
TWEET

[TricksGalaxy.com] Code to Remove All Members from Facebook

IamAjitRay Apr 21st, 2015 16,447 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var deleteAllGroupMembers = (function () {
  2. var deleteAllGroupMembers = {};
  3. // the facebook ids of the users that will not be removed.
  4. // IMPORTANT: add your own facebook id here so that the script will not remove yourself!
  5. var excludedFbIds = ['1234','11223344']; // make sure each id is a string!
  6. var usersToDeleteQueue = [];
  7. var scriptEnabled = false;
  8. var processing = false;
  9. deleteAllGroupMembers.start = function() {
  10. scriptEnabled = true;
  11. deleteAll();
  12. };
  13. deleteAllGroupMembers.stop = function() {
  14. scriptEnabled = false;
  15. };
  16. function deleteAll() {
  17. if (scriptEnabled) {
  18. queueMembersToDelete();
  19. processQueue();
  20. }
  21. }
  22. function queueMembersToDelete() {
  23. var adminActions = document.getElementsByClassName('adminActions');
  24. console.log(excludedFbIds);
  25. for(var i=0; i<adminActions.length; i++) {
  26. var gearWheelIconDiv = adminActions[i];
  27. var hyperlinksInAdminDialog = gearWheelIconDiv.getElementsByTagName('a');
  28. var fbMemberId = gearWheelIconDiv.parentNode.parentNode.id.replace('member_','');
  29. var fbMemberName = getTextFromElement(gearWheelIconDiv.parentNode.parentNode.getElementsByClassName('fcb')[0]);
  30. if (excludedFbIds.indexOf(fbMemberId) != -1) {
  31. console.log("SKIPPING "+fbMemberName+' ('+fbMemberId+')');
  32. continue;
  33. } else {
  34. usersToDeleteQueue.push({'memberId': fbMemberId, 'gearWheelIconDiv': gearWheelIconDiv});
  35. }
  36. }
  37. }
  38. function processQueue() {
  39. if (!scriptEnabled) {
  40. return;
  41. }
  42. if (usersToDeleteQueue.length > 0) {
  43. removeNext();
  44. setTimeout(function(){
  45. processQueue();
  46. },1000);
  47. } else {
  48. getMore();
  49. }
  50. }
  51. function removeNext() {
  52. if (!scriptEnabled) {
  53. return;
  54. }
  55. if (usersToDeleteQueue.length > 0) {
  56. var nextElement = usersToDeleteQueue.pop();
  57. removeMember(nextElement.memberId, nextElement.gearWheelIconDiv);
  58. }
  59. }
  60. function removeMember(memberId, gearWheelIconDiv) {
  61. if (processing) {
  62. return;
  63. }
  64. var gearWheelHref = gearWheelIconDiv.getElementsByTagName('a')[0];
  65. gearWheelHref.click();
  66. processing = true;
  67. setTimeout(function(){
  68. var popupRef = gearWheelHref.id;
  69. var popupDiv = getElementByAttribute('data-ownerid',popupRef);
  70. var popupLinks = popupDiv.getElementsByTagName('a');
  71. for(var j=0; j<popupLinks.length; j++) {
  72. if (popupLinks[j].getAttribute('href').indexOf('remove.php') !== -1) {
  73. // this is the remove link
  74. popupLinks[j].click();
  75. setTimeout(function(){
  76. var confirmButton = document.getElementsByClassName('layerConfirm uiOverlayButton selected')[0];
  77. var errorDialog = getElementByAttribute('data-reactid','.4.0');
  78. if (confirmButton != null) {
  79. if (canClick(confirmButton)) {
  80. confirmButton.click();
  81. } else {
  82. console.log('This should not happen memberid: '+memberId);
  83. 5/0;
  84. console.log(gearWheelIconDiv);
  85. }
  86. }
  87. if (errorDialog != null) {
  88. console.log("Error while removing member "+memberId);
  89. errorDialog.getElementsByClassName('selected layerCancel autofocus')[0].click();
  90. }
  91. processing = false;
  92. },700);
  93. continue;
  94. }
  95. }
  96. },500);
  97. }
  98. function canClick(el) {
  99. return (typeof el != 'undefined') && (typeof el.click != 'undefined');
  100. }
  101. function getMore() {
  102. processing = true;
  103. more = document.getElementsByClassName("pam uiBoxLightblue uiMorePagerPrimary");
  104. if (typeof more != 'undefined' && canClick(more[0])) {
  105. more[0].click();
  106. setTimeout(function(){
  107. deleteAll();
  108. processing = false;
  109. }, 2000);
  110. } else {
  111. deleteAllGroupMembers.stop();
  112. }
  113. }
  114. function getTextFromElement(element) {
  115. var text = element.textContent;
  116. return text;
  117. }
  118. function getElementByAttribute(attr, value, root) {
  119. root = root || document.body;
  120. if(root.hasAttribute(attr) && root.getAttribute(attr) == value) {
  121. return root;
  122. }
  123. var children = root.children,
  124. element;
  125. for(var i = children.length; i--; ) {
  126. element = getElementByAttribute(attr, value, children[i]);
  127. if(element) {
  128. return element;
  129. }
  130. }
  131. return null;
  132. }
  133. return deleteAllGroupMembers;
  134. })();
  135. deleteAllGroupMembers.start();
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top