Auto Farm

Farmgod and send attack automatically at Loot Assistant at random intervals

目前为 2024-10-31 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Auto Farm
  3. // @version 1
  4. // @description Farmgod and send attack automatically at Loot Assistant at random intervals
  5. // @include https://*/game.php*screen=am_farm*
  6. // @namespace https://greasyfork.org/users/1388863
  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";
  40. document.body.appendChild(countdownPopup);
  41.  
  42. let isRunning = true;
  43. let intervalId;
  44. let countdownInterval;
  45.  
  46. // Functions
  47. function randomDelay(min, max) {
  48. return Math.floor(Math.random() * (max - min + 1)) + min;
  49. }
  50.  
  51. function pressEnterRandomly() {
  52. const delay = randomDelay(200, 350);
  53. document.dispatchEvent(new KeyboardEvent('keydown', {
  54. key: 'Enter',
  55. code: 'Enter',
  56. which: 13,
  57. keyCode: 13,
  58. bubbles: true
  59. }));
  60. intervalId = setTimeout(pressEnterRandomly, delay);
  61. }
  62.  
  63. function loadFarmGodScript() {
  64. $.getScript('https://higamy.github.io/TW/Scripts/Approved/FarmGodCopy.js')
  65. .done(function (script, textStatus) {
  66. console.log('Script loaded successfully:', textStatus);
  67. })
  68. .fail(function (jqxhr, settings, exception) {
  69. console.error('Error loading script:', exception);
  70. });
  71. }
  72.  
  73. function clickOptionButton(retries = 3) {
  74. let button = document.querySelector('input.btn.optionButton[value="Plan farms"]');
  75. if (button) {
  76. button.click();
  77. console.log("Button 'Plan farms' clicked");
  78. } else {
  79. console.log("Button 'Plan farms' not found");
  80. if (retries > 0) {
  81. console.log("Retrying...");
  82. setTimeout(function () {
  83. clickOptionButton(retries - 1);
  84. }, randomDelay(2000, 4000));
  85. }
  86. }
  87. }
  88.  
  89. function startProcess() {
  90. setTimeout(() => {
  91. loadFarmGodScript();
  92. setTimeout(() => {
  93. clickOptionButton();
  94. setTimeout(() => {
  95. pressEnterRandomly();
  96. startCountdown();
  97. }, randomDelay(1000, 5000));
  98. }, randomDelay(1000, 5000));
  99. }, randomDelay(1000, 5000));
  100. }
  101.  
  102. function stopProcess() {
  103. clearTimeout(intervalId);
  104. clearInterval(countdownInterval);
  105. button.innerText = "Start";
  106. countdownPopup.style.display = "none";
  107. isRunning = false;
  108. }
  109.  
  110. function toggleProcess() {
  111. if (isRunning) {
  112. stopProcess();
  113. } else {
  114. startProcess();
  115. button.innerText = "Stop";
  116. isRunning = true;
  117. }
  118. }
  119.  
  120. function startCountdown() {
  121. let timeLeft = randomDelay(300, 600);
  122. countdownPopup.style.display = "block";
  123. countdownInterval = setInterval(() => {
  124. if (timeLeft <= 0) {
  125. clearInterval(countdownInterval);
  126. countdownPopup.style.display = "none";
  127. location.reload();
  128. } else {
  129. countdownPopup.innerText = `Next loop in: ${Math.floor(timeLeft / 60)}m ${timeLeft % 60}s`;
  130. timeLeft--;
  131. }
  132. }, 1000);
  133. }
  134.  
  135. startProcess();
  136.  
  137. button.addEventListener("click", toggleProcess);
  138.  
  139. })();