Fake bot Change Villa

Change villa every iteration

当前为 2025-01-19 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Fake bot Change Villa
  3. // @version 1
  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. // 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
  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';
  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
  56. let isRunning = localStorage.getItem('botState') === 'running';
  57. let remainingLoops = parseFloat(localStorage.getItem('remainingLoops')) || 0;
  58. let currentloop = parseFloat(localStorage.getItem('currentloop')) || remainingLoops;
  59.  
  60. // Set initial button and loop counter state
  61. startStopButton.textContent = isRunning ? 'Stop' : 'Start';
  62. loopCounterDisplay.textContent = `Remaining Loops: ${remainingLoops}`;
  63.  
  64. // Start the bot if it was running
  65. if (isRunning) {
  66. startBot();
  67. }
  68.  
  69. // Start/Stop button event
  70. startStopButton.addEventListener('click', () => {
  71. if (isRunning) {
  72. stopBot();
  73. } else {
  74. startBot();
  75. }
  76. });
  77.  
  78. // Loop button event
  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;
  83. currentloop = remainingLoops;
  84. localStorage.setItem('remainingLoops', remainingLoops);
  85. localStorage.setItem('currentloop', currentloop);
  86. loopCounterDisplay.textContent = `Remaining Loops: ${remainingLoops}`;
  87. console.log(`Set loops to: ${remainingLoops}`);
  88. }
  89. });
  90.  
  91. function startBot() {
  92. isRunning = true;
  93. localStorage.setItem('botState', 'running');
  94. startStopButton.textContent = 'Stop';
  95. console.log("Bot started");
  96. loopCounterDisplay.textContent = `Remaining Loops: ${remainingLoops}`;
  97. runBotLoop();
  98. }
  99.  
  100. function stopBot() {
  101. isRunning = false;
  102. localStorage.setItem('botState', 'stopped');
  103. startStopButton.textContent = 'Start';
  104. console.log("Bot stopped");
  105. }
  106.  
  107. function runBotLoop() {
  108. if (remainingLoops > 0) {
  109. if (!window.location.href.includes("&screen=place&try=confirm")) {
  110. if (currentloop !== remainingLoops) {
  111. setTimeout(() => {
  112. clickKeyD(() => {
  113. console.log("Clicked key 'D' and resuming...");
  114. });
  115. currentloop = remainingLoops;
  116. localStorage.setItem('currentloop', currentloop);
  117. }, 300 + Math.random() * 200);
  118. }
  119. setTimeout(() => {
  120. document.dispatchEvent(new KeyboardEvent('keydown', {
  121. key: '0', code: 'Digit0', keyCode: 48, which: 48, bubbles: true
  122. }));
  123. console.log("Key '0' pressed.");
  124.  
  125. setTimeout(() => {
  126. const attackButton = document.getElementById("target_attack");
  127. if (attackButton) {
  128. attackButton.click();
  129. console.log("Clicked target_attack button.");
  130. } else {
  131. console.log("Button with ID 'target_attack' not found.");
  132. }
  133. }, 500 + Math.random() * 300);
  134. }, 1000 + Math.random() * 300);
  135. }
  136.  
  137. setTimeout(() => {
  138. const url = window.location.href;
  139. if (url.includes("&screen=place&try=confirm")) {
  140. const confirmButton = document.querySelector('#troop_confirm_submit');
  141. if (confirmButton) {
  142. console.log("Detected &screen=place&try=confirm and #troop_confirm_submit exists");
  143. // setTimeout(()=> clickButton('#troop_confirm_submit', Math.random() * 100 + 100), 100);
  144. setTimeout(() => {
  145. clickButton('#troop_confirm_submit')
  146. }, 200 + Math.random() * 100);
  147. remainingLoops -= 1;
  148. localStorage.setItem('remainingLoops', remainingLoops);
  149. localStorage.setItem('currentloop', currentloop);
  150. loopCounterDisplay.textContent = `Remaining Loops: ${remainingLoops}`;
  151. console.log("Sent confirmation");
  152. } else {
  153. // const newUrl = url.replace("&try=confirm", "");
  154. // window.location.href = newUrl;
  155. currentloop -= 1;
  156. localStorage.setItem('currentloop', currentloop);
  157. const newUrl = url.replace(/(&screen=place).*$/, "$1");
  158. window.location.href = newUrl;
  159.  
  160. }
  161. }
  162.  
  163. if (remainingLoops > 0) {
  164. runBotLoop();
  165. } else {
  166. stopBot();
  167. }
  168. }, 700 + Math.random() * 300);
  169. }
  170. }
  171.  
  172. function clickKeyD(callback) {
  173. setTimeout(() => {
  174. document.dispatchEvent(new KeyboardEvent('keydown', {
  175. key: 'D', code: 'KeyD', keyCode: 68, which: 68, bubbles: true
  176. }));
  177. console.log("Key 'D' pressed.");
  178. if (callback) callback();
  179. }, Math.random() * 200 + 100);
  180. }
  181.  
  182. // function clickButton(selector, delay) {
  183. // const button = document.querySelector(selector);
  184. // if (button) {
  185. // setTimeout(() => button.click(), delay);
  186. // console.log(`Button clicked after ${delay}ms`);
  187. // } else {
  188. // console.log("Button not found!");
  189. // }
  190. // }
  191.  
  192. function clickButton(selector) {
  193. const button = document.querySelector(selector);
  194. if (button) {
  195. console.log(`Button clicked`);
  196. button.click()
  197. } else {
  198. console.log("Button not found!");
  199. }
  200. }
  201.  
  202. })();