Fake bot V2

Change villa every iteration

  1. // ==UserScript==
  2. // @name Fake bot V2
  3. // @version 1.5
  4. // @description Change villa every iteration
  5. // @include https://*/game.php*screen=place*
  6. // @namespace https://greasyfork.org/users/1388863
  7. // ==/UserScript==
  8.  
  9. (function() {
  10. 'use strict';
  11.  
  12. const container = document.createElement('div');
  13. container.style.position = 'fixed';
  14. container.style.bottom = '20px';
  15. container.style.right = '20px';
  16. container.style.backgroundColor = '#333';
  17. container.style.color = '#fff';
  18. container.style.padding = '8px';
  19. container.style.borderRadius = '5px';
  20. container.style.zIndex = '10000';
  21. container.style.boxShadow = '0 4px 8px rgba(0, 0, 0, 0.2)';
  22. container.style.display = 'flex';
  23. container.style.flexDirection = 'column';
  24. container.style.gap = '10px';
  25. document.body.appendChild(container);
  26.  
  27. // Remaining loops display
  28. const loopCounterDisplay = document.createElement('div');
  29. loopCounterDisplay.style.fontSize = '14px'; // Smaller text size
  30. loopCounterDisplay.style.textAlign = 'center';
  31. loopCounterDisplay.textContent = 'Remaining Loops: 0';
  32. container.appendChild(loopCounterDisplay);
  33.  
  34. // Create a flex container for buttons to be side by side
  35. const buttonContainer = document.createElement('div');
  36. buttonContainer.style.display = 'flex';
  37. buttonContainer.style.gap = '10px'; // Add space between buttons
  38. buttonContainer.style.width = '100%'; // Ensure the container spans the full width
  39. container.appendChild(buttonContainer);
  40.  
  41. // Start/Stop button
  42. const startStopButton = document.createElement('button');
  43. startStopButton.textContent = 'Start';
  44. startStopButton.style.padding = '5px 8px'; // Smaller padding
  45. startStopButton.style.fontSize = '14px'; // Smaller font size
  46. startStopButton.style.backgroundColor = '#4CAF50';
  47. startStopButton.style.color = '#fff';
  48. startStopButton.style.border = 'none';
  49. startStopButton.style.borderRadius = '3px';
  50. startStopButton.style.cursor = 'pointer';
  51. startStopButton.style.flex = '1'; // Allow button to take equal space
  52. buttonContainer.appendChild(startStopButton);
  53.  
  54. // Set Loops button
  55. const loopButton = document.createElement('button');
  56. loopButton.textContent = 'Set';
  57. loopButton.style.padding = '5px 8px'; // Smaller padding
  58. loopButton.style.fontSize = '14px'; // Smaller font size
  59. loopButton.style.backgroundColor = '#FF9800';
  60. loopButton.style.color = '#fff';
  61. loopButton.style.border = 'none';
  62. loopButton.style.borderRadius = '3px';
  63. loopButton.style.cursor = 'pointer';
  64. loopButton.style.flex = '1'; // Allow button to take equal space
  65. buttonContainer.appendChild(loopButton);
  66.  
  67. // Retrieve the last state from localStorage
  68. let isRunning = localStorage.getItem('botState') === 'running';
  69. let remainingLoops = parseFloat(localStorage.getItem('remainingLoops')) || 0;
  70. let currentloop = parseFloat(localStorage.getItem('currentloop')) || remainingLoops;
  71.  
  72. // Set initial button and loop counter state
  73. startStopButton.textContent = isRunning ? 'Stop' : 'Start';
  74. loopCounterDisplay.textContent = `Remaining Loops: ${remainingLoops}`;
  75.  
  76. // Start the bot if it was running
  77. if (isRunning) {
  78. startBot();
  79. }
  80.  
  81. // Start/Stop button event
  82. startStopButton.addEventListener('click', () => {
  83. if (isRunning) {
  84. stopBot();
  85. } else {
  86. startBot();
  87. }
  88. });
  89.  
  90. // Loop button event
  91. loopButton.addEventListener('click', () => {
  92. const loopsInput = parseInt(prompt("Enter the number of loops to run:", remainingLoops), 10);
  93. if (!isNaN(loopsInput) && loopsInput > 0) {
  94. remainingLoops = loopsInput;
  95. currentloop = remainingLoops;
  96. localStorage.setItem('remainingLoops', remainingLoops);
  97. localStorage.setItem('currentloop', currentloop);
  98. loopCounterDisplay.textContent = `Remaining Loops: ${remainingLoops}`;
  99. console.log(`Set loops to: ${remainingLoops}`);
  100. }
  101. });
  102.  
  103. function startBot() {
  104. isRunning = true;
  105. localStorage.setItem('botState', 'running');
  106. startStopButton.textContent = 'Stop';
  107. console.log("Bot started");
  108. loopCounterDisplay.textContent = `Remaining Loops: ${remainingLoops}`;
  109. runBotLoop();
  110. }
  111.  
  112. function stopBot() {
  113. isRunning = false;
  114. localStorage.setItem('botState', 'stopped');
  115. startStopButton.textContent = 'Start';
  116. console.log("Bot stopped");
  117. }
  118.  
  119. function runBotLoop() {
  120. if (remainingLoops > 0) {
  121. if (!window.location.href.includes("&screen=place&try=confirm")) {
  122. if (currentloop !== remainingLoops) {
  123. setTimeout(() => {
  124. clickKeyD(() => {
  125. console.log("Clicked key 'D' and resuming...");
  126. });
  127. currentloop = remainingLoops;
  128. localStorage.setItem('currentloop', currentloop);
  129. }, 300 + Math.random() * 200);
  130. }
  131. setTimeout(() => {
  132. document.dispatchEvent(new KeyboardEvent('keydown', {
  133. key: '0', code: 'Digit0', keyCode: 48, which: 48, bubbles: true
  134. }));
  135. console.log("Key '0' pressed.");
  136.  
  137. checkAndClickButton();
  138. }, 1200 + Math.random() * 300);
  139. }
  140.  
  141. setTimeout(() => {
  142. const url = window.location.href;
  143. if (url.includes("&screen=place&try=confirm")) {
  144. const confirmButton = document.querySelector('#troop_confirm_submit');
  145. if (confirmButton) {
  146. console.log("Detected &screen=place&try=confirm and #troop_confirm_submit exists");
  147. // setTimeout(()=> clickButton('#troop_confirm_submit', Math.random() * 100 + 100), 100);
  148. setTimeout(() => {
  149. clickButton('#troop_confirm_submit')
  150. }, 200 + Math.random() * 100);
  151. remainingLoops -= 1;
  152. localStorage.setItem('remainingLoops', remainingLoops);
  153. localStorage.setItem('currentloop', currentloop);
  154. loopCounterDisplay.textContent = `Remaining Loops: ${remainingLoops}`;
  155. console.log("Sent confirmation");
  156. } else {
  157. // const newUrl = url.replace("&try=confirm", "");
  158. // window.location.href = newUrl;
  159. currentloop -= 1;
  160. localStorage.setItem('currentloop', currentloop);
  161. const newUrl = url.replace(/(&screen=place).*$/, "$1");
  162. window.location.href = newUrl;
  163.  
  164. }
  165. }
  166.  
  167. if (remainingLoops > 0) {
  168. runBotLoop();
  169. } else {
  170. stopBot();
  171. }
  172. }, 1000 + Math.random() * 300);
  173. }
  174. }
  175.  
  176. function clickKeyD(callback) {
  177. setTimeout(() => {
  178. document.dispatchEvent(new KeyboardEvent('keydown', {
  179. key: 'D', code: 'KeyD', keyCode: 68, which: 68, bubbles: true
  180. }));
  181. console.log("Key 'D' pressed.");
  182. if (callback) callback();
  183. }, Math.random() * 200 + 100);
  184. }
  185.  
  186.  
  187. function clickButton(selector) {
  188. const button = document.querySelector(selector);
  189. if (button) {
  190. console.log(`Button clicked`);
  191. button.click()
  192. } else {
  193. console.log("Button not found!");
  194. }
  195. }
  196.  
  197. function checkAndClickButton() {
  198. var inputElement = document.querySelector('.target-input-field');
  199.  
  200. // Check if the input element has display: none;
  201. if (inputElement.style.display === 'none') {
  202. console.log('The input element has display: none;');
  203.  
  204. // Run the script to click the attack button
  205. setTimeout(() => {
  206. const attackButton = document.getElementById("target_attack");
  207. if (attackButton) {
  208. attackButton.click();
  209. console.log("Clicked target_attack button.");
  210. } else {
  211. console.log("Button with ID 'target_attack' not found.");
  212. }
  213. }, 300 + Math.random() * 200);
  214. } else {
  215. // If display is not none, wait for it
  216. console.log('Input element does not have display: none; Waiting...');
  217. setTimeout(checkAndClickButton, 50); // Check again after 500ms
  218. }
  219. }
  220.  
  221.  
  222. })();
  223.  
  224.  
  225.  
  226.