Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.18 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Zbieractwo
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description try to take over the world!
  6. // @author You
  7. // @match https://*.plemiona.pl/game.php?*&screen=place&mode=scavenge
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function () {
  12. if(game_data.units.length == 10){
  13. window.units = [{
  14. name: 'pik',
  15. count: parseInt(document.querySelector('#scavenge_screen > div > div.candidate-squad-container > table > tbody > tr:nth-child(2) > td:nth-child(1) > a').innerText.replace(/[(|)]/gm, '')),
  16. input: document.querySelector('#scavenge_screen > div > div.candidate-squad-container > table > tbody > tr:nth-child(2) > td:nth-child(1) > input'),
  17. capacity: 25
  18. },
  19. {
  20. name: 'sword',
  21. count: parseInt(document.querySelector('#scavenge_screen > div > div.candidate-squad-container > table > tbody > tr:nth-child(2) > td:nth-child(2) > a').innerText.replace(/[(|)]/gm, '')),
  22. input: document.querySelector('#scavenge_screen > div > div.candidate-squad-container > table > tbody > tr:nth-child(2) > td:nth-child(2) > input'),
  23. capacity: 15
  24. },
  25. {
  26. name: 'axe',
  27. count: parseInt(document.querySelector('#scavenge_screen > div > div.candidate-squad-container > table > tbody > tr:nth-child(2) > td:nth-child(3) > a').innerText.replace(/[(|)]/gm, '')),
  28. input: document.querySelector('#scavenge_screen > div > div.candidate-squad-container > table > tbody > tr:nth-child(2) > td:nth-child(3) > input'),
  29. capacity: 10
  30. },
  31. {
  32. name: 'light',
  33. count: parseInt(document.querySelector('#scavenge_screen > div > div.candidate-squad-container > table > tbody > tr:nth-child(2) > td:nth-child(4) > a').innerText.replace(/[(|)]/gm, '')),
  34. input: document.querySelector('#scavenge_screen > div > div.candidate-squad-container > table > tbody > tr:nth-child(2) > td:nth-child(4) > input'),
  35. capacity: 80
  36. },
  37. {
  38. name: 'heavy',
  39. count: parseInt(document.querySelector('#scavenge_screen > div > div.candidate-squad-container > table > tbody > tr:nth-child(2) > td:nth-child(5) > a').innerText.replace(/[(|)]/gm, '')),
  40. input: document.querySelector('#scavenge_screen > div > div.candidate-squad-container > table > tbody > tr:nth-child(2) > td:nth-child(5) > input'),
  41. capacity: 50
  42. },
  43. {
  44. name: 'noble',
  45. count: parseInt(document.querySelector('#scavenge_screen > div > div.candidate-squad-container > table > tbody > tr:nth-child(2) > td:nth-child(6) > a').innerText.replace(/[(|)]/gm, '')),
  46. input: document.querySelector('#scavenge_screen > div > div.candidate-squad-container > table > tbody > tr:nth-child(2) > td:nth-child(6) > input'),
  47. capacity: 100
  48. }
  49. ]
  50. }else{
  51. window.units = [{
  52. name: 'pik',
  53. count: parseInt(document.querySelector('#scavenge_screen > div > div.candidate-squad-container > table > tbody > tr:nth-child(2) > td:nth-child(1) > a').innerText.replace(/[(|)]/gm, '')),
  54. input: document.querySelector('#scavenge_screen > div > div.candidate-squad-container > table > tbody > tr:nth-child(2) > td:nth-child(1) > input'),
  55. capacity: 25
  56. },
  57. {
  58. name: 'sword',
  59. count: parseInt(document.querySelector('#scavenge_screen > div > div.candidate-squad-container > table > tbody > tr:nth-child(2) > td:nth-child(2) > a').innerText.replace(/[(|)]/gm, '')),
  60. input: document.querySelector('#scavenge_screen > div > div.candidate-squad-container > table > tbody > tr:nth-child(2) > td:nth-child(2) > input'),
  61. capacity: 15
  62. },
  63. {
  64. name: 'axe',
  65. count: parseInt(document.querySelector('#scavenge_screen > div > div.candidate-squad-container > table > tbody > tr:nth-child(2) > td:nth-child(3) > a').innerText.replace(/[(|)]/gm, '')),
  66. input: document.querySelector('#scavenge_screen > div > div.candidate-squad-container > table > tbody > tr:nth-child(2) > td:nth-child(3) > input'),
  67. capacity: 10
  68. },
  69. {
  70. name: 'arrow',
  71. count: parseInt(document.querySelector('#scavenge_screen > div > div.candidate-squad-container > table > tbody > tr:nth-child(2) > td:nth-child(4) > a').innerText.replace(/[(|)]/gm, '')),
  72. input: document.querySelector('#scavenge_screen > div > div.candidate-squad-container > table > tbody > tr:nth-child(2) > td:nth-child(4) > input'),
  73. capacity: 10
  74. },
  75. {
  76. name: 'light',
  77. count: parseInt(document.querySelector('#scavenge_screen > div > div.candidate-squad-container > table > tbody > tr:nth-child(2) > td:nth-child(5) > a').innerText.replace(/[(|)]/gm, '')),
  78. input: document.querySelector('#scavenge_screen > div > div.candidate-squad-container > table > tbody > tr:nth-child(2) > td:nth-child(5) > input'),
  79. capacity: 80
  80. },
  81. {
  82. name: 'arrowhorse',
  83. count: parseInt(document.querySelector('#scavenge_screen > div > div.candidate-squad-container > table > tbody > tr:nth-child(2) > td:nth-child(6) > a').innerText.replace(/[(|)]/gm, '')),
  84. input: document.querySelector('#scavenge_screen > div > div.candidate-squad-container > table > tbody > tr:nth-child(2) > td:nth-child(6) > input'),
  85. capacity: 50
  86. },
  87. {
  88. name: 'heavy',
  89. count: parseInt(document.querySelector('#scavenge_screen > div > div.candidate-squad-container > table > tbody > tr:nth-child(2) > td:nth-child(7) > a').innerText.replace(/[(|)]/gm, '')),
  90. input: document.querySelector('#scavenge_screen > div > div.candidate-squad-container > table > tbody > tr:nth-child(2) > td:nth-child(7) > input'),
  91. capacity: 50
  92. },
  93. {
  94. name: 'noble',
  95. count: parseInt(document.querySelector('#scavenge_screen > div > div.candidate-squad-container > table > tbody > tr:nth-child(2) > td:nth-child(8) > a').innerText.replace(/[(|)]/gm, '')),
  96. input: document.querySelector('#scavenge_screen > div > div.candidate-squad-container > table > tbody > tr:nth-child(2) > td:nth-child(8) > input'),
  97. capacity: 100
  98. }
  99. ]
  100. }
  101.  
  102.  
  103. window.get_capacity = function () {
  104. var output = 0;
  105. units.forEach(unit => {
  106. output = output + unit.capacity * unit.count
  107. });
  108. return output;
  109. }
  110.  
  111. window.getSelectedCapacity = function(){
  112. var output = 0;
  113. units.forEach(unit =>{
  114. output = output + unit.input.value * unit.capacity;
  115. });
  116. return output;
  117. }
  118.  
  119. window.customFlag1 = false;
  120. window.requiredResources = [];
  121. window.requiredParts = [10,4,2,1];
  122. window.activeplans = $('.status-specific').length - $('.locked-view').length;
  123. var partsCount = activeplans == 1 ? 10 : activeplans == 2 ? 14 : activeplans == 3 ? 16 : activeplans == 4 ? 17 : null;
  124.  
  125. window.queCurrent = function(){
  126. if(!window.customFlag1)
  127. this.setTimeout(show_current, 50);
  128. window.customFlag1 = true;
  129. }
  130.  
  131. window.show_current = function () {
  132. window.customFlag1 = false;
  133. $('.remove_selector_countAll').remove()
  134. $('#scavenge_screen > div > div.options-container > div').each(function (index, element) {
  135. var e = $(element).find('ul');
  136. if (typeof e != 'undefined') {
  137. var sum = 0;
  138. for (var lii = 0; lii < e.children(':not([class])').length; lii++) {
  139. sum = sum + parseInt($(e.children(':not([class])')[lii]).find(':last-child').text());
  140. }
  141. e.append('<li class="remove_selector_countAll">' + sum + ' / '+getSelectedCapacity()+'</li>')
  142. }
  143. })
  144. }
  145.  
  146. window.calculateInput = function(){
  147. var part = Math.floor(get_capacity() / partsCount);
  148. for(var index = 0; index<activeplans; index++){
  149. window.requiredResources[index] = part*window.requiredParts[index];
  150. }
  151. }
  152.  
  153. window.refreshUnits = function(){
  154. for(var unitIndex = 1; unitIndex <= units.length; unitIndex++){
  155. units[unitIndex-1].count = parseInt(document.querySelector('#scavenge_screen > div > div.candidate-squad-container > table > tbody > tr:nth-child(2) > td:nth-child('+unitIndex+') > a').innerText.replace(/[(|)]/gm, ''))
  156. }
  157. }
  158.  
  159. window.fillInputs = async function(){
  160. for(var inde = 0; inde<activeplans; inde++){
  161. refreshUnits();
  162. var selectedUnits = [];
  163. var filledCappacity = 0;
  164. for(var currentUnitIndex = 0; currentUnitIndex < units.length; currentUnitIndex++){
  165. //Analiza pojedynczej jednostki
  166. if(filledCappacity < requiredResources[inde]){
  167. var u = units[currentUnitIndex];
  168. var count = 0;
  169. for(var unitCountIndex = 0; unitCountIndex<u.count; unitCountIndex++){
  170. filledCappacity = filledCappacity + u.capacity;
  171. if(filledCappacity < requiredResources[inde]){
  172. count++;
  173. }else{
  174. break;
  175. }
  176. }
  177. if(count > 0){
  178. console.log("Push to "+(inde+1)+" "+count+" of "+units[currentUnitIndex].name);
  179. selectedUnits.push({
  180. unitID:currentUnitIndex,
  181. unitCount:count,
  182. input:u.input
  183. });
  184. }
  185. }else{
  186. break;
  187. }
  188. }
  189.  
  190. selectedUnits.forEach(su=>{
  191. $(su.input).trigger('focus');
  192. $(su.input).trigger('keydown');
  193. $(su.input).val(su.unitCount);
  194. $(su.input).trigger('keyup');
  195. $(su.input).trigger('change');
  196. });
  197. await sleep(2000);
  198. $('#scavenge_screen > div > div.options-container > div:nth-child('+(inde+1)+') > div.status-specific > div > div.action-container > a.btn.btn-default.free_send_button').click();
  199. await sleep(2000);
  200. }
  201. window.BotIsWorking = false;
  202. }
  203.  
  204. window.startBot = function(){
  205. console.log("trying to start");
  206. var active_buttons = $('.action-container > a.free_send_button').length;
  207. if(active_buttons == window.activeplans && localStorage.botIsActive == "true"){
  208. console.log("Started");
  209. setTimeout(calculateInput, 2000);
  210. setTimeout(fillInputs, 4000);
  211. }
  212. }
  213. window.BotIsWorking = null;
  214. window.preStartBot = function(){
  215. console.log("PreStarting");
  216. clearTimeout(window.BotIsWorking);
  217. window.BotIsWorking = setTimeout(startBot, 20000);
  218. }
  219.  
  220. window.turnOnFarm = function(e){
  221. localStorage.botIsActive = e.checked;
  222. location.reload();
  223. }
  224.  
  225. function sleep(ms) {
  226. return new Promise(resolve => setTimeout(resolve, ms));
  227. }
  228.  
  229. $('#scavenge_screen > div > div.options-container > div > div.status-specific > div > div.squad-preview > ul > li:nth-child(1) > span.wood-value').bind("DOMSubtreeModified", function() {
  230. queCurrent();
  231. });
  232. window.Collecting = false;
  233. $('#scavenge_screen > div > div.candidate-squad-container > table > tbody > tr:nth-child(1)').append('<th></th>');
  234. $('#scavenge_screen > div > div.candidate-squad-container > table > tbody > tr:nth-child(1)').append('<th></th>');
  235. $('#scavenge_screen > div > div.candidate-squad-container > table > tbody > tr:nth-child(2)').append('<td><a href="#" class="btn btn-default custom-lock-buttons" onclick="calculateInput()">Oblicz</a></td>');
  236. $('#scavenge_screen > div > div.candidate-squad-container > table > tbody > tr:nth-child(2)').append('<td><a href="#" class="btn btn-default custom-lock-buttons" onclick="fillInputs()">Wypełnij</a></td>');
  237. $('#scavenge_screen > div > div.candidate-squad-container > table > tbody > tr:nth-child(1)').append('<th>Działaj ciągle</th>');
  238. $('#scavenge_screen > div > div.candidate-squad-container > table > tbody > tr:nth-child(2)').append('<td><input type="checkbox" onchange="turnOnFarm(this)" /></td>');
  239. document.querySelector('#scavenge_screen > div > div.candidate-squad-container > table > tbody > tr:nth-child(2) > td:nth-child(11) > input[type=checkbox]').checked = localStorage.botIsActive == "true";
  240. if(localStorage.botIsActive == "true"){
  241. $('.custom-lock-buttons').hide();
  242. startBot();
  243. }
  244.  
  245. $('.status-specific').bind("DOMSubtreeModified",function(){
  246. var active_buttons = $('.action-container > a.free_send_button').length;
  247. if(active_buttons == window.activeplans && localStorage.botIsActive == "true")
  248. window.preStartBot();
  249. });
  250.  
  251.  
  252.  
  253. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement