Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 31.56 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Busca Tribos
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description try to take over the world!
  6. // @author You
  7. // @match https://*/game.php?*&screen=place&mode=scavenge*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11.  
  12. //added to count how many times script gets ran
  13.  
  14. javascript:
  15. //Creators: Sophie "Shinko to Kuma" - Mitchell "Superdog"
  16. /*Update list:
  17. V1.0 - Updated 2/03 - Added automatic grabbing of iables!
  18. V1.1 - Updated 7/03 - Functionality on all servers!
  19. V1.2 - Updated 8/03 - rewrote script to fix some big bugs, condensed code, retiring old version
  20. V1.3 - Updated 9/03 - Adjusted script to work on mobile APP!
  21. */
  22.  
  23. //added to count how many times script gets ran
  24.  
  25. var count = 0;
  26.  
  27.  
  28. function scavenge() {
  29. //checking correct page
  30. const doc = document;
  31. if (window.frames.length > 0 && window.main != null) doc = window.main.document;
  32.  
  33. if (window.location.href.indexOf('screen=place&mode=scavenge') < 0) {
  34. window.location.assign(game_data.link_base_pure + "place&mode=scavenge");
  35. }
  36. var lackadaisicalLooters = document.getElementsByClassName("title")[0].innerHTML;
  37. var humbleHaulers = document.getElementsByClassName("title")[1].innerHTML;
  38. var cleverCollectors = document.getElementsByClassName("title")[2].innerHTML;
  39. var greatGatherers = document.getElementsByClassName("title")[3].innerHTML;
  40. if (parseFloat(game_data.majorVersion) < 8.177) {
  41. var scavengeInfo = JSON.parse($('html').find('script:contains("ScavengeScreen")').html().match(/\{.*\:\{.*\:.*\}\}/g)[0]);
  42. var duration_factor = scavengeInfo[1].duration_factor;
  43. var duration_exponent = scavengeInfo[1].duration_exponent;
  44. var duration_initial_seconds = scavengeInfo[1].duration_initial_seconds;
  45. }
  46. else {
  47. var duration_factor = window.ScavengeScreen.village.options[1].base.duration_factor;
  48. var duration_exponent = window.ScavengeScreen.village.options[1].base.duration_exponent;
  49. var duration_initial_seconds = window.ScavengeScreen.village.options[1].base.duration_initial_seconds;
  50. }
  51. //var loot_factor = scavengeInfo[1].loot_factor
  52.  
  53.  
  54.  
  55.  
  56. function setScavTime() {
  57. //check if duration is preset already
  58. if ("ScavengeTime" in localStorage) {
  59. hours = parseInt(localStorage.getItem("ScavengeTime"));
  60.  
  61. } else {
  62. hours = 6;
  63. }
  64. localStorage.setItem("ScavengeTime", hours);
  65.  
  66.  
  67. }
  68. setScavTime();
  69.  
  70.  
  71. if ($('button').length == 0) {
  72.  
  73. //create interface and button
  74.  
  75.  
  76.  
  77. haulCategory = 0;
  78. localStorage.setItem("haulCategory", haulCategory);
  79. button = document.createElement("button");
  80. button.classList.add("btn-confirm-yes");
  81. button.innerHTML = "Adjust scavenge time";
  82. button.style.visibility = 'hidden';
  83. body = document.getElementById("scavenge_screen");
  84. body.prepend(button);
  85. scavDiv = document.createElement('div');
  86. //check if archer world or not, depending on outcome make table with or without archers
  87. if ($('.units-entry-all[data-unit=archer]').text() != "") {
  88. htmlString = '<div ID= scavTable >\
  89. <table class="scavengeTable" width="15%" style="border: 7px solid rgba(121,0,0,0.71); border-image-slice: 7 7 7 7; border-image-source: url(https://dsen.innogamescdn.com/asset/cf2959e7/graphic/border/frame-gold-red.png);">\
  90. <tbody>\
  91. <tr>\
  92. <th style="text-align:center" colspan="13">Select unittypes to scavenge with</th>\
  93. </tr>\
  94. <tr>\
  95. <th style="text-align:center" width="35"><a href="#" class="unit_link" data-unit="spear"><img src="https://dsen.innogamescdn.com/asset/cf2959e7/graphic/unit/unit_spear.png" title="Spear fighter" alt="" class=""></a></th>\
  96. <th style="text-align:center" width="35"><a href="#" class="unit_link" data-unit="sword"><img src="https://dsen.innogamescdn.com/asset/cf2959e7/graphic/unit/unit_sword.png" title="Swordsman" alt="" class=""></a></th>\
  97. <th style="text-align:center" width="35"><a href="#" class="unit_link" data-unit="axe"><img src="https://dsen.innogamescdn.com/asset/cf2959e7/graphic/unit/unit_axe.png" title="Axeman" alt="" class=""></a></th>\
  98. <th style="text-align:center" width="35"><a href="#" cl ass="unit_link" data-unit="archer"><img src="https://dsen.innogamescdn.com/asset/cf2959e7/graphic/unit/unit_archer.png" title="Archer" alt="" class=""></a></th>\
  99. <th style="text-align:center" width="35"><a href="#" class="unit_link" data-unit="light"><img src="https://dsen.innogamescdn.com/asset/cf2959e7/graphic/unit/unit_light.png" title="Light cavalry" alt="" class=""></a></th>\
  100. <th style="text-align:center" width="35"><a href="#" class="unit_link" data-unit="marcher"><img src="https://dsen.innogamescdn.com/asset/cf2959e7/graphic/unit/unit_marcher.png" title="Mounted Archer" alt="" class=""></a></th>\
  101. <th style="text-align:center" width="35"><a href="#" class="unit_link" data-unit="heavy"><img src="https://dsen.innogamescdn.com/asset/cf2959e7/graphic/unit/unit_heavy.png" title="Heavy cavalry" alt="" class=""></a></th>\
  102. <th style="text-align:center" nowrap>Target runtime</th>\
  103. <th style="text-align:center" nowrap>How many times did the script get launched</th>\
  104. </tr>\
  105. <tr>\
  106. <td align="center"><input type="checkbox" ID="spear" name="spear" checked = "checked" ></td>\
  107. <td align="center"><input type="checkbox" ID="sword" name="sword" ></td>\
  108. <td align="center"><input type="checkbox" ID="axe" name="axe" ></td>\
  109. <td align="center"><input type="checkbox" ID="archer" name="archer" ></td>\
  110. <td align="center"><input type="checkbox" ID="light" name="light" ></td>\
  111. <td align="center"><input type="checkbox" ID="marcher" name="marcher" ></td>\
  112. <td align="center"><input type="checkbox" ID="heavy" name="heavy" ></td>\
  113. <td ID="runtime" align="center"><input type="text" ID="hours" name="hours" size="4" maxlength="5" align=left > hours</td>\
  114. <td id="countScript" align="center"></td>\
  115. </tbody>\
  116. </table>\
  117. </br>\
  118. </div>\
  119. ';
  120. } else {
  121. htmlString = '<div ID= scavTable>\
  122. <table class="scavengeTable" width="15%" style="border: 7px solid rgba(121,0,0,0.71); border-image-slice: 7 7 7 7; border-image-source: url(https://dsen.innogamescdn.com/asset/cf2959e7/graphic/border/frame-gold-red.png);">\
  123. <tbody>\
  124. <tr>\
  125. <th style="text-align:center" colspan="11">Select unittypes to scavenge with</th>\
  126. </tr>\
  127. <tr>\
  128. <th style="text-align:center" width="35"><a href="#" class="unit_link" data-unit="spear"><img src="https://dsen.innogamescdn.com/asset/cf2959e7/graphic/unit/unit_spear.png" title="Spear fighter" alt="" class=""></a></th>\
  129. <th style="text-align:center" width="35"><a href="#" class="unit_link" data-unit="sword"><img src="https://dsen.innogamescdn.com/asset/cf2959e7/graphic/unit/unit_sword.png" title="Swordsman" alt="" class=""></a></th>\
  130. <th style="text-align:center" width="35"><a href="#" class="unit_link" data-unit="axe"><img src="https://dsen.innogamescdn.com/asset/cf2959e7/graphic/unit/unit_axe.png" title="Axeman" alt="" class=""></a></th>\
  131. <th style="text-align:center" width="35"><a href="#" class="unit_link" data-unit="light"><img src="https://dsen.innogamescdn.com/asset/cf2959e7/graphic/unit/unit_light.png" title="Light cavalry" alt="" class=""></a></th>\
  132. <th style="text-align:center" width="35"><a href="#" class="unit_link" data-unit="heavy"><img src="https://dsen.innogamescdn.com/asset/cf2959e7/graphic/unit/unit_heavy.png" title="Heavy cavalry" alt="" class=""></a></th>\
  133. <th style="text-align:center" nowrap>Target runtime</th>\
  134. </tr>\
  135. <tr>\
  136. <td align="center"><input type="checkbox" ID="spear" name="spear"></td>\
  137. <td align="center"><input type="checkbox" ID="sword" name="sword" ></td>\
  138. <td align="center"><input type="checkbox" ID="axe" name="axe" ></td>\
  139. <td align="center"><input type="checkbox" ID="light" name="light" ></td>\
  140. <td align="center"><input type="checkbox" ID="heavy" name="heavy" ></td>\
  141. <td ID="runtime" align="center"><input type="text" ID="hours" name="hours" size="4" maxlength="5" align=left > hours</td>\
  142. <td id="countScript" align="center"></td>\
  143. </tbody>\
  144. </table>\
  145. </br>\
  146. </div>\
  147. ';
  148. }
  149. for (i = 0; i < $(".border-frame-gold-red").length; i++) {
  150. cat = document.createElement('div');
  151. cat.innerHTML = '<div align="center"><h3>Enable</h3><input type="checkbox" ID="haul' + (i + 1) + 'Enabled" name="haul' + (i + 1) + 'Enabled" ><hr></div>';
  152. $(".border-frame-gold-red")[i].prepend(cat);
  153. }
  154.  
  155. scavDiv.innerHTML = htmlString;
  156. scavenge_screen.prepend(scavDiv.firstChild);
  157.  
  158. document.getElementById("hours").value = hours;
  159. document.getElementById("hours").addEventListener("change", function () {
  160. hours = parseInt(document.getElementById("hours").value);
  161. localStorage.setItem("ScavengeTime", hours);
  162. haulCategory = 0;
  163. localStorage.setItem("haulCategory", haulCategory);
  164. calculateHauls();
  165. clear();
  166. setScavTime();
  167. scavenge();
  168. document.getElementById("hours").focus();
  169.  
  170. });
  171.  
  172. }
  173.  
  174. if ($(".scavengeTable")[0]) {
  175. document.getElementById("hours").value = hours;
  176. }
  177.  
  178. checkboxValues = JSON.parse(localStorage.getItem('checkboxValues')) || {}, $checkboxes = $("#scavTable :checkbox");
  179. $checkboxes.on("change", function () {
  180. $checkboxes.each(function () {
  181. checkboxValues[this.id] = this.checked;
  182. });
  183. localStorage.setItem("checkboxValues", JSON.stringify(checkboxValues));
  184. calculateHauls();
  185. haulCategory = 0;
  186. localStorage.setItem("haulCategory", haulCategory);
  187. scavenge();
  188. });
  189.  
  190. $.each(checkboxValues, function (key, value) {
  191. $("#" + key).prop('checked', value);
  192. });
  193.  
  194.  
  195. if ($(".scavengeTable").length) {
  196. spears = $('.units-entry-all[data-unit=spear]').text().match(/\((\d+)\)/)[1];
  197. swords = $('.units-entry-all[data-unit=sword]').text().match(/\((\d+)\)/)[1];
  198. axes = $('.units-entry-all[data-unit=axe]').text().match(/\((\d+)\)/)[1];
  199. lightC = $('.units-entry-all[data-unit=light]').text().match(/\((\d+)\)/)[1];
  200. heavyC = $('.units-entry-all[data-unit=heavy]').text().match(/\((\d+)\)/)[1];
  201. if ($('.units-entry-all[data-unit=archer]').text() != "") {
  202. archer = $('.units-entry-all[data-unit=archer]').text().match(/\((\d+)\)/)[1]
  203. } else archer = 0;
  204.  
  205. if ($('.units-entry-all[data-unit=marcher]').text() != "") {
  206. marcher = $('.units-entry-all[data-unit=marcher]').text().match(/\((\d+)\)/)[1]
  207. } else marcher = 0;
  208. checkboxStatus();
  209. }
  210. else {
  211. spears = $('.units-entry-all[data-unit=spear]').text().match(/\((\d+)\)/)[1];
  212. swords = $('.units-entry-all[data-unit=sword]').text().match(/\((\d+)\)/)[1];
  213. axes = $('.units-entry-all[data-unit=axe]').text().match(/\((\d+)\)/)[1];
  214. lightC = $('.units-entry-all[data-unit=light]').text().match(/\((\d+)\)/)[1];
  215. heavyC = $('.units-entry-all[data-unit=heavy]').text().match(/\((\d+)\)/)[1];
  216. if ($('.units-entry-all[data-unit=archer]').text() != "") {
  217. archer = $('.units-entry-all[data-unit=archer]').text().match(/\((\d+)\)/)[1]
  218. } else archer = 0;
  219.  
  220. if ($('.units-entry-all[data-unit=marcher]').text() != "") {
  221. marcher = $('.units-entry-all[data-unit=marcher]').text().match(/\((\d+)\)/)[1]
  222. } else marcher = 0;
  223. }
  224.  
  225. function checkboxStatus() {
  226. if (document.getElementById("spear").checked == false) {
  227. spears = 0;
  228. haulcategory = 0;
  229. }
  230. if (document.getElementById("sword").checked == false) {
  231. swords = 0;
  232. haulcategory = 0;
  233. }
  234. if (document.getElementById("axe").checked == false) {
  235. axes = 0;
  236. haulcategory = 0;
  237. }
  238. if (document.getElementById("light").checked == false) {
  239. lightC = 0;
  240. haulcategory = 0;
  241. }
  242. if (document.getElementById("heavy").checked == false) {
  243. heavyC = 0;
  244. haulcategory = 0;
  245. }
  246. if ($('.units-entry-all[data-unit=archer]').text() != "") {
  247. if (document.getElementById("archer").checked == false) {
  248. archer = 0;
  249. haulcategory = 0;
  250. }
  251. }
  252. if ($('.units-entry-all[data-unit=marcher]').text() != "") {
  253. if (document.getElementById("marcher").checked == false) {
  254. marcher = 0;
  255. haulcategory = 0;
  256. }
  257. }
  258.  
  259. }
  260.  
  261.  
  262. function calculateHauls() {
  263.  
  264. checkboxStatus();
  265.  
  266. totalLoot = spears * 25 + swords * 15 + axes * 10 + lightC * 80 + heavyC * 50 + archer * 10 + marcher * 50;
  267. totalSpSwLoot = spears * 25 + swords * 15;
  268. possibleLoot = spears * 25 + swords * 15 + axes * 10 + lightC * 80 + heavyC * 50 + archer * 10 + marcher * 50;
  269. spearRatio = spears / (spears * 25 + swords * 15);
  270. swordRatio = swords / (spears * 25 + swords * 15);
  271.  
  272. time = hours * 3600;
  273. haul = ((time / duration_factor - duration_initial_seconds) ** (1 / (duration_exponent)) / 100) ** (1 / 2);
  274. haul1 = haul / 0.1;
  275. haul2 = haul / 0.25;
  276. haul3 = haul / 0.5;
  277. haul4 = haul / 0.75;
  278. totalHaul = haul1 + haul2 + haul3 + haul4;
  279.  
  280. }
  281. calculateHauls();
  282.  
  283. if ("haulCategory" in localStorage) {
  284. haulCategory = localStorage.getItem("haulCategory");
  285. } else {
  286. haulCategory = 0;
  287. localStorage.setItem("haulCategory", haulCategory);
  288. }
  289.  
  290.  
  291. if (totalLoot > totalHaul) {
  292. if (totalSpSwLoot > totalHaul) {
  293. if (haulCategory == 0) {
  294. haulCategory = 1;
  295. localStorage.setItem("haulCategory", haulCategory);
  296. }
  297. } else {
  298. if (haulCategory == 0) {
  299. haulCategory = 2;
  300. localStorage.setItem("haulCategory", haulCategory);
  301. }
  302. }
  303. } else {
  304. if (haulCategory == 0) {
  305. haulCategory = 3;
  306. localStorage.setItem("haulCategory", haulCategory);
  307. }
  308. }
  309.  
  310. if (haulCategory == 1) {
  311. scavengeOptions = {};
  312. scavengeOptions[greatGatherers] = [
  313. {
  314. type: 'spear',
  315. count: (haul4 * spearRatio)
  316. },
  317. {
  318. type: 'sword',
  319. count: (haul4 * swordRatio)
  320. },
  321. {
  322. type: 'axe',
  323. count: 0
  324. },
  325. {
  326. type: 'archer',
  327. count: 0
  328. },
  329. {
  330. type: 'light',
  331. count: 0
  332. },
  333. {
  334. type: 'marcher',
  335. count: 0
  336. },
  337. {
  338. type: 'heavy',
  339. count: 0
  340. },
  341. ];
  342. scavengeOptions[cleverCollectors] = [
  343. {
  344. type: 'spear',
  345. count: (haul3 * spearRatio)
  346. },
  347. {
  348. type: 'sword',
  349. count: (haul3 * swordRatio)
  350. },
  351. {
  352. type: 'axe',
  353. count: 0
  354. },
  355. {
  356. type: 'archer',
  357. count: 0
  358. },
  359. {
  360. type: 'light',
  361. count: 0
  362. },
  363. {
  364. type: 'marcher',
  365. count: 0
  366. },
  367. {
  368. type: 'heavy',
  369. count: 0
  370. },
  371. ];
  372. scavengeOptions[humbleHaulers] = [
  373. {
  374. type: 'spear',
  375. count: (haul2 * spearRatio)
  376. },
  377. {
  378. type: 'sword',
  379. count: (haul2 * swordRatio)
  380. },
  381. {
  382. type: 'axe',
  383. count: 0
  384. },
  385. {
  386. type: 'archer',
  387. count: 0
  388. },
  389. {
  390. type: 'light',
  391. count: 0
  392. },
  393. {
  394. type: 'marcher',
  395. count: 0
  396. },
  397. {
  398. type: 'heavy',
  399. count: 0
  400. },
  401. ];
  402. scavengeOptions[lackadaisicalLooters] = [
  403. {
  404. type: 'spear',
  405. count: (haul1 * spearRatio)
  406. },
  407. {
  408. type: 'sword',
  409. count: (haul1 * swordRatio)
  410. },
  411. {
  412. type: 'axe',
  413. count: 0
  414. },
  415. {
  416. type: 'archer',
  417. count: 0
  418. },
  419. {
  420. type: 'light',
  421. count: 0
  422. },
  423. {
  424. type: 'marcher',
  425. count: 0
  426. },
  427. {
  428. type: 'heavy',
  429. count: 0
  430. },
  431. ];
  432.  
  433. } else {
  434. if (haulCategory == 2) {
  435. scavengeOptions = {};
  436. scavengeOptions[greatGatherers] = [
  437. {
  438. type: 'spear',
  439. count: (haul4 * (spears / possibleLoot))
  440. },
  441. {
  442. type: 'sword',
  443. count: (haul4 * (swords / possibleLoot))
  444. },
  445. {
  446. type: 'axe',
  447. count: (haul4 * (axes / possibleLoot))
  448. },
  449. {
  450. type: 'light',
  451. count: (haul4 * (lightC / possibleLoot))
  452. },
  453. {
  454. type: 'heavy',
  455. count: (haul4 * (heavyC / possibleLoot))
  456. },
  457. {
  458. type: 'archer',
  459. count: (haul4 * (archer / possibleLoot))
  460. },
  461. {
  462. type: 'marcher',
  463. count: (haul4 * (marcher / possibleLoot))
  464. },
  465. ];
  466. scavengeOptions[cleverCollectors] = [
  467. {
  468. type: 'spear',
  469. count: (haul3 * (spears / possibleLoot))
  470. },
  471. {
  472. type: 'sword',
  473. count: (haul3 * (swords / possibleLoot))
  474. },
  475. {
  476. type: 'axe',
  477. count: (haul3 * (axes / possibleLoot))
  478. },
  479. {
  480. type: 'light',
  481. count: (haul3 * (lightC / possibleLoot))
  482. },
  483. {
  484. type: 'heavy',
  485. count: (haul3 * (heavyC / possibleLoot))
  486. },
  487. {
  488. type: 'archer',
  489. count: (haul3 * (archer / possibleLoot))
  490. },
  491. {
  492. type: 'marcher',
  493. count: (haul3 * (marcher / possibleLoot))
  494. },
  495. ];
  496. scavengeOptions[humbleHaulers] = [
  497. {
  498. type: 'spear',
  499. count: (haul2 * (spears / possibleLoot))
  500. },
  501. {
  502. type: 'sword',
  503. count: (haul2 * (swords / possibleLoot))
  504. },
  505. {
  506. type: 'axe',
  507. count: (haul2 * (axes / possibleLoot))
  508. },
  509. {
  510. type: 'light',
  511. count: (haul2 * (lightC / possibleLoot))
  512. },
  513. {
  514. type: 'heavy',
  515. count: (haul2 * (heavyC / possibleLoot))
  516. },
  517. {
  518. type: 'archer',
  519. count: (haul2 * (archer / possibleLoot))
  520. },
  521. {
  522. type: 'marcher',
  523. count: (haul2 * (marcher / possibleLoot))
  524. },
  525. ];
  526. scavengeOptions[lackadaisicalLooters] = [
  527. {
  528. type: 'spear',
  529. count: (haul1 * (spears / possibleLoot))
  530. },
  531. {
  532. type: 'sword',
  533. count: (haul1 * (swords / possibleLoot))
  534. },
  535. {
  536. type: 'axe',
  537. count: (haul1 * (axes / possibleLoot))
  538. },
  539. {
  540. type: 'light',
  541. count: (haul1 * (lightC / possibleLoot))
  542. },
  543. {
  544. type: 'heavy',
  545. count: (haul1 * (heavyC / possibleLoot))
  546. },
  547. {
  548. type: 'archer',
  549. count: (haul1 * (archer / possibleLoot))
  550. },
  551. {
  552. type: 'marcher',
  553. count: (haul1 * (marcher / possibleLoot))
  554. },
  555. ];
  556. } else {
  557. if (haulCategory == 3) {
  558. scavengeOptions = {};
  559. scavengeOptions[greatGatherers] = [
  560. {
  561. type: 'spear',
  562. count: ((totalLoot / totalHaul * haul4) * (spears / possibleLoot))
  563. },
  564. {
  565. type: 'sword',
  566. count: ((totalLoot / totalHaul * haul4) * (swords / possibleLoot))
  567. },
  568. {
  569. type: 'axe',
  570. count: ((totalLoot / totalHaul * haul4) * (axes / possibleLoot))
  571. },
  572. {
  573. type: 'light',
  574. count: ((totalLoot / totalHaul * haul4) * (lightC / possibleLoot))
  575. },
  576. {
  577. type: 'heavy',
  578. count: ((totalLoot / totalHaul * haul4) * (heavyC / possibleLoot))
  579. },
  580. {
  581. type: 'archer',
  582. count: ((totalLoot / totalHaul * haul4) * (archer / possibleLoot))
  583. },
  584. {
  585. type: 'marcher',
  586. count: ((totalLoot / totalHaul * haul4) * (marcher / possibleLoot))
  587. },
  588. ];
  589. scavengeOptions[cleverCollectors] = [
  590. {
  591. type: 'spear',
  592. count: ((totalLoot / (totalHaul - haul4) * haul3) * (spears / possibleLoot))
  593. },
  594. {
  595. type: 'sword',
  596. count: ((totalLoot / (totalHaul - haul4) * haul3) * (swords / possibleLoot))
  597. },
  598. {
  599. type: 'axe',
  600. count: ((totalLoot / (totalHaul - haul4) * haul3) * (axes / possibleLoot))
  601. },
  602. {
  603. type: 'light',
  604. count: ((totalLoot / (totalHaul - haul4) * haul3) * (lightC / possibleLoot))
  605. },
  606. {
  607. type: 'heavy',
  608. count: ((totalLoot / (totalHaul - haul4) * haul3) * (heavyC / possibleLoot))
  609. },
  610. {
  611. type: 'archer',
  612. count: ((totalLoot / (totalHaul - haul4) * haul3) * (archer / possibleLoot))
  613. },
  614. {
  615. type: 'marcher',
  616. count: ((totalLoot / (totalHaul - haul4) * haul3) * (marcher / possibleLoot))
  617. },
  618. ];
  619. scavengeOptions[humbleHaulers] = [
  620. {
  621. type: 'spear',
  622. count: ((totalLoot / (totalHaul - haul4 - haul3) * haul2) * (spears / possibleLoot))
  623. },
  624. {
  625. type: 'sword',
  626. count: ((totalLoot / (totalHaul - haul4 - haul3) * haul2) * (swords / possibleLoot))
  627. },
  628. {
  629. type: 'axe',
  630. count: ((totalLoot / (totalHaul - haul4 - haul3) * haul2) * (axes / possibleLoot))
  631. },
  632. {
  633. type: 'light',
  634. count: ((totalLoot / (totalHaul - haul4 - haul3) * haul2) * (lightC / possibleLoot))
  635. },
  636. {
  637. type: 'heavy',
  638. count: ((totalLoot / (totalHaul - haul4 - haul3) * haul2) * (heavyC / possibleLoot))
  639. },
  640. {
  641. type: 'archer',
  642. count: ((totalLoot / (totalHaul - haul4 - haul3) * haul2) * (archer / possibleLoot))
  643. },
  644. {
  645. type: 'marcher',
  646. count: ((totalLoot / (totalHaul - haul4 - haul3) * haul2) * (marcher / possibleLoot))
  647. },
  648. ];
  649. scavengeOptions[lackadaisicalLooters] = [
  650. {
  651. type: 'spear',
  652. count: (totalLoot * (spears / possibleLoot))
  653. },
  654. {
  655. type: 'sword',
  656. count: (totalLoot * (swords / possibleLoot))
  657. },
  658. {
  659. type: 'axe',
  660. count: (totalLoot * (axes / possibleLoot))
  661. },
  662. {
  663. type: 'light',
  664. count: (totalLoot * (lightC / possibleLoot))
  665. },
  666. {
  667. type: 'heavy',
  668. count: (totalLoot * (heavyC / possibleLoot))
  669. },
  670. {
  671. type: 'archer',
  672. count: (totalLoot * (archer / possibleLoot))
  673. },
  674. {
  675. type: 'marcher',
  676. count: (totalLoot * (marcher / possibleLoot))
  677. },
  678. ];
  679. }
  680. }
  681. }
  682.  
  683. document.getElementById("spear").checked = true;
  684. document.getElementById("sword").checked = true;
  685. document.getElementById("axe").checked = true;
  686. document.getElementById("light").checked = true;
  687. run();
  688.  
  689. function run() {
  690. let btn = null;
  691. for (const option in scavengeOptions) {
  692. btn = findNextButton(option);
  693.  
  694. if (btn) {
  695. fillInTroops(option, getAvailableUnits(), btn);
  696. btn[0].click();
  697. location.reload();
  698. break;
  699. } else {
  700. window.setInterval(function(){
  701. location.reload();
  702. }, 60000);
  703. }
  704. }
  705. }
  706.  
  707. function clear() {
  708. let btn = null;
  709. for (const option in scavengeOptions) {
  710. btn = findNextButton(option);
  711. if (btn) {
  712. emptyTroops(option);
  713. break;
  714. }
  715. }
  716. }
  717.  
  718. function fillInTroops(option, availableUnits, button) {
  719. scavengeOptions[option].forEach(units => {
  720. const type = units.type;
  721. const count = units.count;
  722. let requiredCapacity = availableUnits[type] < count ? availableUnits[type] : count;
  723.  
  724. $(`input.unitsInput[name='${type}']`).val(requiredCapacity).trigger("change");
  725. $(button).focus();
  726. });
  727. }
  728.  
  729. function emptyTroops(option) {
  730. scavengeOptions[option].forEach(units => {
  731. const type = units.type;
  732. $(`input.unitsInput[name='${type}']`).val("").trigger("change");
  733. });
  734. }
  735.  
  736. function getCookie(name) {
  737. var dc = document.cookie;
  738. var prefix = name + "=";
  739. var begin = dc.indexOf("; " + prefix);
  740. if (begin == -1) {
  741. begin = dc.indexOf(prefix);
  742. if (begin != 0) return null;
  743. }
  744. else
  745. {
  746. begin += 2;
  747. var end = document.cookie.indexOf(";", begin);
  748. if (end == -1) {
  749. end = dc.length;
  750. }
  751. }
  752. // because unescape has been deprecated, replaced with decodeURI
  753. //return unescape(dc.substring(begin + prefix.length, end));
  754. return decodeURI(dc.substring(begin + prefix.length, end));
  755. }
  756.  
  757. function setCookie(name,value,days) {
  758. var expires = "";
  759. if (days) {
  760. var date = new Date();
  761. date.setTime(date.getTime() + (days*24*60*60*1000));
  762. expires = "; expires=" + date.toUTCString();
  763. }
  764. document.cookie = name + "=" + (value || "") + expires + "; path=/";
  765. }
  766.  
  767. function findNextButton(option) {
  768. if (getCookie('clicar') == null) {
  769. setCookie('clicar', 'nbtn', 3);
  770. } else {
  771. var tmpArray = [];
  772. for (i = 0; i < document.getElementsByClassName("btn btn-default free_send_button").length ; i++) {
  773. var tmp = document.getElementsByClassName("btn btn-default free_send_button")[i].innerHTML;
  774. tmpArray.push(tmp);
  775. }
  776.  
  777. if (tmpArray.length == 4) {
  778. setCookie('clicar', '4btn', 3);
  779. } else if (tmpArray.length == 0) {
  780. setCookie('clicar', '0btn', 3);
  781. }
  782. }
  783.  
  784. if (getCookie('clicar') == '4btn') {
  785. startButtonName = document.getElementsByClassName("btn btn-default free_send_button")[0].innerHTML;
  786. let btn = $(`.scavenge-option:contains("${option}")`).find('a:contains(' + startButtonName + ')');
  787. if (btn.length > 0 && !$(btn).hasClass('btn-disabled')) return btn;
  788. } else {
  789. return false;
  790. }
  791. }
  792.  
  793.  
  794. function getAvailableUnits() {
  795. let availableUnits = {};
  796.  
  797. $('.units-entry-all').each((i, e) => {
  798. const unitName = $(e).attr("data-unit");
  799. const count = $(e).text().replace(/[()]/, '');
  800. availableUnits[unitName] = parseInt(count);
  801. });
  802. return availableUnits;
  803. }
  804.  
  805.  
  806. }
  807.  
  808. scavenge();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement