Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 81.23 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Buscas Automáticas
  3. // @version 0.1
  4. // @author FancyDevs
  5. // @include https://*.tribalwars.com.pt/game.php?*village=*&screen=place*&mode=scavenge*
  6. // @namespace https://fancydevsgeneral.github.io/
  7. // @icon https://vignette.wikia.nocookie.net/nonsensopedia/images/8/8d/Worek.png/revision/latest?cb=20130716095617
  8. // ==/UserScript==
  9.  
  10.  
  11.  
  12. function scavenge() {
  13.  
  14. //checking correct page
  15. const doc = document;
  16. if (window.frames.length > 0 && window.main != null) doc = window.main.document;
  17.  
  18. //if (window.location.href.indexOf('screen=place&mode=scavenge') < 0) {
  19. // window.location.assign(game_data.link_base_pure + "place&mode=scavenge");
  20. // }
  21. var lackadaisicalLooters = document.getElementsByClassName("title")[0].innerHTML;
  22. var humbleHaulers = document.getElementsByClassName("title")[1].innerHTML;
  23. var cleverCollectors = document.getElementsByClassName("title")[2].innerHTML;
  24. var greatGatherers = document.getElementsByClassName("title")[3].innerHTML;
  25. var scavengeInfo = JSON.parse($('html').find('script:contains("ScavengeScreen")').html().match(/\{.*\:\{.*\:.*\}\}/g)[1]);
  26. var duration_factor = scavengeInfo[1].duration_factor;
  27. var duration_exponent = scavengeInfo[1].duration_exponent;
  28. var duration_initial_seconds = scavengeInfo[1].duration_initial_seconds;
  29. //var loot_factor = scavengeInfo[1].loot_factor
  30.  
  31.  
  32.  
  33.  
  34. function setScavTime() {
  35. //check if duration is preset already
  36. if ("ScavengeTime" in sessionStorage) {
  37. hours = parseInt(sessionStorage.getItem("ScavengeTime"));
  38.  
  39. } else {
  40. hours = 24;
  41. }
  42. sessionStorage.setItem("ScavengeTime", hours);
  43.  
  44.  
  45. }
  46. setScavTime();
  47.  
  48.  
  49. if ($('button').length == 0) {
  50. //create interface and button
  51. haulCategory = 0;
  52. sessionStorage.setItem("haulCategory", haulCategory);
  53. button = document.createElement("button");
  54. button.classList.add("btn-confirm-yes");
  55. button.innerHTML = "Adjust scavenge time";
  56. button.style.visibility = 'hidden';
  57. body = document.getElementById("scavenge_screen");
  58. body.prepend(button);
  59.  
  60. scavDiv = document.createElement('div');
  61. //check if archer world or not, depending on outcome make table with or without archers
  62. if ($('.units-entry-all[data-unit=archer]').text() != "") {
  63. htmlString = '<div class = center1 ID= scavTable >\
  64. <table class="center1" width="30%" 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);">\
  65. <tbody>\
  66. <tr>\
  67. <th style="text-align:center" colspan="8">Escolha as unidades a enviar</th>\
  68. </tr>\
  69. <tr>\
  70. <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>\
  71. <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>\
  72. <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>\
  73. <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>\
  74. <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>\
  75. <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>\
  76. <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>\
  77. <th style="text-align:center" nowrap>Duração</th>\
  78. </tr>\
  79. <tr>\
  80. <td align="center"><input type="checkbox" ID="spear" name="spear" checked = "checked" ></td>\
  81. <td align="center"><input type="checkbox" ID="sword" name="sword" checked = "checked" ></td>\
  82. <td align="center"><input type="checkbox" ID="axe" name="axe" checked = "checked" ></td>\
  83. <td align="center"><input type="checkbox" ID="archer" name="archer" checked = "checked" ></td>\
  84. <td align="center"><input type="checkbox" ID="light" name="light" checked = "checked" ></td>\
  85. <td align="center"><input type="checkbox" ID="marcher" name="marcher" checked = "checked" ></td>\
  86. <td align="center"><input type="checkbox" ID="heavy" name="heavy" checked = "checked" ></td>\
  87. <td ID="runtime" align="center"><input type="text" ID="hours" name="hours" size="4" maxlength="2" align=left > hours</td>\
  88. </tbody>\
  89. </table>\
  90. </br>\
  91. </div>\
  92. ';
  93. } else {
  94. htmlString = '<div class = center1 ID= scavTable>\
  95. <table class="center1" width="30%" 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);">\
  96. <tbody>\
  97. <tr>\
  98. <th style="text-align:center" colspan="6">Escolha as unidades a enviar</th>\
  99. </tr>\
  100. <tr>\
  101. <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>\
  102. <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>\
  103. <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>\
  104. <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>\
  105. <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>\
  106. <th style="text-align:center" nowrap>Duração</th>\
  107. </tr>\
  108. <tr>\
  109. <td align="center"><input type="checkbox" ID="spear" name="spear"></td>\
  110. <td align="center"><input type="checkbox" ID="sword" name="sword" ></td>\
  111. <td align="center"><input type="checkbox" ID="axe" name="axe" ></td>\
  112. <td align="center"><input type="checkbox" ID="light" name="light" ></td>\
  113. <td align="center"><input type="checkbox" ID="heavy" name="heavy" ></td>\
  114. <td ID="runtime" align="center"><input type="text" ID="hours" name="hours" size="4" maxlength="2" align=left > hours</td>\
  115. </tbody>\
  116. </table>\
  117. </br>\
  118. </div>\
  119. ';
  120. }
  121. scavDiv.innerHTML = htmlString;
  122. scavenge_screen.after(scavDiv.firstChild);
  123. document.getElementById("hours").value = hours;
  124. document.getElementById("hours").addEventListener("change", function () {
  125. hours = parseInt(document.getElementById("hours").value);
  126. sessionStorage.setItem("ScavengeTime", hours);
  127. haulCategory=0;
  128. sessionStorage.setItem("haulCategory", haulCategory);
  129. calculateHauls();
  130. clear();
  131. setScavTime();
  132. scavenge();
  133. document.getElementById("hours").focus();
  134. });
  135. }
  136.  
  137. if ($(".scavengeTable")[0]) {
  138. document.getElementById("hours").value = hours;
  139. }
  140.  
  141. checkboxValues = JSON.parse(localStorage.getItem('checkboxValues')) || {}, $checkboxes = $("#scavTable :checkbox");
  142. $checkboxes.on("change", function () {
  143. $checkboxes.each(function () {
  144. checkboxValues[this.id] = this.checked;
  145. });
  146. localStorage.setItem("checkboxValues", JSON.stringify(checkboxValues));
  147. calculateHauls();
  148. haulCategory = 0;
  149. sessionStorage.setItem("haulCategory", haulCategory);
  150. scavenge();
  151. });
  152.  
  153. $.each(checkboxValues, function (key, value) {
  154. $("#" + key).prop('checked', value);
  155. });
  156.  
  157.  
  158. if ($(".scavengeTable").length) {
  159. spears = $('.units-entry-all[data-unit=spear]').text().match(/\((\d+)\)/)[1];
  160. swords = $('.units-entry-all[data-unit=sword]').text().match(/\((\d+)\)/)[1];
  161. axes = $('.units-entry-all[data-unit=axe]').text().match(/\((\d+)\)/)[1];
  162. lightC = $('.units-entry-all[data-unit=light]').text().match(/\((\d+)\)/)[1];
  163. heavyC = $('.units-entry-all[data-unit=heavy]').text().match(/\((\d+)\)/)[1];
  164. if ($('.units-entry-all[data-unit=archer]').text() != "") {
  165. archer = $('.units-entry-all[data-unit=archer]').text().match(/\((\d+)\)/)[1]
  166. } else archer = 0;
  167.  
  168. if ($('.units-entry-all[data-unit=marcher]').text() != "") {
  169. marcher = $('.units-entry-all[data-unit=marcher]').text().match(/\((\d+)\)/)[1]
  170. } else marcher = 0;
  171. checkboxStatus();
  172. }
  173. else {
  174. spears = $('.units-entry-all[data-unit=spear]').text().match(/\((\d+)\)/)[1];
  175. swords = $('.units-entry-all[data-unit=sword]').text().match(/\((\d+)\)/)[1];
  176. axes = $('.units-entry-all[data-unit=axe]').text().match(/\((\d+)\)/)[1];
  177. lightC = $('.units-entry-all[data-unit=light]').text().match(/\((\d+)\)/)[1];
  178. heavyC = $('.units-entry-all[data-unit=heavy]').text().match(/\((\d+)\)/)[1];
  179. if ($('.units-entry-all[data-unit=archer]').text() != "") {
  180. archer = $('.units-entry-all[data-unit=archer]').text().match(/\((\d+)\)/)[1]
  181. } else archer = 0;
  182.  
  183. if ($('.units-entry-all[data-unit=marcher]').text() != "") {
  184. marcher = $('.units-entry-all[data-unit=marcher]').text().match(/\((\d+)\)/)[1]
  185. } else marcher = 0;
  186. }
  187.  
  188. function checkboxStatus() {
  189. if (document.getElementById("spear").checked == false) {
  190. spears = 0;
  191. haulcategory = 0;
  192. }
  193. if (document.getElementById("sword").checked == false) {
  194. swords = 0;
  195. haulcategory = 0;
  196. }
  197. if (document.getElementById("axe").checked == false) {
  198. axes = 0;
  199. haulcategory = 0;
  200. }
  201. if (document.getElementById("light").checked == false) {
  202. lightC = 0;
  203. haulcategory = 0;
  204. }
  205. if (document.getElementById("heavy").checked == false) {
  206. heavyC = 0;
  207. haulcategory = 0;
  208. }
  209. if ($('.units-entry-all[data-unit=archer]').text() != "") {
  210. if (document.getElementById("archer").checked == false) {
  211. archer = 0;
  212. haulcategory = 0;
  213. }
  214. }
  215. if ($('.units-entry-all[data-unit=marcher]').text() != "") {
  216. if (document.getElementById("marcher").checked == false) {
  217. marcher = 0;
  218. haulcategory = 0;
  219. }
  220. }
  221.  
  222. }
  223.  
  224.  
  225. function calculateHauls() {
  226.  
  227. checkboxStatus();
  228.  
  229. totalLoot = spears * 25 + swords * 15 + axes * 10 + lightC * 80 + heavyC * 50 + archer * 10 + marcher * 50;
  230. totalSpSwLoot = spears * 25 + swords * 15;
  231. possibleLoot = spears * 25 + swords * 15 + axes * 10 + lightC * 80 + heavyC * 50 + archer * 10 + marcher * 50;
  232. spearRatio = spears / (spears * 25 + swords * 15);
  233. swordRatio = swords / (spears * 25 + swords * 15);
  234.  
  235. time = hours * 3600;
  236. haul = ((time / duration_factor - duration_initial_seconds) ** (1 / (duration_exponent)) / 100) ** (1 / 2);
  237. haul1 = haul / 0.1;
  238. haul2 = haul / 0.25;
  239. haul3 = haul / 0.5;
  240. haul4 = haul / 0.75;
  241. totalHaul = haul1 + haul2 + haul3 + haul4;
  242.  
  243. }
  244. calculateHauls();
  245.  
  246. if ("haulCategory" in sessionStorage) {
  247. haulCategory = sessionStorage.getItem("haulCategory");
  248. } else {
  249. haulCategory = 0;
  250. sessionStorage.setItem("haulCategory", haulCategory);
  251. }
  252.  
  253.  
  254. if (totalLoot > totalHaul) {
  255. if (totalSpSwLoot > totalHaul) {
  256. if (haulCategory == 0) {
  257. haulCategory = 1;
  258. sessionStorage.setItem("haulCategory", haulCategory);
  259. }
  260. } else {
  261. if (haulCategory == 0) {
  262. haulCategory = 2;
  263. sessionStorage.setItem("haulCategory", haulCategory);
  264. }
  265. }
  266. } else {
  267. if (haulCategory == 0) {
  268. haulCategory = 3;
  269. sessionStorage.setItem("haulCategory", haulCategory);
  270. }
  271. }
  272.  
  273. if (haulCategory == 1) {
  274. scavengeOptions = {};
  275. scavengeOptions[greatGatherers] = [
  276. {
  277. type: 'spear',
  278. count: (haul4 * spearRatio)
  279. },
  280. {
  281. type: 'sword',
  282. count: (haul4 * swordRatio)
  283. },
  284. {
  285. type: 'axe',
  286. count: 0
  287. },
  288. {
  289. type: 'archer',
  290. count: 0
  291. },
  292. {
  293. type: 'light',
  294. count: 0
  295. },
  296. {
  297. type: 'marcher',
  298. count: 0
  299. },
  300. {
  301. type: 'heavy',
  302. count: 0
  303. },
  304. ];
  305. scavengeOptions[cleverCollectors] = [
  306. {
  307. type: 'spear',
  308. count: (haul3 * spearRatio)
  309. },
  310. {
  311. type: 'sword',
  312. count: (haul3 * swordRatio)
  313. },
  314. {
  315. type: 'axe',
  316. count: 0
  317. },
  318. {
  319. type: 'archer',
  320. count: 0
  321. },
  322. {
  323. type: 'light',
  324. count: 0
  325. },
  326. {
  327. type: 'marcher',
  328. count: 0
  329. },
  330. {
  331. type: 'heavy',
  332. count: 0
  333. },
  334. ];
  335. scavengeOptions[humbleHaulers] = [
  336. {
  337. type: 'spear',
  338. count: (haul2 * spearRatio)
  339. },
  340. {
  341. type: 'sword',
  342. count: (haul2 * swordRatio)
  343. },
  344. {
  345. type: 'axe',
  346. count: 0
  347. },
  348. {
  349. type: 'archer',
  350. count: 0
  351. },
  352. {
  353. type: 'light',
  354. count: 0
  355. },
  356. {
  357. type: 'marcher',
  358. count: 0
  359. },
  360. {
  361. type: 'heavy',
  362. count: 0
  363. },
  364. ];
  365. scavengeOptions[lackadaisicalLooters] = [
  366. {
  367. type: 'spear',
  368. count: (haul1 * spearRatio)
  369. },
  370. {
  371. type: 'sword',
  372. count: (haul1 * swordRatio)
  373. },
  374. {
  375. type: 'axe',
  376. count: 0
  377. },
  378. {
  379. type: 'archer',
  380. count: 0
  381. },
  382. {
  383. type: 'light',
  384. count: 0
  385. },
  386. {
  387. type: 'marcher',
  388. count: 0
  389. },
  390. {
  391. type: 'heavy',
  392. count: 0
  393. },
  394. ];
  395.  
  396. } else {
  397. if (haulCategory == 2) {
  398. scavengeOptions = {};
  399. scavengeOptions[greatGatherers] = [
  400. {
  401. type: 'spear',
  402. count: (haul4 * (spears / possibleLoot))
  403. },
  404. {
  405. type: 'sword',
  406. count: (haul4 * (swords / possibleLoot))
  407. },
  408. {
  409. type: 'axe',
  410. count: (haul4 * (axes / possibleLoot))
  411. },
  412. {
  413. type: 'light',
  414. count: (haul4 * (lightC / possibleLoot))
  415. },
  416. {
  417. type: 'heavy',
  418. count: (haul4 * (heavyC / possibleLoot))
  419. },
  420. {
  421. type: 'archer',
  422. count: (haul4 * (archer / possibleLoot))
  423. },
  424. {
  425. type: 'marcher',
  426. count: (haul4 * (marcher / possibleLoot))
  427. },
  428. ];
  429. scavengeOptions[cleverCollectors] = [
  430. {
  431. type: 'spear',
  432. count: (haul3 * (spears / possibleLoot))
  433. },
  434. {
  435. type: 'sword',
  436. count: (haul3 * (swords / possibleLoot))
  437. },
  438. {
  439. type: 'axe',
  440. count: (haul3 * (axes / possibleLoot))
  441. },
  442. {
  443. type: 'light',
  444. count: (haul3 * (lightC / possibleLoot))
  445. },
  446. {
  447. type: 'heavy',
  448. count: (haul3 * (heavyC / possibleLoot))
  449. },
  450. {
  451. type: 'archer',
  452. count: (haul3 * (archer / possibleLoot))
  453. },
  454. {
  455. type: 'marcher',
  456. count: (haul3 * (marcher / possibleLoot))
  457. },
  458. ];
  459. scavengeOptions[humbleHaulers] = [
  460. {
  461. type: 'spear',
  462. count: (haul2 * (spears / possibleLoot))
  463. },
  464. {
  465. type: 'sword',
  466. count: (haul2 * (swords / possibleLoot))
  467. },
  468. {
  469. type: 'axe',
  470. count: (haul2 * (axes / possibleLoot))
  471. },
  472. {
  473. type: 'light',
  474. count: (haul2 * (lightC / possibleLoot))
  475. },
  476. {
  477. type: 'heavy',
  478. count: (haul2 * (heavyC / possibleLoot))
  479. },
  480. {
  481. type: 'archer',
  482. count: (haul2 * (archer / possibleLoot))
  483. },
  484. {
  485. type: 'marcher',
  486. count: (haul2 * (marcher / possibleLoot))
  487. },
  488. ];
  489. scavengeOptions[lackadaisicalLooters] = [
  490. {
  491. type: 'spear',
  492. count: (haul1 * (spears / possibleLoot))
  493. },
  494. {
  495. type: 'sword',
  496. count: (haul1 * (swords / possibleLoot))
  497. },
  498. {
  499. type: 'axe',
  500. count: (haul1 * (axes / possibleLoot))
  501. },
  502. {
  503. type: 'light',
  504. count: (haul1 * (lightC / possibleLoot))
  505. },
  506. {
  507. type: 'heavy',
  508. count: (haul1 * (heavyC / possibleLoot))
  509. },
  510. {
  511. type: 'archer',
  512. count: (haul1 * (archer / possibleLoot))
  513. },
  514. {
  515. type: 'marcher',
  516. count: (haul1 * (marcher / possibleLoot))
  517. },
  518. ];
  519. } else {
  520. if (haulCategory == 3) {
  521. scavengeOptions = {};
  522. scavengeOptions[greatGatherers] = [
  523. {
  524. type: 'spear',
  525. count: ((totalLoot / totalHaul * haul4) * (spears / possibleLoot))
  526. },
  527. {
  528. type: 'sword',
  529. count: ((totalLoot / totalHaul * haul4) * (swords / possibleLoot))
  530. },
  531. {
  532. type: 'axe',
  533. count: ((totalLoot / totalHaul * haul4) * (axes / possibleLoot))
  534. },
  535. {
  536. type: 'light',
  537. count: ((totalLoot / totalHaul * haul4) * (lightC / possibleLoot))
  538. },
  539. {
  540. type: 'heavy',
  541. count: ((totalLoot / totalHaul * haul4) * (heavyC / possibleLoot))
  542. },
  543. {
  544. type: 'archer',
  545. count: ((totalLoot / totalHaul * haul4) * (archer / possibleLoot))
  546. },
  547. {
  548. type: 'marcher',
  549. count: ((totalLoot / totalHaul * haul4) * (marcher / possibleLoot))
  550. },
  551. ];
  552. scavengeOptions[cleverCollectors] = [
  553. {
  554. type: 'spear',
  555. count: ((totalLoot / (totalHaul - haul4) * haul3) * (spears / possibleLoot))
  556. },
  557. {
  558. type: 'sword',
  559. count: ((totalLoot / (totalHaul - haul4) * haul3) * (swords / possibleLoot))
  560. },
  561. {
  562. type: 'axe',
  563. count: ((totalLoot / (totalHaul - haul4) * haul3) * (axes / possibleLoot))
  564. },
  565. {
  566. type: 'light',
  567. count: ((totalLoot / (totalHaul - haul4) * haul3) * (lightC / possibleLoot))
  568. },
  569. {
  570. type: 'heavy',
  571. count: ((totalLoot / (totalHaul - haul4) * haul3) * (heavyC / possibleLoot))
  572. },
  573. {
  574. type: 'archer',
  575. count: ((totalLoot / (totalHaul - haul4) * haul3) * (archer / possibleLoot))
  576. },
  577. {
  578. type: 'marcher',
  579. count: ((totalLoot / (totalHaul - haul4) * haul3) * (marcher / possibleLoot))
  580. },
  581. ];
  582. scavengeOptions[humbleHaulers] = [
  583. {
  584. type: 'spear',
  585. count: ((totalLoot / (totalHaul - haul4 - haul3) * haul2) * (spears / possibleLoot))
  586. },
  587. {
  588. type: 'sword',
  589. count: ((totalLoot / (totalHaul - haul4 - haul3) * haul2) * (swords / possibleLoot))
  590. },
  591. {
  592. type: 'axe',
  593. count: ((totalLoot / (totalHaul - haul4 - haul3) * haul2) * (axes / possibleLoot))
  594. },
  595. {
  596. type: 'light',
  597. count: ((totalLoot / (totalHaul - haul4 - haul3) * haul2) * (lightC / possibleLoot))
  598. },
  599. {
  600. type: 'heavy',
  601. count: ((totalLoot / (totalHaul - haul4 - haul3) * haul2) * (heavyC / possibleLoot))
  602. },
  603. {
  604. type: 'archer',
  605. count: ((totalLoot / (totalHaul - haul4 - haul3) * haul2) * (archer / possibleLoot))
  606. },
  607. {
  608. type: 'marcher',
  609. count: ((totalLoot / (totalHaul - haul4 - haul3) * haul2) * (marcher / possibleLoot))
  610. },
  611. ];
  612. scavengeOptions[lackadaisicalLooters] = [
  613. {
  614. type: 'spear',
  615. count: (totalLoot * (spears / possibleLoot))
  616. },
  617. {
  618. type: 'sword',
  619. count: (totalLoot * (swords / possibleLoot))
  620. },
  621. {
  622. type: 'axe',
  623. count: (totalLoot * (axes / possibleLoot))
  624. },
  625. {
  626. type: 'light',
  627. count: (totalLoot * (lightC / possibleLoot))
  628. },
  629. {
  630. type: 'heavy',
  631. count: (totalLoot * (heavyC / possibleLoot))
  632. },
  633. {
  634. type: 'archer',
  635. count: (totalLoot * (archer / possibleLoot))
  636. },
  637. {
  638. type: 'marcher',
  639. count: (totalLoot * (marcher / possibleLoot))
  640. },
  641. ];
  642. }
  643. }
  644. }
  645.  
  646. run();
  647.  
  648. function run() {
  649. let btn = null;
  650. for (const option in scavengeOptions) {
  651. btn = findNextButton(option);
  652.  
  653. if (btn) {
  654. fillInTroops(option, getAvailableUnits(), btn);
  655. break;
  656. }
  657. }
  658. }
  659.  
  660. function clear() {
  661. let btn = null;
  662. for (const option in scavengeOptions) {
  663. btn = findNextButton(option);
  664. if (btn) {
  665. emptyTroops(option);
  666. break;
  667. }
  668. }
  669. }
  670.  
  671. function fillInTroops(option, availableUnits, button) {
  672. scavengeOptions[option].forEach(units => {
  673. const type = units.type;
  674. const count = units.count;
  675. let requiredCapacity = availableUnits[type] < count ? availableUnits[type] : count;
  676.  
  677. $(`input.unitsInput[name='${type}']`).val(requiredCapacity).trigger("change");
  678. $(button).focus();
  679. });
  680. }
  681.  
  682. function emptyTroops(option) {
  683. scavengeOptions[option].forEach(units => {
  684. const type = units.type;
  685. $(`input.unitsInput[name='${type}']`).val("").trigger("change");
  686. });
  687. }
  688.  
  689. function findNextButton(option) {
  690. startButtonName=document.getElementsByClassName("btn btn-default free_send_button")[0].innerHTML;
  691. let btn = $(`.scavenge-option:contains("${option}")`).find('a:contains('+startButtonName+')');
  692. if (btn.length > 0 && !$(btn).hasClass('btn-disabled')) return btn;
  693. }
  694.  
  695.  
  696. function getAvailableUnits() {
  697. let availableUnits = {};
  698.  
  699. $('.units-entry-all').each((i, e) => {
  700. const unitName = $(e).attr("data-unit");
  701. const count = $(e).text().replace(/[()]/, '');
  702. availableUnits[unitName] = parseInt(count);
  703. });
  704. return availableUnits;
  705. }
  706.  
  707.  
  708. }
  709.  
  710. var o4 = $("#scavenge_screen > div.scavenge-screen-main-widget > div.options-container > div:nth-child(4) > div.status-specific > div > div.action-container > a.btn.btn-default").hasClass("unlock-button");
  711. var o3 = $("#scavenge_screen > div.scavenge-screen-main-widget > div.options-container > div:nth-child(3) > div.status-specific > div > div.action-container > a.btn.btn-default").hasClass("unlock-button");
  712. var o2 = $("#scavenge_screen > div.scavenge-screen-main-widget > div.options-container > div:nth-child(2) > div.status-specific > div > div.action-container > a.btn.btn-default").hasClass("unlock-button");
  713. var o1 = $("#scavenge_screen > div.scavenge-screen-main-widget > div.options-container > div:nth-child(1) > div.status-specific > div > div.action-container > a.btn.btn-default").hasClass("unlock-button");
  714.  
  715. if(!o4 || !o3 || !o2 || !o1){
  716. scavenge();
  717. };
  718.  
  719. //$("#main_layout > tbody > tr.shadedBG").append ( `
  720. $("#scavTable").prepend ( `
  721. <html>
  722. <style>
  723. .button {
  724. background-color: #4CAF50; /* Green */
  725. border: none;
  726. color: white;
  727. padding: 16px 32px;
  728. text-align: center;
  729. text-decoration: none;
  730. display: inline-block;
  731. font-size: 16px;
  732. margin: 4px 2px;
  733. -webkit-transition-duration: 0.4s; /* Safari */
  734. transition-duration: 0.4s;
  735. cursor: pointer;
  736. }
  737.  
  738. .button1 {
  739. background-color: white;
  740. color: black;
  741. border: 2px solid #4CAF50;
  742. }
  743.  
  744. .button1:hover {
  745. background-color: #4CAF50;
  746. color: white;
  747. }
  748.  
  749. .button2 {
  750. background-color: white;
  751. color: black;
  752. border: 2px solid #008CBA;
  753. }
  754.  
  755. .button2:hover {
  756. background-color: #008CBA;
  757. color: white;
  758. }
  759.  
  760. .button3 {
  761. background-color: white;
  762. color: black;
  763. border: 2px solid #f44336;
  764. }
  765.  
  766. .button3:hover {
  767. background-color: #f44336;
  768. color: white;
  769. }
  770.  
  771. .button4 {
  772. background-color: white;
  773. color: black;
  774. border: 2px solid #e7e7e7;
  775. }
  776.  
  777. .button4:hover {background-color: #e7e7e7;}
  778.  
  779. .button5 {
  780. background-color: white;
  781. color: black;
  782. border: 2px solid #555555;
  783. }
  784.  
  785. .button5:hover {
  786. background-color: #555555;
  787. color: white;
  788. }
  789.  
  790. .center1 {
  791. margin: auto;
  792. width: 50%;
  793. border: 3px solid green;
  794. padding: 10px;
  795. }
  796.  
  797.  
  798. .can-toggle {
  799. position: relative;
  800. }
  801. .can-toggle *, .can-toggle *:before, .can-toggle *:after {
  802. box-sizing: border-box;
  803. }
  804. .can-toggle input[type="checkbox"] {
  805. opacity: 0;
  806. position: absolute;
  807. top: 0;
  808. left: 0;
  809. }
  810. .can-toggle input[type="checkbox"][disabled] ~ label {
  811. pointer-events: none;
  812. }
  813. .can-toggle input[type="checkbox"][disabled] ~ label .can-toggle__switch {
  814. opacity: 0.4;
  815. }
  816. .can-toggle input[type="checkbox"]:checked ~ label .can-toggle__switch:before {
  817. content: attr(data-unchecked);
  818. left: 0;
  819. }
  820. .can-toggle input[type="checkbox"]:checked ~ label .can-toggle__switch:after {
  821. content: attr(data-checked);
  822. }
  823. .can-toggle label {
  824. -webkit-user-select: none;
  825. -moz-user-select: none;
  826. -ms-user-select: none;
  827. user-select: none;
  828. position: relative;
  829. display: flex;
  830. align-items: center;
  831. }
  832. .can-toggle label .can-toggle__label-text {
  833. flex: 1;
  834. padding-left: 32px;
  835. }
  836. .can-toggle label .can-toggle__switch {
  837. position: relative;
  838. }
  839. .can-toggle label .can-toggle__switch:before {
  840. content: attr(data-checked);
  841. position: absolute;
  842. top: 0;
  843. text-transform: uppercase;
  844. text-align: center;
  845. }
  846. .can-toggle label .can-toggle__switch:after {
  847. content: attr(data-unchecked);
  848. position: absolute;
  849. z-index: 5;
  850. text-transform: uppercase;
  851. text-align: center;
  852. background: white;
  853. -webkit-transform: translate3d(0, 0, 0);
  854. transform: translate3d(0, 0, 0);
  855. }
  856. .can-toggle input[type="checkbox"][disabled] ~ label {
  857. color: rgba(119, 119, 119, 0.5);
  858. }
  859. .can-toggle input[type="checkbox"]:focus ~ label .can-toggle__switch, .can-toggle input[type="checkbox"]:hover ~ label .can-toggle__switch {
  860. background-color: #777;
  861. }
  862. .can-toggle input[type="checkbox"]:focus ~ label .can-toggle__switch:after, .can-toggle input[type="checkbox"]:hover ~ label .can-toggle__switch:after {
  863. color: #5e5e5e;
  864. }
  865. .can-toggle input[type="checkbox"]:hover ~ label {
  866. color: #6a6a6a;
  867. }
  868. .can-toggle input[type="checkbox"]:checked ~ label:hover {
  869. color: #55bc49;
  870. }
  871. .can-toggle input[type="checkbox"]:checked ~ label .can-toggle__switch {
  872. background-color: #70c767;
  873. }
  874. .can-toggle input[type="checkbox"]:checked ~ label .can-toggle__switch:after {
  875. color: #4fb743;
  876. }
  877. .can-toggle input[type="checkbox"]:checked:focus ~ label .can-toggle__switch, .can-toggle input[type="checkbox"]:checked:hover ~ label .can-toggle__switch {
  878. background-color: #5fc054;
  879. }
  880. .can-toggle input[type="checkbox"]:checked:focus ~ label .can-toggle__switch:after, .can-toggle input[type="checkbox"]:checked:hover ~ label .can-toggle__switch:after {
  881. color: #47a43d;
  882. }
  883. .can-toggle label .can-toggle__label-text {
  884. flex: 1;
  885. }
  886. .can-toggle label .can-toggle__switch {
  887. transition: background-color 0.3s cubic-bezier(0, 1, 0.5, 1);
  888. background: #848484;
  889. }
  890. .can-toggle label .can-toggle__switch:before {
  891. color: rgba(255, 255, 255, 0.5);
  892. }
  893. .can-toggle label .can-toggle__switch:after {
  894. transition: -webkit-transform 0.3s cubic-bezier(0, 1, 0.5, 1);
  895. transition: transform 0.3s cubic-bezier(0, 1, 0.5, 1);
  896. transition: transform 0.3s cubic-bezier(0, 1, 0.5, 1), -webkit-transform 0.3s cubic-bezier(0, 1, 0.5, 1);
  897. color: #777;
  898. }
  899. .can-toggle input[type="checkbox"]:focus ~ label .can-toggle__switch:after, .can-toggle input[type="checkbox"]:hover ~ label .can-toggle__switch:after {
  900. box-shadow: 0 3px 3px rgba(0, 0, 0, 0.4);
  901. }
  902. .can-toggle input[type="checkbox"]:checked ~ label .can-toggle__switch:after {
  903. -webkit-transform: translate3d(65px, 0, 0);
  904. transform: translate3d(65px, 0, 0);
  905. }
  906. .can-toggle input[type="checkbox"]:checked:focus ~ label .can-toggle__switch:after, .can-toggle input[type="checkbox"]:checked:hover ~ label .can-toggle__switch:after {
  907. box-shadow: 0 3px 3px rgba(0, 0, 0, 0.4);
  908. }
  909. .can-toggle label {
  910. font-size: 14px;
  911. }
  912. .can-toggle label .can-toggle__switch {
  913. height: 36px;
  914. flex: 0 0 134px;
  915. border-radius: 4px;
  916. }
  917. .can-toggle label .can-toggle__switch:before {
  918. left: 67px;
  919. font-size: 12px;
  920. line-height: 36px;
  921. width: 67px;
  922. padding: 0 12px;
  923. }
  924. .can-toggle label .can-toggle__switch:after {
  925. top: 2px;
  926. left: 2px;
  927. border-radius: 2px;
  928. width: 65px;
  929. line-height: 32px;
  930. font-size: 12px;
  931. }
  932. .can-toggle label .can-toggle__switch:hover:after {
  933. box-shadow: 0 3px 3px rgba(0, 0, 0, 0.4);
  934. }
  935. .can-toggle.can-toggle--size-small input[type="checkbox"]:focus ~ label .can-toggle__switch:after, .can-toggle.can-toggle--size-small input[type="checkbox"]:hover ~ label .can-toggle__switch:after {
  936. box-shadow: 0 2px 2px rgba(0, 0, 0, 0.4);
  937. }
  938. .can-toggle.can-toggle--size-small input[type="checkbox"]:checked ~ label .can-toggle__switch:after {
  939. -webkit-transform: translate3d(44px, 0, 0);
  940. transform: translate3d(44px, 0, 0);
  941. }
  942. .can-toggle.can-toggle--size-small input[type="checkbox"]:checked:focus ~ label .can-toggle__switch:after, .can-toggle.can-toggle--size-small input[type="checkbox"]:checked:hover ~ label .can-toggle__switch:after {
  943. box-shadow: 0 2px 2px rgba(0, 0, 0, 0.4);
  944. }
  945. .can-toggle.can-toggle--size-small label {
  946. font-size: 13px;
  947. }
  948. .can-toggle.can-toggle--size-small label .can-toggle__switch {
  949. height: 28px;
  950. flex: 0 0 90px;
  951. border-radius: 2px;
  952. }
  953. .can-toggle.can-toggle--size-small label .can-toggle__switch:before {
  954. left: 45px;
  955. font-size: 10px;
  956. line-height: 28px;
  957. width: 45px;
  958. padding: 0 12px;
  959. }
  960. .can-toggle.can-toggle--size-small label .can-toggle__switch:after {
  961. top: 1px;
  962. left: 1px;
  963. border-radius: 1px;
  964. width: 44px;
  965. line-height: 26px;
  966. font-size: 10px;
  967. }
  968. .can-toggle.can-toggle--size-small label .can-toggle__switch:hover:after {
  969. box-shadow: 0 2px 2px rgba(0, 0, 0, 0.4);
  970. }
  971. .can-toggle.can-toggle--size-large input[type="checkbox"]:focus ~ label .can-toggle__switch:after, .can-toggle.can-toggle--size-large input[type="checkbox"]:hover ~ label .can-toggle__switch:after {
  972. box-shadow: 0 4px 4px rgba(0, 0, 0, 0.4);
  973. }
  974. .can-toggle.can-toggle--size-large input[type="checkbox"]:checked ~ label .can-toggle__switch:after {
  975. -webkit-transform: translate3d(78px, 0, 0);
  976. transform: translate3d(78px, 0, 0);
  977. }
  978. .can-toggle.can-toggle--size-large input[type="checkbox"]:checked:focus ~ label .can-toggle__switch:after, .can-toggle.can-toggle--size-large input[type="checkbox"]:checked:hover ~ label .can-toggle__switch:after {
  979. box-shadow: 0 4px 4px rgba(0, 0, 0, 0.4);
  980. }
  981. .can-toggle.can-toggle--size-large label {
  982. font-size: 14px;
  983. }
  984. .can-toggle.can-toggle--size-large label .can-toggle__switch {
  985. height: 50px;
  986. flex: 0 0 160px;
  987. border-radius: 4px;
  988. }
  989. .can-toggle.can-toggle--size-large label .can-toggle__switch:before {
  990. left: 80px;
  991. font-size: 14px;
  992. line-height: 50px;
  993. width: 80px;
  994. padding: 0 12px;
  995. }
  996. .can-toggle.can-toggle--size-large label .can-toggle__switch:after {
  997. top: 2px;
  998. left: 2px;
  999. border-radius: 2px;
  1000. width: 78px;
  1001. line-height: 46px;
  1002. font-size: 14px;
  1003. }
  1004. .can-toggle.can-toggle--size-large label .can-toggle__switch:hover:after {
  1005. box-shadow: 0 4px 4px rgba(0, 0, 0, 0.4);
  1006. }
  1007. .can-toggle.demo-rebrand-1 input[type="checkbox"][disabled] ~ label {
  1008. color: rgba(181, 62, 116, 0.5);
  1009. }
  1010. .can-toggle.demo-rebrand-1 input[type="checkbox"]:focus ~ label .can-toggle__switch, .can-toggle.demo-rebrand-1 input[type="checkbox"]:hover ~ label .can-toggle__switch {
  1011. background-color: #b53e74;
  1012. }
  1013. .can-toggle.demo-rebrand-1 input[type="checkbox"]:focus ~ label .can-toggle__switch:after, .can-toggle.demo-rebrand-1 input[type="checkbox"]:hover ~ label .can-toggle__switch:after {
  1014. color: #8f315c;
  1015. }
  1016. .can-toggle.demo-rebrand-1 input[type="checkbox"]:hover ~ label {
  1017. color: #a23768;
  1018. }
  1019. .can-toggle.demo-rebrand-1 input[type="checkbox"]:checked ~ label:hover {
  1020. color: #39916a;
  1021. }
  1022. .can-toggle.demo-rebrand-1 input[type="checkbox"]:checked ~ label .can-toggle__switch {
  1023. background-color: #44ae7f;
  1024. }
  1025. .can-toggle.demo-rebrand-1 input[type="checkbox"]:checked ~ label .can-toggle__switch:after {
  1026. color: #368a65;
  1027. }
  1028. .can-toggle.demo-rebrand-1 input[type="checkbox"]:checked:focus ~ label .can-toggle__switch, .can-toggle.demo-rebrand-1 input[type="checkbox"]:checked:hover ~ label .can-toggle__switch {
  1029. background-color: #3d9c72;
  1030. }
  1031. .can-toggle.demo-rebrand-1 input[type="checkbox"]:checked:focus ~ label .can-toggle__switch:after, .can-toggle.demo-rebrand-1 input[type="checkbox"]:checked:hover ~ label .can-toggle__switch:after {
  1032. color: #2f7757;
  1033. }
  1034. .can-toggle.demo-rebrand-1 label .can-toggle__label-text {
  1035. flex: 1;
  1036. }
  1037. .can-toggle.demo-rebrand-1 label .can-toggle__switch {
  1038. transition: background-color 0.3s ease-in-out;
  1039. background: #c14b81;
  1040. }
  1041. .can-toggle.demo-rebrand-1 label .can-toggle__switch:before {
  1042. color: rgba(255, 255, 255, 0.6);
  1043. }
  1044. .can-toggle.demo-rebrand-1 label .can-toggle__switch:after {
  1045. transition: -webkit-transform 0.3s ease-in-out;
  1046. transition: transform 0.3s ease-in-out;
  1047. transition: transform 0.3s ease-in-out, -webkit-transform 0.3s ease-in-out;
  1048. color: #b53e74;
  1049. }
  1050. .can-toggle.demo-rebrand-2 input[type="checkbox"][disabled] ~ label {
  1051. color: rgba(68, 68, 68, 0.5);
  1052. }
  1053. .can-toggle.demo-rebrand-2 input[type="checkbox"]:focus ~ label .can-toggle__switch, .can-toggle.demo-rebrand-2 input[type="checkbox"]:hover ~ label .can-toggle__switch {
  1054. background-color: #444;
  1055. }
  1056. .can-toggle.demo-rebrand-2 input[type="checkbox"]:focus ~ label .can-toggle__switch:after, .can-toggle.demo-rebrand-2 input[type="checkbox"]:hover ~ label .can-toggle__switch:after {
  1057. color: #2b2b2b;
  1058. }
  1059. .can-toggle.demo-rebrand-2 input[type="checkbox"]:hover ~ label {
  1060. color: #373737;
  1061. }
  1062. .can-toggle.demo-rebrand-2 input[type="checkbox"]:checked ~ label:hover {
  1063. color: #62b125;
  1064. }
  1065. .can-toggle.demo-rebrand-2 input[type="checkbox"]:checked ~ label .can-toggle__switch {
  1066. background-color: #75d32d;
  1067. }
  1068. .can-toggle.demo-rebrand-2 input[type="checkbox"]:checked ~ label .can-toggle__switch:after {
  1069. color: #5da924;
  1070. }
  1071. .can-toggle.demo-rebrand-2 input[type="checkbox"]:checked:focus ~ label .can-toggle__switch, .can-toggle.demo-rebrand-2 input[type="checkbox"]:checked:hover ~ label .can-toggle__switch {
  1072. background-color: #69be28;
  1073. }
  1074. .can-toggle.demo-rebrand-2 input[type="checkbox"]:checked:focus ~ label .can-toggle__switch:after, .can-toggle.demo-rebrand-2 input[type="checkbox"]:checked:hover ~ label .can-toggle__switch:after {
  1075. color: #52941f;
  1076. }
  1077. .can-toggle.demo-rebrand-2 label .can-toggle__label-text {
  1078. flex: 1;
  1079. }
  1080. .can-toggle.demo-rebrand-2 label .can-toggle__switch {
  1081. transition: background-color 0.3s cubic-bezier(0.86, 0, 0.07, 1);
  1082. background: #515151;
  1083. }
  1084. .can-toggle.demo-rebrand-2 label .can-toggle__switch:before {
  1085. color: rgba(255, 255, 255, 0.7);
  1086. }
  1087. .can-toggle.demo-rebrand-2 label .can-toggle__switch:after {
  1088. transition: -webkit-transform 0.3s cubic-bezier(0.86, 0, 0.07, 1);
  1089. transition: transform 0.3s cubic-bezier(0.86, 0, 0.07, 1);
  1090. transition: transform 0.3s cubic-bezier(0.86, 0, 0.07, 1), -webkit-transform 0.3s cubic-bezier(0.86, 0, 0.07, 1);
  1091. color: #444;
  1092. }
  1093. .can-toggle.demo-rebrand-2 input[type="checkbox"]:focus ~ label .can-toggle__switch:after, .can-toggle.demo-rebrand-2 input[type="checkbox"]:hover ~ label .can-toggle__switch:after {
  1094. box-shadow: 0 4px 4px rgba(0, 0, 0, 0.4);
  1095. }
  1096. .can-toggle.demo-rebrand-2 input[type="checkbox"]:checked ~ label .can-toggle__switch:after {
  1097. -webkit-transform: translate3d(58px, 0, 0);
  1098. transform: translate3d(58px, 0, 0);
  1099. }
  1100. .can-toggle.demo-rebrand-2 input[type="checkbox"]:checked:focus ~ label .can-toggle__switch:after, .can-toggle.demo-rebrand-2 input[type="checkbox"]:checked:hover ~ label .can-toggle__switch:after {
  1101. box-shadow: 0 4px 4px rgba(0, 0, 0, 0.4);
  1102. }
  1103. .can-toggle.demo-rebrand-2 label {
  1104. font-size: 13px;
  1105. }
  1106. .can-toggle.demo-rebrand-2 label .can-toggle__switch {
  1107. height: 60px;
  1108. flex: 0 0 120px;
  1109. border-radius: 60px;
  1110. }
  1111. .can-toggle.demo-rebrand-2 label .can-toggle__switch:before {
  1112. left: 60px;
  1113. font-size: 13px;
  1114. line-height: 60px;
  1115. width: 60px;
  1116. padding: 0 12px;
  1117. }
  1118. .can-toggle.demo-rebrand-2 label .can-toggle__switch:after {
  1119. top: 2px;
  1120. left: 2px;
  1121. border-radius: 30px;
  1122. width: 58px;
  1123. line-height: 56px;
  1124. font-size: 13px;
  1125. }
  1126. .can-toggle.demo-rebrand-2 label .can-toggle__switch:hover:after {
  1127. box-shadow: 0 4px 4px rgba(0, 0, 0, 0.4);
  1128. }
  1129.  
  1130. </style>
  1131. <div class="center" width="100%">
  1132. <h2>Assistente de buscas</h2>
  1133. <p>Pressione o botão para enviar o exército para a busca</p>
  1134. <div class="can-toggle can-toggle--size-large">
  1135. <input id="c" type="checkbox">
  1136. <label for="c">
  1137. <div class="can-toggle__switch" data-checked="Auto" data-unchecked="Off"></div>
  1138. <button class="button button1" id="greenbutton">Guardar</button>
  1139. <button class="button button2" id="delbutton">Reset</button>
  1140. </div>
  1141. <br>
  1142. </html>
  1143.  
  1144. ` );
  1145.  
  1146. if (localStorage.getItem("attempts") === null) {
  1147. localStorage.setItem("attempts", "0");
  1148. } else {
  1149. var vil = parseInt(game_data.player.villages);
  1150. var attempts = Number(localStorage.getItem("attempts"));
  1151. localStorage.setItem("attempts", ++attempts);
  1152.  
  1153. document.title = "Enviado " + attempts + "/" + vil;
  1154. };
  1155.  
  1156. $("#delbutton").click(function() {
  1157. localStorage.setItem("attempts", parseInt(0));
  1158. });
  1159.  
  1160. $("#greenbutton").click(function() {
  1161. function scavenge() {
  1162.  
  1163. //checking correct page
  1164. const doc = document;
  1165. if (window.frames.length > 0 && window.main != null) doc = window.main.document;
  1166.  
  1167. if (window.location.href.indexOf('screen=place&mode=scavenge') < 0) {
  1168. window.location.assign(game_data.link_base_pure + "place&mode=scavenge");
  1169. }
  1170. var lackadaisicalLooters = document.getElementsByClassName("title")[0].innerHTML;
  1171. var humbleHaulers = document.getElementsByClassName("title")[1].innerHTML;
  1172. var cleverCollectors = document.getElementsByClassName("title")[2].innerHTML;
  1173. var greatGatherers = document.getElementsByClassName("title")[3].innerHTML;
  1174. var scavengeInfo = JSON.parse($('html').find('script:contains("ScavengeScreen")').html().match(/\{.*\:\{.*\:.*\}\}/g)[1]);
  1175. var duration_factor = scavengeInfo[1].duration_factor;
  1176. var duration_exponent = scavengeInfo[1].duration_exponent;
  1177. var duration_initial_seconds = scavengeInfo[1].duration_initial_seconds;
  1178. //var loot_factor = scavengeInfo[1].loot_factor
  1179.  
  1180.  
  1181.  
  1182.  
  1183. function setScavTime() {
  1184. //check if duration is preset already
  1185. if ("ScavengeTime" in sessionStorage) {
  1186. hours = parseInt(sessionStorage.getItem("ScavengeTime"));
  1187.  
  1188. } else {
  1189. hours = 24;
  1190. }
  1191. sessionStorage.setItem("ScavengeTime", hours);
  1192.  
  1193.  
  1194. }
  1195. setScavTime();
  1196.  
  1197.  
  1198. if ($('button').length == 0) {
  1199. //create interface and button
  1200. haulCategory = 0;
  1201. sessionStorage.setItem("haulCategory", haulCategory);
  1202. button = document.createElement("button");
  1203. button.classList.add("btn-confirm-yes");
  1204. button.innerHTML = "Adjust scavenge time";
  1205. button.style.visibility = 'hidden';
  1206. body = document.getElementById("scavenge_screen");
  1207. body.prepend(button);
  1208.  
  1209. scavDiv = document.createElement('div');
  1210. //check if archer world or not, depending on outcome make table with or without archers
  1211. if ($('.units-entry-all[data-unit=archer]').text() != "") {
  1212. htmlString = '<div class = center ID= scavTable >\
  1213. <table class="center" width="30%" 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);">\
  1214. <tbody>\
  1215. <tr>\
  1216. <th style="text-align:center" colspan="8">Escolha as unidades a enviar</th>\
  1217. </tr>\
  1218. <tr>\
  1219. <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>\
  1220. <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>\
  1221. <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>\
  1222. <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>\
  1223. <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>\
  1224. <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>\
  1225. <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>\
  1226. <th style="text-align:center" nowrap>Duração</th>\
  1227. </tr>\
  1228. <tr>\
  1229. <td align="center"><input type="checkbox" ID="spear" name="spear" checked = "checked" ></td>\
  1230. <td align="center"><input type="checkbox" ID="sword" name="sword" checked = "checked" ></td>\
  1231. <td align="center"><input type="checkbox" ID="axe" name="axe" checked = "checked" ></td>\
  1232. <td align="center"><input type="checkbox" ID="archer" name="archer" checked = "checked" ></td>\
  1233. <td align="center"><input type="checkbox" ID="light" name="light" checked = "checked" ></td>\
  1234. <td align="center"><input type="checkbox" ID="marcher" name="marcher" checked = "checked" ></td>\
  1235. <td align="center"><input type="checkbox" ID="heavy" name="heavy" checked = "checked" ></td>\
  1236. <td ID="runtime" align="center"><input type="text" ID="hours" name="hours" size="4" maxlength="2" align=left > hours</td>\
  1237. </tbody>\
  1238. </table>\
  1239. </br>\
  1240. </div>\
  1241. ';
  1242. } else {
  1243. htmlString = '<div class = center ID= scavTable>\
  1244. <table class="center" width="30%" 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);">\
  1245. <tbody>\
  1246. <tr>\
  1247. <th style="text-align:center" colspan="6">Escolha as unidades a enviar</th>\
  1248. </tr>\
  1249. <tr>\
  1250. <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>\
  1251. <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>\
  1252. <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>\
  1253. <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>\
  1254. <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>\
  1255. <th style="text-align:center" nowrap>Duração</th>\
  1256. </tr>\
  1257. <tr>\
  1258. <td align="center"><input type="checkbox" ID="spear" name="spear"></td>\
  1259. <td align="center"><input type="checkbox" ID="sword" name="sword" ></td>\
  1260. <td align="center"><input type="checkbox" ID="axe" name="axe" ></td>\
  1261. <td align="center"><input type="checkbox" ID="light" name="light" ></td>\
  1262. <td align="center"><input type="checkbox" ID="heavy" name="heavy" ></td>\
  1263. <td ID="runtime" align="center"><input type="text" ID="hours" name="hours" size="4" maxlength="2" align=left > hours</td>\
  1264. </tbody>\
  1265. </table>\
  1266. </br>\
  1267. </div>\
  1268. ';
  1269. }
  1270. scavDiv.innerHTML = htmlString;
  1271. scavenge_screen.prepend(scavDiv.firstChild);
  1272. document.getElementById("hours").value = hours;
  1273. document.getElementById("hours").addEventListener("change", function () {
  1274. hours = parseInt(document.getElementById("hours").value);
  1275. sessionStorage.setItem("ScavengeTime", hours);
  1276. haulCategory=0;
  1277. sessionStorage.setItem("haulCategory", haulCategory);
  1278. calculateHauls();
  1279. clear();
  1280. setScavTime();
  1281. scavenge();
  1282. document.getElementById("hours").focus();
  1283. });
  1284. }
  1285.  
  1286. if ($(".scavengeTable")[0]) {
  1287. document.getElementById("hours").value = hours;
  1288. }
  1289.  
  1290. checkboxValues = JSON.parse(localStorage.getItem('checkboxValues')) || {}, $checkboxes = $("#scavTable :checkbox");
  1291. $checkboxes.on("change", function () {
  1292. $checkboxes.each(function () {
  1293. checkboxValues[this.id] = this.checked;
  1294. });
  1295. localStorage.setItem("checkboxValues", JSON.stringify(checkboxValues));
  1296. calculateHauls();
  1297. haulCategory = 0;
  1298. sessionStorage.setItem("haulCategory", haulCategory);
  1299. scavenge();
  1300. });
  1301.  
  1302. $.each(checkboxValues, function (key, value) {
  1303. $("#" + key).prop('checked', value);
  1304. });
  1305.  
  1306.  
  1307. if ($(".scavengeTable").length) {
  1308. spears = $('.units-entry-all[data-unit=spear]').text().match(/\((\d+)\)/)[1];
  1309. swords = $('.units-entry-all[data-unit=sword]').text().match(/\((\d+)\)/)[1];
  1310. axes = $('.units-entry-all[data-unit=axe]').text().match(/\((\d+)\)/)[1];
  1311. lightC = $('.units-entry-all[data-unit=light]').text().match(/\((\d+)\)/)[1];
  1312. heavyC = $('.units-entry-all[data-unit=heavy]').text().match(/\((\d+)\)/)[1];
  1313. if ($('.units-entry-all[data-unit=archer]').text() != "") {
  1314. archer = $('.units-entry-all[data-unit=archer]').text().match(/\((\d+)\)/)[1]
  1315. } else archer = 0;
  1316.  
  1317. if ($('.units-entry-all[data-unit=marcher]').text() != "") {
  1318. marcher = $('.units-entry-all[data-unit=marcher]').text().match(/\((\d+)\)/)[1]
  1319. } else marcher = 0;
  1320. checkboxStatus();
  1321. }
  1322. else {
  1323. spears = $('.units-entry-all[data-unit=spear]').text().match(/\((\d+)\)/)[1];
  1324. swords = $('.units-entry-all[data-unit=sword]').text().match(/\((\d+)\)/)[1];
  1325. axes = $('.units-entry-all[data-unit=axe]').text().match(/\((\d+)\)/)[1];
  1326. lightC = $('.units-entry-all[data-unit=light]').text().match(/\((\d+)\)/)[1];
  1327. heavyC = $('.units-entry-all[data-unit=heavy]').text().match(/\((\d+)\)/)[1];
  1328. if ($('.units-entry-all[data-unit=archer]').text() != "") {
  1329. archer = $('.units-entry-all[data-unit=archer]').text().match(/\((\d+)\)/)[1]
  1330. } else archer = 0;
  1331.  
  1332. if ($('.units-entry-all[data-unit=marcher]').text() != "") {
  1333. marcher = $('.units-entry-all[data-unit=marcher]').text().match(/\((\d+)\)/)[1]
  1334. } else marcher = 0;
  1335. }
  1336.  
  1337. function checkboxStatus() {
  1338. if (document.getElementById("spear").checked == false) {
  1339. spears = 0;
  1340. haulcategory = 0;
  1341. }
  1342. if (document.getElementById("sword").checked == false) {
  1343. swords = 0;
  1344. haulcategory = 0;
  1345. }
  1346. if (document.getElementById("axe").checked == false) {
  1347. axes = 0;
  1348. haulcategory = 0;
  1349. }
  1350. if (document.getElementById("light").checked == false) {
  1351. lightC = 0;
  1352. haulcategory = 0;
  1353. }
  1354. if (document.getElementById("heavy").checked == false) {
  1355. heavyC = 0;
  1356. haulcategory = 0;
  1357. }
  1358. if ($('.units-entry-all[data-unit=archer]').text() != "") {
  1359. if (document.getElementById("archer").checked == false) {
  1360. archer = 0;
  1361. haulcategory = 0;
  1362. }
  1363. }
  1364. if ($('.units-entry-all[data-unit=marcher]').text() != "") {
  1365. if (document.getElementById("marcher").checked == false) {
  1366. marcher = 0;
  1367. haulcategory = 0;
  1368. }
  1369. }
  1370.  
  1371. }
  1372.  
  1373.  
  1374. function calculateHauls() {
  1375.  
  1376. checkboxStatus();
  1377.  
  1378. totalLoot = spears * 25 + swords * 15 + axes * 10 + lightC * 80 + heavyC * 50 + archer * 10 + marcher * 50;
  1379. totalSpSwLoot = spears * 25 + swords * 15;
  1380. possibleLoot = spears * 25 + swords * 15 + axes * 10 + lightC * 80 + heavyC * 50 + archer * 10 + marcher * 50;
  1381. spearRatio = spears / (spears * 25 + swords * 15);
  1382. swordRatio = swords / (spears * 25 + swords * 15);
  1383.  
  1384. time = hours * 3600;
  1385. haul = ((time / duration_factor - duration_initial_seconds) ** (1 / (duration_exponent)) / 100) ** (1 / 2);
  1386. haul1 = haul / 0.1;
  1387. haul2 = haul / 0.25;
  1388. haul3 = haul / 0.5;
  1389. haul4 = haul / 0.75;
  1390. totalHaul = haul1 + haul2 + haul3 + haul4;
  1391.  
  1392. }
  1393. calculateHauls();
  1394.  
  1395. if ("haulCategory" in sessionStorage) {
  1396. haulCategory = sessionStorage.getItem("haulCategory");
  1397. } else {
  1398. haulCategory = 0;
  1399. sessionStorage.setItem("haulCategory", haulCategory);
  1400. }
  1401.  
  1402.  
  1403. if (totalLoot > totalHaul) {
  1404. if (totalSpSwLoot > totalHaul) {
  1405. if (haulCategory == 0) {
  1406. haulCategory = 1;
  1407. sessionStorage.setItem("haulCategory", haulCategory);
  1408. }
  1409. } else {
  1410. if (haulCategory == 0) {
  1411. haulCategory = 2;
  1412. sessionStorage.setItem("haulCategory", haulCategory);
  1413. }
  1414. }
  1415. } else {
  1416. if (haulCategory == 0) {
  1417. haulCategory = 3;
  1418. sessionStorage.setItem("haulCategory", haulCategory);
  1419. }
  1420. }
  1421.  
  1422. if (haulCategory == 1) {
  1423. scavengeOptions = {};
  1424. scavengeOptions[greatGatherers] = [
  1425. {
  1426. type: 'spear',
  1427. count: (haul4 * spearRatio)
  1428. },
  1429. {
  1430. type: 'sword',
  1431. count: (haul4 * swordRatio)
  1432. },
  1433. {
  1434. type: 'axe',
  1435. count: 0
  1436. },
  1437. {
  1438. type: 'archer',
  1439. count: 0
  1440. },
  1441. {
  1442. type: 'light',
  1443. count: 0
  1444. },
  1445. {
  1446. type: 'marcher',
  1447. count: 0
  1448. },
  1449. {
  1450. type: 'heavy',
  1451. count: 0
  1452. },
  1453. ];
  1454. scavengeOptions[cleverCollectors] = [
  1455. {
  1456. type: 'spear',
  1457. count: (haul3 * spearRatio)
  1458. },
  1459. {
  1460. type: 'sword',
  1461. count: (haul3 * swordRatio)
  1462. },
  1463. {
  1464. type: 'axe',
  1465. count: 0
  1466. },
  1467. {
  1468. type: 'archer',
  1469. count: 0
  1470. },
  1471. {
  1472. type: 'light',
  1473. count: 0
  1474. },
  1475. {
  1476. type: 'marcher',
  1477. count: 0
  1478. },
  1479. {
  1480. type: 'heavy',
  1481. count: 0
  1482. },
  1483. ];
  1484. scavengeOptions[humbleHaulers] = [
  1485. {
  1486. type: 'spear',
  1487. count: (haul2 * spearRatio)
  1488. },
  1489. {
  1490. type: 'sword',
  1491. count: (haul2 * swordRatio)
  1492. },
  1493. {
  1494. type: 'axe',
  1495. count: 0
  1496. },
  1497. {
  1498. type: 'archer',
  1499. count: 0
  1500. },
  1501. {
  1502. type: 'light',
  1503. count: 0
  1504. },
  1505. {
  1506. type: 'marcher',
  1507. count: 0
  1508. },
  1509. {
  1510. type: 'heavy',
  1511. count: 0
  1512. },
  1513. ];
  1514. scavengeOptions[lackadaisicalLooters] = [
  1515. {
  1516. type: 'spear',
  1517. count: (haul1 * spearRatio)
  1518. },
  1519. {
  1520. type: 'sword',
  1521. count: (haul1 * swordRatio)
  1522. },
  1523. {
  1524. type: 'axe',
  1525. count: 0
  1526. },
  1527. {
  1528. type: 'archer',
  1529. count: 0
  1530. },
  1531. {
  1532. type: 'light',
  1533. count: 0
  1534. },
  1535. {
  1536. type: 'marcher',
  1537. count: 0
  1538. },
  1539. {
  1540. type: 'heavy',
  1541. count: 0
  1542. },
  1543. ];
  1544.  
  1545. } else {
  1546. if (haulCategory == 2) {
  1547. scavengeOptions = {};
  1548. scavengeOptions[greatGatherers] = [
  1549. {
  1550. type: 'spear',
  1551. count: (haul4 * (spears / possibleLoot))
  1552. },
  1553. {
  1554. type: 'sword',
  1555. count: (haul4 * (swords / possibleLoot))
  1556. },
  1557. {
  1558. type: 'axe',
  1559. count: (haul4 * (axes / possibleLoot))
  1560. },
  1561. {
  1562. type: 'light',
  1563. count: (haul4 * (lightC / possibleLoot))
  1564. },
  1565. {
  1566. type: 'heavy',
  1567. count: (haul4 * (heavyC / possibleLoot))
  1568. },
  1569. {
  1570. type: 'archer',
  1571. count: (haul4 * (archer / possibleLoot))
  1572. },
  1573. {
  1574. type: 'marcher',
  1575. count: (haul4 * (marcher / possibleLoot))
  1576. },
  1577. ];
  1578. scavengeOptions[cleverCollectors] = [
  1579. {
  1580. type: 'spear',
  1581. count: (haul3 * (spears / possibleLoot))
  1582. },
  1583. {
  1584. type: 'sword',
  1585. count: (haul3 * (swords / possibleLoot))
  1586. },
  1587. {
  1588. type: 'axe',
  1589. count: (haul3 * (axes / possibleLoot))
  1590. },
  1591. {
  1592. type: 'light',
  1593. count: (haul3 * (lightC / possibleLoot))
  1594. },
  1595. {
  1596. type: 'heavy',
  1597. count: (haul3 * (heavyC / possibleLoot))
  1598. },
  1599. {
  1600. type: 'archer',
  1601. count: (haul3 * (archer / possibleLoot))
  1602. },
  1603. {
  1604. type: 'marcher',
  1605. count: (haul3 * (marcher / possibleLoot))
  1606. },
  1607. ];
  1608. scavengeOptions[humbleHaulers] = [
  1609. {
  1610. type: 'spear',
  1611. count: (haul2 * (spears / possibleLoot))
  1612. },
  1613. {
  1614. type: 'sword',
  1615. count: (haul2 * (swords / possibleLoot))
  1616. },
  1617. {
  1618. type: 'axe',
  1619. count: (haul2 * (axes / possibleLoot))
  1620. },
  1621. {
  1622. type: 'light',
  1623. count: (haul2 * (lightC / possibleLoot))
  1624. },
  1625. {
  1626. type: 'heavy',
  1627. count: (haul2 * (heavyC / possibleLoot))
  1628. },
  1629. {
  1630. type: 'archer',
  1631. count: (haul2 * (archer / possibleLoot))
  1632. },
  1633. {
  1634. type: 'marcher',
  1635. count: (haul2 * (marcher / possibleLoot))
  1636. },
  1637. ];
  1638. scavengeOptions[lackadaisicalLooters] = [
  1639. {
  1640. type: 'spear',
  1641. count: (haul1 * (spears / possibleLoot))
  1642. },
  1643. {
  1644. type: 'sword',
  1645. count: (haul1 * (swords / possibleLoot))
  1646. },
  1647. {
  1648. type: 'axe',
  1649. count: (haul1 * (axes / possibleLoot))
  1650. },
  1651. {
  1652. type: 'light',
  1653. count: (haul1 * (lightC / possibleLoot))
  1654. },
  1655. {
  1656. type: 'heavy',
  1657. count: (haul1 * (heavyC / possibleLoot))
  1658. },
  1659. {
  1660. type: 'archer',
  1661. count: (haul1 * (archer / possibleLoot))
  1662. },
  1663. {
  1664. type: 'marcher',
  1665. count: (haul1 * (marcher / possibleLoot))
  1666. },
  1667. ];
  1668. } else {
  1669. if (haulCategory == 3) {
  1670. scavengeOptions = {};
  1671. scavengeOptions[greatGatherers] = [
  1672. {
  1673. type: 'spear',
  1674. count: ((totalLoot / totalHaul * haul4) * (spears / possibleLoot))
  1675. },
  1676. {
  1677. type: 'sword',
  1678. count: ((totalLoot / totalHaul * haul4) * (swords / possibleLoot))
  1679. },
  1680. {
  1681. type: 'axe',
  1682. count: ((totalLoot / totalHaul * haul4) * (axes / possibleLoot))
  1683. },
  1684. {
  1685. type: 'light',
  1686. count: ((totalLoot / totalHaul * haul4) * (lightC / possibleLoot))
  1687. },
  1688. {
  1689. type: 'heavy',
  1690. count: ((totalLoot / totalHaul * haul4) * (heavyC / possibleLoot))
  1691. },
  1692. {
  1693. type: 'archer',
  1694. count: ((totalLoot / totalHaul * haul4) * (archer / possibleLoot))
  1695. },
  1696. {
  1697. type: 'marcher',
  1698. count: ((totalLoot / totalHaul * haul4) * (marcher / possibleLoot))
  1699. },
  1700. ];
  1701. scavengeOptions[cleverCollectors] = [
  1702. {
  1703. type: 'spear',
  1704. count: ((totalLoot / (totalHaul - haul4) * haul3) * (spears / possibleLoot))
  1705. },
  1706. {
  1707. type: 'sword',
  1708. count: ((totalLoot / (totalHaul - haul4) * haul3) * (swords / possibleLoot))
  1709. },
  1710. {
  1711. type: 'axe',
  1712. count: ((totalLoot / (totalHaul - haul4) * haul3) * (axes / possibleLoot))
  1713. },
  1714. {
  1715. type: 'light',
  1716. count: ((totalLoot / (totalHaul - haul4) * haul3) * (lightC / possibleLoot))
  1717. },
  1718. {
  1719. type: 'heavy',
  1720. count: ((totalLoot / (totalHaul - haul4) * haul3) * (heavyC / possibleLoot))
  1721. },
  1722. {
  1723. type: 'archer',
  1724. count: ((totalLoot / (totalHaul - haul4) * haul3) * (archer / possibleLoot))
  1725. },
  1726. {
  1727. type: 'marcher',
  1728. count: ((totalLoot / (totalHaul - haul4) * haul3) * (marcher / possibleLoot))
  1729. },
  1730. ];
  1731. scavengeOptions[humbleHaulers] = [
  1732. {
  1733. type: 'spear',
  1734. count: ((totalLoot / (totalHaul - haul4 - haul3) * haul2) * (spears / possibleLoot))
  1735. },
  1736. {
  1737. type: 'sword',
  1738. count: ((totalLoot / (totalHaul - haul4 - haul3) * haul2) * (swords / possibleLoot))
  1739. },
  1740. {
  1741. type: 'axe',
  1742. count: ((totalLoot / (totalHaul - haul4 - haul3) * haul2) * (axes / possibleLoot))
  1743. },
  1744. {
  1745. type: 'light',
  1746. count: ((totalLoot / (totalHaul - haul4 - haul3) * haul2) * (lightC / possibleLoot))
  1747. },
  1748. {
  1749. type: 'heavy',
  1750. count: ((totalLoot / (totalHaul - haul4 - haul3) * haul2) * (heavyC / possibleLoot))
  1751. },
  1752. {
  1753. type: 'archer',
  1754. count: ((totalLoot / (totalHaul - haul4 - haul3) * haul2) * (archer / possibleLoot))
  1755. },
  1756. {
  1757. type: 'marcher',
  1758. count: ((totalLoot / (totalHaul - haul4 - haul3) * haul2) * (marcher / possibleLoot))
  1759. },
  1760. ];
  1761. scavengeOptions[lackadaisicalLooters] = [
  1762. {
  1763. type: 'spear',
  1764. count: (totalLoot * (spears / possibleLoot))
  1765. },
  1766. {
  1767. type: 'sword',
  1768. count: (totalLoot * (swords / possibleLoot))
  1769. },
  1770. {
  1771. type: 'axe',
  1772. count: (totalLoot * (axes / possibleLoot))
  1773. },
  1774. {
  1775. type: 'light',
  1776. count: (totalLoot * (lightC / possibleLoot))
  1777. },
  1778. {
  1779. type: 'heavy',
  1780. count: (totalLoot * (heavyC / possibleLoot))
  1781. },
  1782. {
  1783. type: 'archer',
  1784. count: (totalLoot * (archer / possibleLoot))
  1785. },
  1786. {
  1787. type: 'marcher',
  1788. count: (totalLoot * (marcher / possibleLoot))
  1789. },
  1790. ];
  1791. }
  1792. }
  1793. }
  1794.  
  1795. run();
  1796.  
  1797. function run() {
  1798. let btn = null;
  1799. for (const option in scavengeOptions) {
  1800. btn = findNextButton(option);
  1801.  
  1802. if (btn) {
  1803. fillInTroops(option, getAvailableUnits(), btn);
  1804. break;
  1805. }
  1806. }
  1807. }
  1808.  
  1809. function clear() {
  1810. let btn = null;
  1811. for (const option in scavengeOptions) {
  1812. btn = findNextButton(option);
  1813. if (btn) {
  1814. emptyTroops(option);
  1815. break;
  1816. }
  1817. }
  1818. }
  1819.  
  1820. function fillInTroops(option, availableUnits, button) {
  1821. scavengeOptions[option].forEach(units => {
  1822. const type = units.type;
  1823. const count = units.count;
  1824. let requiredCapacity = availableUnits[type] < count ? availableUnits[type] : count;
  1825.  
  1826. $(`input.unitsInput[name='${type}']`).val(requiredCapacity).trigger("change");
  1827. $(button).focus();
  1828. });
  1829. }
  1830.  
  1831. function emptyTroops(option) {
  1832. scavengeOptions[option].forEach(units => {
  1833. const type = units.type;
  1834. $(`input.unitsInput[name='${type}']`).val("").trigger("change");
  1835. });
  1836. }
  1837.  
  1838. function findNextButton(option) {
  1839. startButtonName=document.getElementsByClassName("btn btn-default free_send_button")[0].innerHTML;
  1840. let btn = $(`.scavenge-option:contains("${option}")`).find('a:contains('+startButtonName+')');
  1841. if (btn.length > 0 && !$(btn).hasClass('btn-disabled')) return btn;
  1842. }
  1843.  
  1844.  
  1845. function getAvailableUnits() {
  1846. let availableUnits = {};
  1847.  
  1848. $('.units-entry-all').each((i, e) => {
  1849. const unitName = $(e).attr("data-unit");
  1850. const count = $(e).text().replace(/[()]/, '');
  1851. availableUnits[unitName] = parseInt(count);
  1852. });
  1853. return availableUnits;
  1854. }
  1855.  
  1856.  
  1857. }
  1858.  
  1859. scavenge();
  1860.  
  1861. //var pkt = parseInt(document.querySelector('#rank_points').textContent.split('.').join("")) < 1000
  1862. var zagroda = parseInt(document.querySelector('#pop_current_label').textContent) > 0
  1863. var poj = parseInt(document.querySelector('#scavenge_screen > div.scavenge-screen-main-widget > div.candidate-squad-container > table > tbody > tr:nth-child(2) > td.carry-max').innerText);
  1864. var odb4 = $("#scavenge_screen > div.scavenge-screen-main-widget > div.options-container > div:nth-child(4) > div.status-specific > div > div.action-container > a.btn.btn-default").hasClass("unlock-button");
  1865. var odb3 = $("#scavenge_screen > div.scavenge-screen-main-widget > div.options-container > div:nth-child(3) > div.status-specific > div > div.action-container > a.btn.btn-default").hasClass("unlock-button");
  1866. var odb2 = $("#scavenge_screen > div.scavenge-screen-main-widget > div.options-container > div:nth-child(2) > div.status-specific > div > div.action-container > a.btn.btn-default").hasClass("unlock-button");
  1867. var odb1 = $("#scavenge_screen > div.scavenge-screen-main-widget > div.options-container > div:nth-child(1) > div.status-specific > div > div.action-container > a.btn.btn-default").hasClass("unlock-button");
  1868. var blok4 = $("#scavenge_screen > div.scavenge-screen-main-widget > div.options-container > div:nth-child(4) > div.status-specific > div > div.action-container > a.btn.btn-default").hasClass("btn-disabled");
  1869. var blok3 = $("#scavenge_screen > div.scavenge-screen-main-widget > div.options-container > div:nth-child(3) > div.status-specific > div > div.action-container > a.btn.btn-default").hasClass("btn-disabled");
  1870. var blok2 = $("#scavenge_screen > div.scavenge-screen-main-widget > div.options-container > div:nth-child(2) > div.status-specific > div > div.action-container > a.btn.btn-default").hasClass("btn-disabled");
  1871. var blok1 = $("#scavenge_screen > div.scavenge-screen-main-widget > div.options-container > div:nth-child(1) > div.status-specific > div > div.action-container > a.btn.btn-default").hasClass("btn-disabled");
  1872. var start4 = $("#scavenge_screen > div.scavenge-screen-main-widget > div.options-container > div:nth-child(4) > div.status-specific > div > div.action-container > a.btn.btn-default").hasClass("free_send_button");
  1873. var start3 = $("#scavenge_screen > div.scavenge-screen-main-widget > div.options-container > div:nth-child(3) > div.status-specific > div > div.action-container > a.btn.btn-default").hasClass("free_send_button");
  1874. var start2 = $("#scavenge_screen > div.scavenge-screen-main-widget > div.options-container > div:nth-child(2) > div.status-specific > div > div.action-container > a.btn.btn-default").hasClass("free_send_button");
  1875. var start1 = $("#scavenge_screen > div.scavenge-screen-main-widget > div.options-container > div:nth-child(1) > div.status-specific > div > div.action-container > a.btn.btn-default").hasClass("free_send_button");
  1876. var unl4 = $("#scavenge_screen > div.scavenge-screen-main-widget > div.options-container > div:nth-child(4) > div.status-specific > div > div.unlock-countdown > span.unlock-countdown-text").hasClass("unlock-countdown-text");
  1877. var unl3 = $("#scavenge_screen > div.scavenge-screen-main-widget > div.options-container > div:nth-child(3) > div.status-specific > div > div.unlock-countdown > span.unlock-countdown-text").hasClass("unlock-countdown-text");
  1878. var unl2 = $("#scavenge_screen > div.scavenge-screen-main-widget > div.options-container > div:nth-child(2) > div.status-specific > div > div.unlock-countdown > span.unlock-countdown-text").hasClass("unlock-countdown-text");
  1879. var unl1 = $("#scavenge_screen > div.scavenge-screen-main-widget > div.options-container > div:nth-child(1) > div.status-specific > div > div.unlock-countdown > span.unlock-countdown-text").hasClass("unlock-countdown-text");
  1880.  
  1881. if(zagroda && poj > 0 && start4){
  1882. document.querySelector('#scavenge_screen > div.scavenge-screen-main-widget > div.options-container > div:nth-child(4) > div.status-specific > div > div.action-container > a.btn.btn-default.free_send_button').click();
  1883. scavenge();
  1884. };
  1885. if(zagroda && poj > 0 && start3 && (blok4 || odb4 || unl4)){
  1886. document.querySelector('#scavenge_screen > div.scavenge-screen-main-widget > div.options-container > div:nth-child(3) > div.status-specific > div > div.action-container > a.btn.btn-default.free_send_button').click();
  1887. scavenge();
  1888. };
  1889.  
  1890. if(zagroda && poj > 0 && start2 && (blok3 || odb3 || unl3) && ((blok4 || odb4) || unl4)){
  1891. document.querySelector('#scavenge_screen > div.scavenge-screen-main-widget > div.options-container > div:nth-child(2) > div.status-specific > div > div.action-container > a.btn.btn-default.free_send_button').click();
  1892. scavenge();
  1893. };
  1894.  
  1895. if(zagroda && poj > 0 && start1 && ((blok2 || odb2) || unl2) && ((blok3 || odb3) || unl3) && ((blok4 || odb4) || unl4)){
  1896. document.querySelector('#scavenge_screen > div.scavenge-screen-main-widget > div.options-container > div:nth-child(1) > div.status-specific > div > div.action-container > a.btn.btn-default.free_send_button').click();
  1897. scavenge();
  1898. };
  1899.  
  1900. });
  1901.  
  1902. setInterval(zegarek,((Math.random() * (1100 - 300 + 1)) + 300));
  1903. function zegarek(){
  1904. $("#greenbutton").click();
  1905. }
  1906.  
  1907. setInterval(odblokowanie,1000);
  1908. function odblokowanie(){
  1909.  
  1910. var wood = parseInt($("#wood").text());
  1911. var stone = parseInt($("#stone").text());
  1912. var iron = parseInt($("#iron").text());
  1913.  
  1914. var odb4 = $("#scavenge_screen > div.scavenge-screen-main-widget > div.options-container > div:nth-child(4) > div.status-specific > div > div.action-container > a.btn.btn-default").hasClass("unlock-button");
  1915. var odb3 = $("#scavenge_screen > div.scavenge-screen-main-widget > div.options-container > div:nth-child(3) > div.status-specific > div > div.action-container > a.btn.btn-default").hasClass("unlock-button");
  1916. var odb2 = $("#scavenge_screen > div.scavenge-screen-main-widget > div.options-container > div:nth-child(2) > div.status-specific > div > div.action-container > a.btn.btn-default").hasClass("unlock-button");
  1917. var odb1 = $("#scavenge_screen > div.scavenge-screen-main-widget > div.options-container > div:nth-child(1) > div.status-specific > div > div.action-container > a.btn.btn-default").hasClass("unlock-button");
  1918. var unl4 = $("#scavenge_screen > div.scavenge-screen-main-widget > div.options-container > div:nth-child(4) > div.status-specific > div > div.unlock-countdown > span.unlock-countdown-text").hasClass("unlock-countdown-text");
  1919. var unl3 = $("#scavenge_screen > div.scavenge-screen-main-widget > div.options-container > div:nth-child(3) > div.status-specific > div > div.unlock-countdown > span.unlock-countdown-text").hasClass("unlock-countdown-text");
  1920. var unl2 = $("#scavenge_screen > div.scavenge-screen-main-widget > div.options-container > div:nth-child(2) > div.status-specific > div > div.unlock-countdown > span.unlock-countdown-text").hasClass("unlock-countdown-text");
  1921. var unl1 = $("#scavenge_screen > div.scavenge-screen-main-widget > div.options-container > div:nth-child(1) > div.status-specific > div > div.unlock-countdown > span.unlock-countdown-text").hasClass("unlock-countdown-text");
  1922.  
  1923. if(odb1 && odb2 && odb3 && odb4){
  1924. $("#scavenge_screen > div > div.options-container > div:nth-child(1) > div.status-specific > div > div.action-container > a").click();
  1925. $("#popup_box_unlock-option-1 > div > div > a").click();
  1926. };
  1927. if(!odb1 && !unl1 && odb2 && odb3 && odb4){
  1928. $("#scavenge_screen > div > div.options-container > div:nth-child(2) > div.status-specific > div > div.action-container > a").click();
  1929. $("#popup_box_unlock-option-2 > div > div > a").click();
  1930. };
  1931. if(!odb1 && !unl1 && !odb2 && !unl2 && odb3 && odb4 && (wood > 1000 && stone > 1200 && iron > 1000)){
  1932. $("#scavenge_screen > div > div.options-container > div:nth-child(3) > div.status-specific > div > div.action-container > a").click();
  1933. $("#popup_box_unlock-option-3 > div > div > a").click();
  1934. };
  1935. if(!odb1 && !unl1 && !odb2 && !unl2 && !odb3 && !unl3 && odb4 && (wood > 10000 && stone > 10000 && iron > 10000)){
  1936. $("#scavenge_screen > div > div.options-container > div:nth-child(4) > div.status-specific > div > div.action-container > a").click();
  1937. $("#popup_box_unlock-option-4 > div > div > a").click();
  1938. };
  1939.  
  1940. setInterval(odblokowanienext,Math.floor(Math.random() * (7000 - 3000 + 1)) + 3000);
  1941. function odblokowanienext(){
  1942. var a = $("#village_switch_right > span").length;
  1943. if (a > 0){
  1944. $("#village_switch_right > span").click();
  1945. } else {
  1946. function sleep(ms) {
  1947. return new Promise(resolve => setTimeout(resolve, ms));
  1948. }
  1949.  
  1950. async function demo() {
  1951. await sleep(16000);
  1952. window.location.reload(true);
  1953. }
  1954.  
  1955. demo();
  1956.  
  1957. };
  1958. };
  1959.  
  1960. setInterval(fastnext,Math.floor(Math.random() * (2000 - 1000 + 1)) + 1000);
  1961. function fastnext(){
  1962. var blok4 = $("#scavenge_screen > div.scavenge-screen-main-widget > div.options-container > div:nth-child(4) > div.status-specific > div > div.action-container > a.btn.btn-default").hasClass("btn-disabled");
  1963. var blok3 = $("#scavenge_screen > div.scavenge-screen-main-widget > div.options-container > div:nth-child(3) > div.status-specific > div > div.action-container > a.btn.btn-default").hasClass("btn-disabled");
  1964. var blok2 = $("#scavenge_screen > div.scavenge-screen-main-widget > div.options-container > div:nth-child(2) > div.status-specific > div > div.action-container > a.btn.btn-default").hasClass("btn-disabled");
  1965. var blok1 = $("#scavenge_screen > div.scavenge-screen-main-widget > div.options-container > div:nth-child(1) > div.status-specific > div > div.action-container > a.btn.btn-default").hasClass("btn-disabled");
  1966. if(blok1 && blok2 && blok3 && blok4){
  1967. var a = $("#village_switch_right > span").length;
  1968. if (a > 0){
  1969. $("#village_switch_right > span").click();
  1970. }
  1971. };
  1972. };
  1973. };
  1974.  
  1975. //scavenge();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement