Autofarm V2

Farmgod and send attack automatically at Loot Assistant at random intervals

目前为 2024-11-13 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Autofarm V2
  3. // @version 2.1
  4. // @include https://*/game.php*screen=am_farm*
  5. // @namespace https://greasyfork.org/users/1388863
  6. // @description Farmgod and send attack automatically at Loot Assistant at random intervals
  7. // ==/UserScript==
  8.  
  9. (function () {
  10. 'use strict';
  11.  
  12. // Create toggle button
  13. let button = document.createElement("button");
  14. button.innerText = "Stop";
  15. button.style.position = "fixed";
  16. button.style.bottom = "40px";
  17. button.style.left = "20px";
  18. button.style.padding = "8px 15px";
  19. button.style.fontSize = "14px";
  20. button.style.zIndex = "1000";
  21. button.style.backgroundColor = "#4CAF50";
  22. button.style.color = "white";
  23. button.style.border = "none";
  24. button.style.borderRadius = "5px";
  25. button.style.cursor = "pointer";
  26. document.body.appendChild(button);
  27.  
  28. // Create countdown box
  29. let countdownPopup = document.createElement("div");
  30. countdownPopup.style.position = "fixed";
  31. countdownPopup.style.bottom = "75px";
  32. countdownPopup.style.left = "20px";
  33. countdownPopup.style.padding = "8px 15px";
  34. countdownPopup.style.fontSize = "14px";
  35. countdownPopup.style.zIndex = "1000";
  36. countdownPopup.style.backgroundColor = "#333";
  37. countdownPopup.style.color = "white";
  38. countdownPopup.style.borderRadius = "5px";
  39. countdownPopup.style.display = "none"; // Initially hidden
  40. document.body.appendChild(countdownPopup);
  41.  
  42. // Settings button
  43. const settingsBtn = document.createElement('button');
  44. settingsBtn.innerText = 'Settings';
  45. settingsBtn.style.position = 'fixed';
  46. settingsBtn.style.bottom = '110px';
  47. settingsBtn.style.left = '20px';
  48. settingsBtn.style.zIndex = '1000';
  49. settingsBtn.style.backgroundColor = '#555';
  50. settingsBtn.style.color = 'white';
  51. settingsBtn.style.border = 'none';
  52. settingsBtn.style.borderRadius = '5px';
  53. settingsBtn.style.cursor = 'pointer';
  54. document.body.appendChild(settingsBtn);
  55.  
  56. // Settings popup
  57. const settingsPopup = document.createElement('div');
  58. settingsPopup.style.display = 'none';
  59. settingsPopup.style.position = 'fixed';
  60. settingsPopup.style.bottom = '150px';
  61. settingsPopup.style.left = '20px';
  62. settingsPopup.style.backgroundColor = '#f9f9f9';
  63. settingsPopup.style.padding = '20px';
  64. settingsPopup.style.border = '1px solid #ddd';
  65. settingsPopup.style.zIndex = '1000';
  66. settingsPopup.innerHTML = `
  67. <label>Chat ID: <input type="text" id="chatIdInput" value="${localStorage.getItem('telegramChatId') || '1817608753'}"></label><br><br>
  68. <button id="saveSettingsBtn">Save Settings</button><br><br>
  69. `;
  70. document.body.appendChild(settingsPopup);
  71.  
  72. // Toggle settings popup
  73. settingsBtn.addEventListener('click', () => {
  74. settingsPopup.style.display = settingsPopup.style.display === 'none' ? 'block' : 'none';
  75. });
  76.  
  77. // Save settings
  78. document.getElementById('saveSettingsBtn').addEventListener('click', () => {
  79. const chatId = document.getElementById('chatIdInput').value;
  80. localStorage.setItem('telegramChatId', chatId);
  81. settingsPopup.style.display = 'none';
  82. alert("Settings saved successfully!");
  83. });
  84.  
  85. let isRunning = true;
  86. let intervalId;
  87. let countdownInterval;
  88. let lastCaptchaTime = 0;
  89. let captchaDetected = false;
  90.  
  91. // Telegram bot API token and function
  92. const botToken = "8151644407:AAEzt2C10IC8xGIc_Iaoeno02aPHg-cQFVU";
  93. function sendToTelegram(message) {
  94. const chatId = localStorage.getItem('telegramChatId') || '1817608753';
  95. const url = `https://api.telegram.org/bot${botToken}/sendMessage?chat_id=${chatId}&text=${encodeURIComponent(message)}`;
  96. fetch(url)
  97. .then(response => {
  98. if (!response.ok) {
  99. console.error("Failed to send message to Telegram:", response.statusText);
  100. } else {
  101. console.log("Message sent to Telegram:", message);
  102. }
  103. })
  104. .catch(error => console.error("Telegram API error:", error));
  105. }
  106.  
  107. // Functions
  108. function randomDelay(min, max) {
  109. return Math.floor(Math.random() * (max - min + 1)) + min;
  110. }
  111.  
  112. function pressEnterRandomly() {
  113. const delay = randomDelay(200, 250);
  114. document.dispatchEvent(new KeyboardEvent('keydown', {
  115. key: 'Enter',
  116. code: 'Enter',
  117. which: 13,
  118. keyCode: 13,
  119. bubbles: true
  120. }));
  121. intervalId = setTimeout(pressEnterRandomly, delay);
  122. }
  123.  
  124. function loadFarmGodScript() {
  125. $.getScript('https://higamy.github.io/TW/Scripts/Approved/FarmGodCopy.js')
  126. .done(function (script, textStatus) {
  127. console.log('Script loaded successfully:', textStatus);
  128. })
  129. .fail(function (jqxhr, settings, exception) {
  130. console.error('Error loading script:', exception);
  131. });
  132. }
  133.  
  134. function clickOptionButton(retries = 3) {
  135. let button = document.querySelector('input.btn.optionButton[value="Plan farms"]');
  136. if (button) {
  137. button.click();
  138. console.log("Button 'Plan farms' clicked");
  139. } else {
  140. console.log("Button 'Plan farms' not found");
  141. if (retries > 0) {
  142. console.log("Retrying...");
  143. setTimeout(function () {
  144. clickOptionButton(retries - 1);
  145. }, randomDelay(2000, 4000));
  146. }
  147. }
  148. }
  149.  
  150. function startProcess() {
  151. setTimeout(() => { // Delay before loading FarmGod script
  152. loadFarmGodScript();
  153. setTimeout(() => {
  154. clickOptionButton();
  155. setTimeout(() => {
  156. pressEnterRandomly();
  157. startCountdown(); // Start countdown after initial process setup
  158. }, randomDelay(1000, 5000)); // Step 3 to 4 delay
  159. }, randomDelay(1000, 5000)); // Step 2 to 3 delay
  160. }, randomDelay(1000, 5000)); // Initial delay before loading script
  161. }
  162.  
  163. function stopProcess() {
  164. clearTimeout(intervalId);
  165. clearInterval(countdownInterval);
  166. button.innerText = "Start";
  167. countdownPopup.style.display = "none"; // Hide countdown popup
  168. isRunning = false;
  169. }
  170.  
  171. function toggleProcess() {
  172. if (isRunning) {
  173. stopProcess();
  174. } else if (!captchaDetected) { // Only start if CAPTCHA not detected
  175. startProcess();
  176. button.innerText = "Stop";
  177. isRunning = true;
  178. }
  179. }
  180.  
  181. function startCountdown() {
  182. let timeLeft = randomDelay(300, 600); // 10 to 15 minutes in seconds
  183. countdownPopup.style.display = "block"; // Show countdown popup
  184. countdownInterval = setInterval(() => {
  185. if (timeLeft <= 0) {
  186. clearInterval(countdownInterval);
  187. countdownPopup.style.display = "none"; // Hide countdown popup before reload
  188. location.reload(); // Only reload after the countdown completes
  189. } else {
  190. countdownPopup.innerText = `Next loop in: ${Math.floor(timeLeft / 60)}m ${timeLeft % 60}s`;
  191. timeLeft--;
  192. }
  193. }, 1000);
  194. }
  195.  
  196. // CAPTCHA detection
  197. function checkCaptcha() {
  198. const captchaIframe = document.querySelector('iframe[src*="hcaptcha"]');
  199. const currentTime = Date.now();
  200.  
  201. if (captchaIframe && !captchaDetected) {
  202. console.log("CAPTCHA detected");
  203. captchaDetected = true;
  204. stopProcess(); // Stop all other processes
  205. sendToTelegram("CAPTCHA detected. All processes have been stopped.");
  206. } else if (!captchaIframe && captchaDetected) {
  207. // If CAPTCHA is resolved
  208. captchaDetected = false;
  209. console.log("CAPTCHA resolved");
  210. sendToTelegram("CAPTCHA resolved. You can start the process again.");
  211. }
  212. }
  213.  
  214. // Initial Process Start
  215. startProcess();
  216.  
  217. // Toggle Button Event
  218. button.addEventListener("click", toggleProcess);
  219.  
  220. // Check CAPTCHA every second
  221. setInterval(checkCaptcha, 1000);
  222.  
  223. })();