Facebook
From Unique Panda, 2 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 2458
  1. openFollowersWindow().then(function () {
  2.  
  3.     populateUnfollowsPool();
  4.  
  5.     digestUnfollowsPool();
  6.  
  7. });
  8.  
  9. function openFollowersWindow() {
  10.  
  11.     var onFollowersWindowWasOpenedListeners = [];
  12.  
  13.     var openWindowTimeout = 3000;
  14.  
  15.  
  16.  
  17.  
  18.     var followersElement = getFollowersElement();
  19.  
  20.     followersElement.click();
  21.  
  22.  
  23.  
  24.  
  25.     function digestOnFollowersWindowWasOpenedListeners() {
  26.  
  27.         onFollowersWindowWasOpenedListeners.forEach(function (onFollowersWindowWasOpenedListener) {
  28.  
  29.             onFollowersWindowWasOpenedListener();
  30.  
  31.         });
  32.  
  33.     }
  34.  
  35.     var wasOpened;
  36.  
  37.     setTimeout(function () {
  38.  
  39.         // TODO Verify that the window was indeed opened
  40.  
  41.         wasOpened = true;
  42.  
  43.         digestOnFollowersWindowWasOpenedListeners();
  44.  
  45.     }, openWindowTimeout);
  46.  
  47.     return {
  48.  
  49.         then: function (onFollowersWindowWasOpened) {
  50.  
  51.             if (wasOpened) {
  52.  
  53.                 onFollowersWindowWasOpened();
  54.  
  55.             } else {
  56.  
  57.                 onFollowersWindowWasOpenedListeners.push(onFollowersWindowWasOpened);
  58.  
  59.             }
  60.  
  61.         }
  62.  
  63.     };
  64.  
  65. }
  66.  
  67. function getFollowersElement() {
  68.  
  69.     return getFollowersElementWithUsername(getUsername());
  70.  
  71. }
  72.  
  73. function getUsername() {
  74.  
  75.     var pageTitleElement = document.getElementsByTagName('h1')[0];
  76.  
  77.     if (!pageTitleElement) throw new Error('No title to get username from');
  78.  
  79.     return pageTitleElement.innerHTML;
  80.  
  81. }
  82.  
  83. function getFollowersElementWithUsername(username) {
  84.  
  85.     var followersElement = document.querySelectorAll('a[href="/' + username + '/following/"]')[0];
  86.  
  87.     if (!followersElement) throw new Error('No followers element was found');
  88.  
  89.     return followersElement;
  90.  
  91. }
  92.  
  93. var unfollowsPool;
  94.  
  95. function populateUnfollowsPool() {
  96.  
  97.     var buttons = document.getElementsByTagName('button');
  98.  
  99.     unfollowsPool = [];
  100.  
  101.     for (var i = 0; i < buttons.length; i++) {
  102.  
  103.         var button = buttons[i];
  104.  
  105.         if (button.innerHTML.includes('Following')) {
  106.  
  107.             var randomTimeoutForUnfollow = Math.floor((Math.random() * 10) + 1) * 1000;
  108.  
  109.             console.log('Following button!');
  110.  
  111.             var unfollow = {
  112.  
  113.                 buttonElement: button,
  114.  
  115.                 timeout: randomTimeoutForUnfollow
  116.  
  117.             };
  118.  
  119.             unfollowsPool.push(unfollow);
  120.  
  121.         }
  122.  
  123.     }
  124.  
  125. }
  126.  
  127. function digestUnfollowsPool() {
  128.  
  129.     if (unfollowsPool.length === 0) {
  130.  
  131.         console.log('Unfollow pool empty, repopulating');
  132.  
  133.         populateUnfollowsPool();
  134.  
  135.     }
  136.  
  137.     var unfollow = unfollowsPool.shift();
  138.  
  139.     var unfollowTimeout = unfollow.timeout;
  140.  
  141.     console.log('Clicking unfollow button in ', unfollowTimeout);
  142.  
  143.     setTimeout(function () {
  144.  
  145.         var unfollowButtonElement = unfollow.buttonElement;
  146.  
  147.         unfollowButtonElement.scrollIntoView(true);
  148.  
  149.         console.log('Clicking unfollow button');
  150.  
  151.         unfollowButtonElement.click();
  152.  
  153.         console.log('Clicked. Continuing digesting unfollow pool');
  154.  
  155.         digestUnfollowsPool();
  156.  
  157.     }, unfollowTimeout);
  158.  
  159. }

Replies to Untitled rss

Title Name Language When
Re: Untitled Sloppy Parakeet text 1 Month ago.
bugis BURCU BAKIR text 1 Month ago.
Re: Untitled Rude Baboon text 5 Months ago.
Re: Untitled Sexy Cockroach text 7 Months ago.
Re: Untitled Tacky Meerkat text 10 Months ago.
Re: Untitled Sloppy Mousedeer text 1 Year ago.
Re: Untitled Red Panda text 1 Year ago.
Re: Untitled Corrupt Penguin text 1 Year ago.
Re: Untitled Crimson Goose text 1 Year ago.
Re: Untitled Putrid Mosquito text 1 Year ago.
Re: Untitled Smelly Ibis text 1 Year ago.
Added Buton Name language Onur Özkır javascript 1 Year ago.
Re: Untitled Sloppy Crane text 1 Year ago.
Re: Untitled Burly Hamster text 1 Year ago.
Re: Untitled Gracious Cheetah text 1 Year ago.
Re: Untitled Aqua Curlew text 1 Year ago.
Re: Untitled Round Tapir text 1 Year ago.
Re: Untitled dilaraebloc text 2 Years ago.
Re: Untitled dilaraebloc text 2 Years ago.
Re: Untitled Hot Armadillo text 2 Years ago.
Re: Untitled Melodic Hummingbird text 2 Years ago.
Re: Untitled Colorant Madrill text 2 Years ago.
Re: Untitled Burly Guinea Pig text 2 Years ago.
Re: Untitled Beefy Cheetah text 2 Years ago.
Re: Untitled Burly Parakeet text 2 Years ago.
Re: Untitled Violet Capybara text 2 Years ago.