ShawnsSpace

Twitter mass unfollow script for console.

May 13th, 2021
643
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (() => {
  2.   const $followButtons = '[data-testid$="-unfollow"]';
  3.   const $confirmButton = '[data-testid="confirmationSheetConfirm"]';
  4.  
  5.   const retry = {
  6.     count: 0,
  7.     limit: 3,
  8.   };
  9.  
  10.   const scrollToTheBottom = () => window.scrollTo(0, document.body.scrollHeight);
  11.   const retryLimitReached = () => retry.count === retry.limit;
  12.   const addNewRetry = () => retry.count++;
  13.  
  14.   const sleep = ({ seconds }) =>
  15.     new Promise((proceed) => {
  16.       console.log(`WAITING FOR ${seconds} SECONDS...`);
  17.       setTimeout(proceed, seconds * 1000);
  18.     });
  19.  
  20.   const unfollowAll = async (followButtons) => {
  21.     console.log(`UNFOLLOWING ${followButtons.length} USERS...`);
  22.     await Promise.all(
  23.       followButtons.map(async (followButton) => {
  24.         followButton && followButton.click();
  25.         await sleep({ seconds: 1 });
  26.         const confirmButton = document.querySelector($confirmButton);
  27.         confirmButton && confirmButton.click();
  28.       })
  29.     );
  30.   };
  31.  
  32.   const nextBatch = async () => {
  33.     scrollToTheBottom();
  34.     await sleep({ seconds: 1 });
  35.  
  36.     const followButtons = Array.from(document.querySelectorAll($followButtons));
  37.     const followButtonsWereFound = followButtons.length > 0;
  38.  
  39.     if (followButtonsWereFound) {
  40.       await unfollowAll(followButtons);
  41.       await sleep({ seconds: 2 });
  42.       return nextBatch();
  43.     } else {
  44.       addNewRetry();
  45.     }
  46.  
  47.     if (retryLimitReached()) {
  48.       console.log(`NO ACCOUNTS FOUND, SO I THINK WE'RE DONE`);
  49.      console.log(`RELOAD PAGE AND RE-RUN SCRIPT IF ANY WERE MISSED`);
  50.    } else {
  51.      await sleep({ seconds: 2 });
  52.      return nextBatch();
  53.    }
  54.  };
  55.  
  56.  nextBatch();
  57. })();
RAW Paste Data