Auto Send Att Unit Settings

Set the desired arrival time and the script will automatically send the attack. Added unit settings modal.

目前为 2024-12-07 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Auto Send Att Unit Settings
  3. // @version 1
  4. // @description Set the desired arrival time and the script will automatically send the attack. Added unit settings modal.
  5. // @include https://*/game.php?*&screen=place&try=confirm
  6. // @namespace https://greasyfork.org/users/1388899
  7. // ==/UserScript==
  8.  
  9. // Create a button to open the settings modal
  10. const button = document.createElement('button');
  11. button.id = 'openSettings';
  12. button.innerHTML = 'Set Units';
  13. button.style.position = 'fixed';
  14. button.style.bottom = '20px';
  15. button.style.left = '20px';
  16. button.style.padding = '10px 20px';
  17. button.style.backgroundColor = '#4CAF50';
  18. button.style.color = 'white';
  19. button.style.border = 'none';
  20. button.style.cursor = 'pointer';
  21. document.body.appendChild(button);
  22.  
  23. // Create the settings modal
  24. const modal = document.createElement('div');
  25. modal.id = 'settingsModal';
  26. modal.style.display = 'none';
  27. modal.style.position = 'fixed';
  28. modal.style.top = '50%';
  29. modal.style.left = '50%';
  30. modal.style.transform = 'translate(-50%, -50%)';
  31. modal.style.backgroundColor = 'white';
  32. modal.style.border = '1px solid #ccc';
  33. modal.style.padding = '20px';
  34. modal.style.boxShadow = '0px 4px 8px rgba(0,0,0,0.2)';
  35. modal.style.zIndex = '1000';
  36. modal.innerHTML = `
  37. <h3>Set Unit Quantities</h3>
  38. <label for="spear">Spear:</label><input type="number" id="spear" value="0"><br>
  39. <label for="sword">Sword:</label><input type="number" id="sword" value="0"><br>
  40. <label for="axe">Axe:</label><input type="number" id="axe" value="0"><br>
  41. <label for="spy">Spy:</label><input type="number" id="spy" value="0"><br>
  42. <label for="light">Light:</label><input type="number" id="light" value="0"><br>
  43. <label for="heavy">Heavy:</label><input type="number" id="heavy" value="0"><br>
  44. <label for="ram">Ram:</label><input type="number" id="ram" value="0"><br>
  45. <label for="catapult">Catapult:</label><input type="number" id="catapult" value="0"><br>
  46. <label for="knight">Knight:</label><input type="number" id="knight" value="0"><br>
  47. <label for="snob">Snob:</label><input type="number" id="snob" value="0"><br>
  48. <label for="numAttack">Num attack:</label><input type="number" id="numAttack" value="0" min="0"><br>
  49. <button id="applySettings" style="margin-top: 20px;">Apply</button>
  50. <button id="saveSettings" style="margin-top: 20px; background-color: #007bff;">Save</button>
  51. <button id="closeModal" style="margin-top: 20px; background-color: red;">Close</button>
  52. `;
  53. document.body.appendChild(modal);
  54.  
  55. // Open the modal when the settings button is clicked
  56. document.getElementById('openSettings').addEventListener('click', function() {
  57. // Load values from localStorage and apply to inputs if available
  58. const savedUnits = JSON.parse(localStorage.getItem('units')) || {};
  59.  
  60. // Populate the inputs with saved values
  61. document.getElementById('spear').value = savedUnits.spear || 0;
  62. document.getElementById('sword').value = savedUnits.sword || 0;
  63. document.getElementById('axe').value = savedUnits.axe || 0;
  64. document.getElementById('spy').value = savedUnits.spy || 0;
  65. document.getElementById('light').value = savedUnits.light || 0;
  66. document.getElementById('heavy').value = savedUnits.heavy || 0;
  67. document.getElementById('ram').value = savedUnits.ram || 0;
  68. document.getElementById('catapult').value = savedUnits.catapult || 0;
  69. document.getElementById('knight').value = savedUnits.knight || 0;
  70. document.getElementById('snob').value = savedUnits.snob || 0;
  71. document.getElementById('numAttack').value = savedUnits.numAttack || 0;
  72.  
  73. document.getElementById('settingsModal').style.display = 'block';
  74. });
  75.  
  76. // Close the modal when the close button is clicked
  77. document.getElementById('closeModal').addEventListener('click', function() {
  78. document.getElementById('settingsModal').style.display = 'none';
  79. });
  80.  
  81. // Apply the unit values to the input fields and click the button multiple times when the "Apply" button is clicked
  82. document.getElementById('applySettings').addEventListener('click', function() {
  83. // Get the values from the modal inputs
  84. const spear = document.getElementById('spear').value;
  85. const sword = document.getElementById('sword').value;
  86. const axe = document.getElementById('axe').value;
  87. const spy = document.getElementById('spy').value;
  88. const light = document.getElementById('light').value;
  89. const heavy = document.getElementById('heavy').value;
  90. const ram = document.getElementById('ram').value;
  91. const catapult = document.getElementById('catapult').value;
  92. const knight = document.getElementById('knight').value;
  93. const snob = document.getElementById('snob').value;
  94. const numAttack = parseInt(document.getElementById('numAttack').value); // Get the number of attacks
  95.  
  96. // Save the values to localStorage
  97. const units = {
  98. spear,
  99. sword,
  100. axe,
  101. spy,
  102. light,
  103. heavy,
  104. ram,
  105. catapult,
  106. knight,
  107. snob,
  108. numAttack
  109. };
  110. localStorage.setItem('units', JSON.stringify(units));
  111.  
  112. // Click the button 'numAttack' times with a delay of 200ms between clicks
  113. const element = document.getElementById('troop_confirm_train');
  114. for (let i = 0; i < numAttack; i++) {
  115. setTimeout(() => {
  116. if (element) {
  117. element.click(); // Simulate the click
  118. }
  119. }, 200 * i); // Delay of 200ms between clicks
  120. }
  121.  
  122. // Update the corresponding input values on the page after clicking
  123. setTimeout(() => {
  124. const inputs = document.querySelectorAll('.units-row input[data-unit]');
  125. inputs.forEach(input => {
  126. const unitType = input.dataset.unit;
  127. // Set value for each unit according to the modal input value
  128. if (unitType === 'spear') {
  129. input.value = spear;
  130. } else if (unitType === 'sword') {
  131. input.value = sword;
  132. } else if (unitType === 'axe') {
  133. input.value = axe;
  134. } else if (unitType === 'spy') {
  135. input.value = spy;
  136. } else if (unitType === 'light') {
  137. input.value = light;
  138. } else if (unitType === 'heavy') {
  139. input.value = heavy;
  140. } else if (unitType === 'ram') {
  141. input.value = ram;
  142. } else if (unitType === 'catapult') {
  143. input.value = catapult;
  144. } else if (unitType === 'knight') {
  145. input.value = knight;
  146. } else if (unitType === 'snob') {
  147. input.value = snob;
  148. }
  149. });
  150.  
  151. // Close the modal after applying the settings
  152. document.getElementById('settingsModal').style.display = 'none';
  153.  
  154. // Delay of 200ms before enabling the submit button
  155. setTimeout(() => {
  156. // Get the input element with the ID 'troop_confirm_submit'
  157. const submitButton = document.getElementById('troop_confirm_submit');
  158.  
  159. // Remove the 'disabled' attribute to enable the button
  160. if (submitButton) {
  161. submitButton.removeAttribute('disabled');
  162. }
  163. }, 200);
  164. }, 200 * numAttack); // Ensure values are updated after the last click
  165. });
  166.  
  167. // Save the unit values to localStorage without applying or clicking the button
  168. document.getElementById('saveSettings').addEventListener('click', function() {
  169. // Get the values from the modal inputs
  170. const spear = document.getElementById('spear').value;
  171. const sword = document.getElementById('sword').value;
  172. const axe = document.getElementById('axe').value;
  173. const spy = document.getElementById('spy').value;
  174. const light = document.getElementById('light').value;
  175. const heavy = document.getElementById('heavy').value;
  176. const ram = document.getElementById('ram').value;
  177. const catapult = document.getElementById('catapult').value;
  178. const knight = document.getElementById('knight').value;
  179. const snob = document.getElementById('snob').value;
  180. const numAttack = parseInt(document.getElementById('numAttack').value); // Get the number of attacks
  181.  
  182. // Save the values to localStorage
  183. const units = {
  184. spear,
  185. sword,
  186. axe,
  187. spy,
  188. light,
  189. heavy,
  190. ram,
  191. catapult,
  192. knight,
  193. snob,
  194. numAttack
  195. };
  196. localStorage.setItem('units', JSON.stringify(units));
  197. });