Fake bot

auto send fake

  1. // ==UserScript==
  2. // @name Fake bot
  3. // @version 1.7
  4. // @include https://*/game.php*screen=place*
  5. // @namespace https://greasyfork.org/users/1388863
  6. // @description auto send fake
  7. // ==/UserScript==
  8.  
  9. (function() {
  10. 'use strict';
  11.  
  12. // Create Start/Stop button
  13. const startStopButton = document.createElement('button');
  14. startStopButton.textContent = 'Start';
  15. startStopButton.style.position = 'fixed';
  16. startStopButton.style.bottom = '20px';
  17. startStopButton.style.right = '20px';
  18. startStopButton.style.padding = '10px 20px';
  19. startStopButton.style.fontSize = '16px';
  20. startStopButton.style.backgroundColor = '#4CAF50';
  21. startStopButton.style.color = 'white';
  22. startStopButton.style.border = 'none';
  23. startStopButton.style.borderRadius = '5px';
  24. startStopButton.style.cursor = 'pointer';
  25. startStopButton.style.zIndex = '9999';
  26. document.body.appendChild(startStopButton);
  27.  
  28. // Create Loop Count button (for setting the number of loops)
  29. const loopButton = document.createElement('button');
  30. loopButton.textContent = 'Set Loops';
  31. loopButton.style.position = 'fixed';
  32. loopButton.style.bottom = '20px';
  33. loopButton.style.right = '120px'; // Adjusted position for spacing
  34. loopButton.style.padding = '10px 20px';
  35. loopButton.style.fontSize = '16px';
  36. loopButton.style.backgroundColor = '#FF9800';
  37. loopButton.style.color = 'white';
  38. loopButton.style.border = 'none';
  39. loopButton.style.borderRadius = '5px';
  40. loopButton.style.cursor = 'pointer';
  41. loopButton.style.zIndex = '9999';
  42. document.body.appendChild(loopButton);
  43.  
  44. // Create remaining loop counter display
  45. const loopCounterDisplay = document.createElement('div');
  46. loopCounterDisplay.style.position = 'fixed';
  47. loopCounterDisplay.style.bottom = '70px';
  48. loopCounterDisplay.style.right = '20px';
  49. loopCounterDisplay.style.fontSize = '18px';
  50. loopCounterDisplay.style.color = 'white';
  51. loopCounterDisplay.style.zIndex = '9999';
  52. loopCounterDisplay.textContent = 'Remaining Loops: 0';
  53. document.body.appendChild(loopCounterDisplay);
  54.  
  55. // Retrieve the last state from localStorage (Start or Stop)
  56. let isRunning = localStorage.getItem('botState') === 'running';
  57. let remainingLoops = parseFloat(localStorage.getItem('remainingLoops'), 10) || 0;
  58. let loops = parseInt(localStorage.getItem('loops'), 10) || 0;
  59.  
  60. // Set initial button and loop counter state based on localStorage
  61. startStopButton.textContent = isRunning ? 'Stop' : 'Start';
  62. loopCounterDisplay.textContent = `Remaining Loops: ${remainingLoops}`;
  63.  
  64. // If bot is running, start it automatically when the page loads
  65. if (isRunning) {
  66. startBot();
  67. }
  68.  
  69. // Function to toggle the script on/off
  70. startStopButton.addEventListener('click', () => {
  71. if (isRunning) {
  72. stopBot();
  73. } else {
  74. startBot();
  75. }
  76. });
  77.  
  78. // Loop button click event to set the number of loops
  79. loopButton.addEventListener('click', () => {
  80. const loopsInput = parseInt(prompt("Enter the number of loops to run:", remainingLoops), 10);
  81. if (!isNaN(loopsInput) && loopsInput > 0) {
  82. remainingLoops = loopsInput; // Double the entered loops * 2
  83. // loops = loopsInput;
  84. localStorage.setItem('remainingLoops', remainingLoops);
  85. // localStorage.setItem('loops', loops);
  86. loopCounterDisplay.textContent = `Remaining Loops: ${remainingLoops}`;
  87. console.log(`Set loops to: ${remainingLoops}`);
  88. }
  89. });
  90.  
  91. function startBot() {
  92. // Set the bot as running in localStorage
  93. isRunning = true;
  94. localStorage.setItem('botState', 'running');
  95. startStopButton.textContent = 'Stop';
  96. console.log("Bot started");
  97.  
  98. // Start the loop process
  99. loopCounterDisplay.textContent = `Remaining Loops: ${remainingLoops}`;
  100. runBotLoop();
  101. }
  102.  
  103. function stopBot() {
  104. // Set the bot as stopped in localStorage
  105. isRunning = false;
  106. localStorage.setItem('botState', 'stopped');
  107. startStopButton.textContent = 'Start';
  108. console.log("Bot stopped");
  109. }
  110.  
  111. function runBotLoop() {
  112. if (remainingLoops > 0) {
  113. // Dispatch '0' key event unless URL contains &screen=place&try=confirm
  114. if (!window.location.href.includes("&screen=place&try=confirm")) {
  115. setTimeout(() => {
  116. // Simulate pressing the '0' key
  117. document.dispatchEvent(new KeyboardEvent('keydown', {
  118. key: '0', code: 'Digit0', keyCode: 48, which: 48, bubbles: true
  119. }));
  120. console.log("Key '0' pressed.");
  121.  
  122. // Wait 500ms - 1 second, then click the 'target_attack' element
  123. setTimeout(() => {
  124. const attackButton = document.getElementById("target_attack");
  125. if (attackButton) {
  126. attackButton.click();
  127. console.log("Clicked target_attack button.");
  128. } else {
  129. console.log("Button with ID 'target_attack' not found.");
  130. }
  131. }, 2000 + Math.random() * 1000); // Random delay between 500-1000ms
  132. }, 500 + Math.random() * 1000); // Random delay between 100-250ms
  133. }
  134.  
  135. // Handle URL-specific actions
  136. setTimeout(() => {
  137. const url = window.location.href;
  138. if (url.includes("&screen=place&try=confirm")) {
  139. console.log("Detected &screen=place&try=confirm");
  140. setTimeout(() => clickButton('#troop_confirm_submit', Math.random() * 300 + 500), 100);
  141. remainingLoops -= 1;
  142. loops -= 1;
  143. localStorage.setItem('remainingLoops', remainingLoops);
  144. localStorage.setItem('loops', loops);
  145. loopCounterDisplay.textContent = `Remaining Loops: ${remainingLoops.toFixed(1)}`;
  146. console.log("Sent confirmation");
  147. } else {
  148. console.log("No matching URL condition");
  149. checkTroopCount(() => {
  150. console.log("Troop count sufficient. Proceeding...");
  151. clickButton('#target_attack', Math.random() * 500 + 800);
  152. });
  153. }
  154.  
  155. // Continue the loop if there are remaining loops
  156. if (remainingLoops > 0) {
  157. runBotLoop();
  158. } else {
  159. stopBot(); // Stop the bot if no loops are left
  160. }
  161. }, 1000 + Math.random() * 1000);
  162. }
  163. }
  164.  
  165. // Function to check troop count
  166. function checkTroopCount(callback) {
  167. setTimeout(() => {
  168. const RAM = document.getElementById('unit_input_ram');
  169. if (RAM && parseInt(RAM.value, 10) > 0) {
  170. callback();
  171. } else {
  172. setTimeout(() => checkTroopCount(callback), 200);
  173. }
  174. }, 100 + Math.random() * 100);
  175. }
  176.  
  177. // Function to click a button after a delay
  178. function clickButton(selector, delay) {
  179. const button = document.querySelector(selector);
  180. if (button) {
  181. setTimeout(() => button.click(), delay);
  182. console.log(`Button clicked after ${delay}ms`);
  183. } else {
  184. console.log("Button not found!");
  185. }
  186. }
  187.  
  188. })();