Twitter Auto-Blocker (With Counter)

Auto-blocks users on Twitter.com with a START/STOP button and an accurate visual counter.

  1. // ==UserScript==
  2. // @name Twitter Auto-Blocker (With Counter)
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.3
  5. // @description Auto-blocks users on Twitter.com with a START/STOP button and an accurate visual counter.
  6. // @author Rue
  7. // @match https://twitter.com/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (async () => {
  12. // Configuration
  13. const maxBlocks = 500;
  14. const delayRange = [100, 200]; // Random delay range in milliseconds
  15. const clickDelayRange = [20, 40]; // Random click delay range in milliseconds
  16.  
  17. // Variables
  18. let totalBlocked = 0;
  19. let isRunning = false;
  20.  
  21. // UI Elements
  22. const counterElement = document.createElement('div');
  23. counterElement.style.position = 'fixed';
  24. counterElement.style.top = '10px';
  25. counterElement.style.right = '10px';
  26. counterElement.style.backgroundColor = 'white';
  27. counterElement.style.padding = '20px';
  28. counterElement.style.borderRadius = '5px';
  29. counterElement.style.fontSize = '36px';
  30. counterElement.style.fontWeight = 'bold';
  31. counterElement.style.color = 'red';
  32. counterElement.textContent = `Blocked: ${totalBlocked}`;
  33. document.body.appendChild(counterElement);
  34.  
  35. const startStopButton = document.createElement('button');
  36. startStopButton.style.position = 'fixed';
  37. startStopButton.style.top = '80px';
  38. startStopButton.style.left = '10px';
  39. startStopButton.style.backgroundColor = 'green';
  40. startStopButton.style.color = 'white';
  41. startStopButton.style.padding = '10px';
  42. startStopButton.style.borderRadius = '5px';
  43. startStopButton.style.fontSize = '18px';
  44. startStopButton.textContent = 'Start';
  45. startStopButton.addEventListener('click', () => {
  46. isRunning = !isRunning;
  47. startStopButton.textContent = isRunning ? 'Stop' : 'Start';
  48. if (isRunning) {
  49. autoBlockUsers();
  50. } else {
  51. alert(`Stopped auto-blocking. ${totalBlocked} users blocked.`);
  52. }
  53. });
  54. document.body.appendChild(startStopButton);
  55.  
  56. // Functions
  57. async function delay(ms) {
  58. await new Promise(resolve => {
  59. setTimeout(() => {
  60. resolve();
  61. }, Math.floor(ms + Math.random() * (delayRange[1] - delayRange[0])));
  62. });
  63. }
  64.  
  65. async function scrollDown() {
  66. await new Promise(resolve => {
  67. let start = performance.now();
  68. let scrollInterval = setInterval(() => {
  69. let timePassed = performance.now() - start;
  70. if (timePassed > 1000) {
  71. clearInterval(scrollInterval);
  72. resolve();
  73. } else {
  74. window.scrollBy(0, 9 + Math.floor(Math.random() * 3));
  75. }
  76. }, 10);
  77. });
  78. }
  79.  
  80. async function autoBlockUsers() {
  81. while (isRunning && totalBlocked < maxBlocks) {
  82. let users = document.querySelectorAll('div[data-testid="UserCell"]');
  83. let count = users.length;
  84. let blockedCount = 0;
  85. for (let user of users) {
  86. if (user.querySelector('div[data-testid$="-unblock"]')) continue;
  87. user.click();
  88. await delay(clickDelayRange[0] + Math.random() * (clickDelayRange[1] - clickDelayRange[0]));
  89. let unblockConfirmation = document.querySelector("[data-testid=userActions]");
  90. if (!unblockConfirmation) continue;
  91. unblockConfirmation.click();
  92. await delay(clickDelayRange[0] + Math.random() * (clickDelayRange[1] - clickDelayRange[0]));
  93. let blockButton = document.querySelector("[data-testid=block]");
  94. if (blockButton) {
  95. blockButton.click();
  96. await delay(clickDelayRange[0] + Math.random() * (clickDelayRange[1] - clickDelayRange[0]));
  97. let confirmButton = document.querySelector("[data-testid=confirmationSheetConfirm]");
  98. if (confirmButton) {
  99. confirmButton.click();
  100. await delay(clickDelayRange[0] + Math.random() * (clickDelayRange[1] - clickDelayRange[0]));
  101. let backButton = document.querySelector("[data-testid=app-bar-back]");
  102. if (backButton) {
  103. backButton.click();
  104. await delay(clickDelayRange[0] + Math.random() * (clickDelayRange[1] - clickDelayRange[0]));
  105. blockedCount++; // Increment blocked count only if block was successful
  106. }
  107. }
  108. }
  109. }
  110. await scrollDown();
  111. console.log(`Blocked ${blockedCount} users. Total blocked: ${totalBlocked + blockedCount}`);
  112. totalBlocked += blockedCount;
  113. counterElement.textContent = `Blocked: ${totalBlocked}`;
  114.  
  115. if (totalBlocked >= maxBlocks) {
  116. isRunning = false;
  117. startStopButton.textContent = 'Start';
  118. alert(`Maximum block limit of ${maxBlocks} reached.`);
  119. }
  120. }
  121. }
  122. })();