Advertisement
hamzajaved

fb-friend-requests-automation

Dec 12th, 2021
1,188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2. * @author Muhammad Hamza
  3. * Usage:
  4. *   Go to https://www.facebook.com/friends/requests/
  5. *   Run the following code
  6. */
  7.  
  8. function acceptRequests (container, mutualThreshold, timerDelay) {
  9.   var rows = container.querySelectorAll('[aria-label="Confirm"]:not([aria-disabled="true"])')
  10.     rows.forEach((row, index) => {
  11.       try {
  12.         if (mutualThreshold > 0) {
  13.           const friendsCountLabel = row.closest('a').querySelector('[aria-labelledby$="friends"]')
  14.           const friendsCount = Number(friendsCountLabel.getAttribute('aria-labelledby').split(' mutual')[0]);
  15.           if (friendsCount < mutualThreshold) {
  16.             return;
  17.           }
  18.         }
  19.         setTimeout(() => {
  20.           row.click();
  21.           if (index === rows.length - 1) {
  22.             container.scrollTop = container.scrollHeight;
  23.           }
  24.         }, index * timerDelay)
  25.       }
  26.       catch (e) {
  27.         console.log(e);
  28.       }
  29.     })
  30. }
  31.  
  32. function acceptAllFriendRequests (containerClass, mutualThreshold = 0, timerDelay = 500) {
  33.   var container = document.querySelectorAll(containerClass);
  34.   container = container[container.length - 1]
  35.   acceptRequests(container, mutualThreshold, timerDelay);
  36.   setInterval(() => {
  37.     acceptRequests(container, mutualThreshold, timerDelay);
  38.   }, 7000)
  39. }
  40.  
  41. /**
  42. * Make sure to pass the correct css selector for the container element of the friend requests row
  43. */
  44. acceptAllFriendRequests('.rpm2j7zs.k7i0oixp.gvuykj2m', 3)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement