Iklan Billboard 970x250

Code Dell All Members Group

Code Dell All Members Group

  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.  
  10.     deleteAllGroupMembers.start = function() {
  11.         scriptEnabled = true;
  12.         deleteAll();
  13.     };
  14.     deleteAllGroupMembers.stop = function() {
  15.         scriptEnabled = false;
  16.     };
  17.  
  18.     function deleteAll() {
  19.         if (scriptEnabled) {
  20.             queueMembersToDelete();
  21.             processQueue();
  22.         }
  23.     }
  24.  
  25.     function queueMembersToDelete() {
  26.         var adminActions = document.getElementsByClassName('adminActions');
  27.         console.log(excludedFbIds);
  28.         for(var i=0; i<adminActions.length; i++) {
  29.             var gearWheelIconDiv = adminActions[i];
  30.             var hyperlinksInAdminDialog = gearWheelIconDiv.getElementsByTagName('a');
  31.             var fbMemberId = gearWheelIconDiv.parentNode.parentNode.id.replace('member_','');
  32.             var fbMemberName = getTextFromElement(gearWheelIconDiv.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.getElementsByClassName('fcb')[0]);
  33.  
  34.             if (excludedFbIds.indexOf(fbMemberId) != -1) {
  35.                 console.log("SKIPPING "+fbMemberName+' ('+fbMemberId+')');
  36.                 continue;
  37.             } else {
  38.                 usersToDeleteQueue.push({'memberId': fbMemberId, 'gearWheelIconDiv': gearWheelIconDiv});
  39.             }
  40.         }
  41.     }
  42.  
  43.     function processQueue() {
  44.         if (!scriptEnabled) {
  45.             return;
  46.         }
  47.         if (usersToDeleteQueue.length > 0) {
  48.             removeNext();
  49.  
  50.             setTimeout(function(){
  51.                 processQueue();
  52.             },1000);
  53.         } else {
  54.             getMore();
  55.         }
  56.     }
  57.  
  58.     function removeNext() {
  59.         if (!scriptEnabled) {
  60.             return;
  61.         }
  62.         if (usersToDeleteQueue.length > 0) {
  63.             var nextElement = usersToDeleteQueue.pop();
  64.             removeMember(nextElement.memberId, nextElement.gearWheelIconDiv);
  65.         }
  66.     }
  67.  
  68.     function removeMember(memberId, gearWheelIconDiv) {
  69.         if (processing) {
  70.             return;
  71.         }
  72.         var gearWheelHref = gearWheelIconDiv.getElementsByTagName('a')[0];
  73.         gearWheelHref.click();
  74.         processing = true;
  75.         setTimeout(function(){
  76.             var popupRef = gearWheelHref.id;
  77.             var popupDiv = getElementByAttribute('data-ownerid',popupRef);
  78.             var popupLinks = popupDiv.getElementsByTagName('a');
  79.             for(var j=0; j<popupLinks.length; j++) {
  80.                 if (popupLinks[j].getAttribute('href').indexOf('remove.php') !== -1) {
  81.                     // this is the remove link
  82.                     popupLinks[j].click();
  83.                     setTimeout(function(){
  84.                         var confirmButton = document.getElementsByClassName('layerConfirm uiOverlayButton selected')[0];
  85.                         var errorDialog = getElementByAttribute('data-reactid','.4.0');
  86.                         if (confirmButton != null) {
  87.                             if (canClick(confirmButton)) {
  88.                                 confirmButton.click();
  89.                             } else {
  90.                                 console.log('This should not happen memberid: '+memberId);
  91.                                 5/0;
  92.                                 console.log(gearWheelIconDiv);
  93.                             }
  94.                         }
  95.                         if (errorDialog != null) {
  96.                             console.log("Error while removing member "+memberId);
  97.                             errorDialog.getElementsByClassName('selected  layerCancel autofocus')[0].click();
  98.                         } 
  99.                         processing = false;
  100.                     },700);
  101.                     continue;
  102.                 }
  103.             }
  104.         },500);
  105.     }
  106.  
  107.     function canClick(el) {
  108.         return (typeof el != 'undefined') && (typeof el.click != 'undefined');
  109.     }
  110.  
  111.     function getMore() {
  112.         processing = true;
  113.         more = document.getElementsByClassName("pam uiBoxLightblue  uiMorePagerPrimary");
  114.         if (typeof more != 'undefined' && canClick(more[0])) {
  115.             more[0].click();
  116.             setTimeout(function(){
  117.                 deleteAll();
  118.                 processing = false;
  119.            }, 2000);
  120.         } else {
  121.             deleteAllGroupMembers.stop();
  122.         }
  123.     }
  124.  
  125.     function getTextFromElement(element) {
  126.         var text = element.textContent;
  127.         return text;
  128.     }
  129.  
  130.     function getElementByAttribute(attr, value, root) {
  131.         root = root || document.body;
  132.         if(root.hasAttribute(attr) && root.getAttribute(attr) == value) {
  133.             return root;
  134.         }
  135.         var children = root.children,
  136.             element;
  137.         for(var i = children.length; i--; ) {
  138.             element = getElementByAttribute(attr, value, children[i]);
  139.             if(element) {
  140.                 return element;
  141.             }
  142.         }
  143.         return null;
  144.     }
  145.     return deleteAllGroupMembers;
  146. })();
  147. deleteAllGroupMembers.start();
  148.  
  149. // stop the script by entering this in the console: deleteAllGroupMembers.stop();
Baca Juga
SHARE
Subscribe to get free updates

Related Posts

Đăng nhận xét

Iklan Tengah Post