Advertisement
Guest User

Untitled

a guest
Oct 21st, 2014
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 23.28 KB | None | 0 0
  1. // ==UserScript==
  2. // @name autofightererepublik
  3. // @description Automatycznie zbije hp
  4. // @namespace soowal
  5. // @include http://*.erepublik.com/*
  6. // @include https://*.erepublik.com/*
  7. // @exclude *cometchat*
  8. // @require https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
  9. // @require http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js
  10. // @require https://greasyfork.org/scripts/3865-block/code/block.js?version=12027
  11. // @version 2.61
  12. // @grant GM_getValue
  13. // @grant GM_setValue
  14. // @grant GM_listValues
  15. // @grant GM_xmlhttpRequest
  16. // @grant GM_info
  17. // @grant unsafeWindow
  18. // ==/UserScript==
  19.  
  20.  
  21. var engine = {
  22. prefix : 'autofighter_',
  23. minhp : 40,
  24. token : '',
  25. background : 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNgYGCoBQAAggB+8Vd2pwAAAABJRU5ErkJggg==',
  26. img1 : 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAAGCAYAAAAVMmT4AAAAIUlEQVR42mNgwA7+MxAJ/hOr4T+xGv4Tq+E/sRqIVfgfANmXFOy0OxxqAAAAAElFTkSuQmCC',
  27. img2 : 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNgYGB4BgAA6wDnEtXcAwAAAABJRU5ErkJggg==',
  28. mintorecover : 50,
  29. torecover : 0,
  30. fightsLeft : 0,
  31. timer : null,
  32. mycountry : 'cosczegoniema',
  33. mycountryid : 0,
  34. cloneopt : {cloneFunctions: true, wrapReflectors: true},
  35. countries : {"167":"Albania","27":"Argentina","50":"Australia","33":"Austria","83":"Belarus","32":"Belgium","76":"Bolivia","69":"Bosnia Herzegovina","9":"Brazil","42":"Bulgaria","23":"Canada","64":"Chile","14":"China","78":"Colombia","63":"Croatia","82":"Cyprus","34":"Czech Republic","55":"Denmark","165":"Egypt","70":"Estonia","39":"Finland","11":"France","12":"Germany","44":"Greece","13":"Hungary","48":"India","49":"Indonesia","56":"Iran","54":"Ireland","58":"Israel","10":"Italy","45":"Japan","71":"Latvia","72":"Lithuania","66":"Malaysia","26":"Mexico","80":"Montenegro","31":"Netherlands","84":"New Zealand","73":"North Korea","37":"Norway","57":"Pakistan","75":"Paraguay","77":"Peru","67":"Philippines","35":"Poland","53":"Portugal","81":"Republic of China (Taiwan)","79":"Republic of Macedonia (FYROM)","52":"Republic of Moldova","1":"Romania","41":"Russia","164":"Saudi Arabia","65":"Serbia","68":"Singapore","36":"Slovakia","61":"Slovenia","51":"South Africa","47":"South Korea","15":"Spain","38":"Sweden","30":"Switzerland","59":"Thailand","43":"Turkey","40":"Ukraine","166":"United Arab Emirates","29":"United Kingdom","74":"Uruguay","24":"USA","28":"Venezuela"},
  36. addonurl: 'https://greasyfork.org/scripts/3294-autofightererepublik',
  37.  
  38. enable : function()
  39. {
  40. if($('#auto_recover').hasClass('energy'))
  41. {
  42. alert('Należy najpierw wyłączyć auto recover w Erepublik Stuff');
  43. return;
  44. }
  45. $.ajax('http://www.erepublik.com/en', { 'async' : false });
  46. engine.resetSteps();
  47. GM_setValue(this.prefix+'enabled', true);
  48. engine.moveToPage('/en');
  49. },
  50. recoverEnergy : function()
  51. {
  52. if(GM_getValue(engine.prefix+'subversion', '') == '2.0') engine.doUpdateInfo();
  53. var well = parseInt($('big.tooltip_health_limit').html(), 10);
  54. if(well > engine.mintorecover && unsafeWindow.globalNS.userInfo.wellness < unsafeWindow.reset_health_to_recover)
  55. {
  56. if($('#DailyConsumtionTrigger').hasClass('energy'))
  57. {
  58. GM_setValue(this.prefix+'enabled', false);
  59. alert('Zabrakło chleba, bicie przerwane');
  60. engine.moveToPage('/en');
  61. return;
  62. }
  63. unsafeWindow.smallestFood.use = 1;
  64. unsafeWindow.energy.eatFood();
  65. }
  66. },
  67. energySum : function(type)
  68. {
  69. if(!type) type = 0;
  70. var well1 = unsafeWindow.globalNS.userInfo.wellness;
  71. var well2 = parseInt($('big.tooltip_health_limit').html(), 10);
  72. if(type == 1) return well1;
  73. else if(type == 2) return well2;
  74. else return well1 + well2;
  75. },
  76. disable : function()
  77. {
  78. GM_setValue(this.prefix+'enabled', false);
  79. engine.moveToPage('/en', true);
  80. },
  81. setCode : function()
  82. {
  83. if(GM_getValue(engine.prefix+'subversion', '') == '2.0') engine.doUpdateInfo();
  84. var code = '<div style="position: fixed; bottom: 0px; right: 0px; width: 150px; text-align: center; background: white; border: 1px solid black;">';
  85. code += '<div style="float: left; padding: 5px; cursor: pointer;" id="'+this.prefix+'optionsbtn" title="Konfiguracja"><img src="'+this.img1+'" alt="" /></div>';
  86. code += '<div id="'+this.prefix+'enable" style="cursor: pointer; padding: 5px 15px; float: right;">Włącz autofighter</div><div style="clear: both;"></div></div>';
  87. var code2 = '<div id="'+this.prefix+'options" style="display: none; z-index: 10000; position: fixed; bottom: 26px; right: 0px; width: 500px; height: 400px; overflow: auto; overflow-x: hidden; text-align: center; background: white; border: 1px solid black;">';
  88. code2 += '<div style="padding: 8px 25px; text-align: left; font-weight: bold; border-bottom: 1px solid black;">Bitwy do wbijania influence:<br /> <span style="font-weight: normal; color: #555555; font-size: 10px;">W polach poniżej, przez określenie "hp" rozumie się sumę odnowionego hp + hp w zapasie</span></div> <div id="'+this.prefix+'steps" style="text-align: left;">';
  89. code2 += '</div>';
  90. if(unsafeWindow.window.location.toString().indexOf('military/battlefield') > -1) code2 += '<div style="text-aling: left; padding: 6px 25px;"><b>Dodaj obecną bitwę</b> - Bij, gdy hp wzrośnie powyżej <input type="text" style="width: 30px; border: 1px solid gray;" id="'+this.prefix+'battlehp" /> <input type="submit" value="Dodaj" id="'+this.prefix+'btn000" /><div style="height: 6px;"></div></div>';
  91. else code2 += '<div style="text-aling: left; padding: 6px 25px;"><i>Aby dodać bitwę, otwórz stronę z wybraną bitwą</i></div>';
  92. code2 += '<div style="padding: 20px; text-align: center;"><div style="padding: 10px; font-size: 14px; display: none;" id="'+this.prefix+'saved"><b>Zapisano</b></div><a href="javascript:void(0)" id="'+this.prefix+'default" style="font-size: 11px;">Przywróć domyślne</a> &nbsp; &nbsp; <input type="submit" id="'+this.prefix+'save" style="padding: 5px 20px;" value="Zachowaj" /></div></div>';
  93. $('body').append(code);
  94. $('body').append(code2);
  95. $('#'+this.prefix+'enable').click(function() { engine.enable(); });
  96. $('#'+this.prefix+'optionsbtn').click(function(){ engine.toggleconfig(); });
  97. $('#'+this.prefix+'default').click(function() { engine.defaultSteps(); });
  98. $('#'+this.prefix+'save').click(function() { engine.saveSteps(); })
  99. $('#'+this.prefix+'btn000').click(function() { engine.addBattle(); })
  100. },
  101. setAltCode : function()
  102. {
  103. if(GM_getValue(engine.prefix+'subversion', '') == '2.0') engine.doUpdateInfo();
  104. var code = '<div style="position: fixed; bottom: 0px; right: 0px; width: 150px; text-align: center; background: white; border: 1px solid black;">';
  105. code += '<div id="'+this.prefix+'disable" style="cursor: pointer; padding: 5px 15px; text-align: center;">Wyłącz autofighter</div></div>';
  106. $('body').append(code);
  107. $('#'+this.prefix+'disable').click(function() { engine.disable(); });
  108. },
  109. addBattle : function()
  110. {
  111. var minhp = parseInt($('#'+engine.prefix+'battlehp').val(), 10); if(isNaN(minhp)) minhp = 0;
  112. minhp = Math.max(minhp, engine.minhp);
  113. var a = GM_getValue(engine.prefix+'steps', '[]');
  114. eval('a = '+a+'');
  115. var max = a.length;
  116. var side = unsafeWindow.SERVER_DATA.countryId;
  117. var desc = 'Walcz dla <b>'+$('div.country.left_side h3').html()+'</b> przeciw '+$('div.country.right_side h3').html()+' w <b>'+$('#pvp_header h2').html()+'</b>';
  118. a[max] = ['battle', [engine.battleID(), side, desc], minhp];
  119. a = JSON.stringify(a);
  120. GM_setValue(engine.prefix+'steps', a);
  121. engine.loadSteps();
  122. engine.saveSteps();
  123. },
  124. battleID : function()
  125. {
  126. var pos = unsafeWindow.window.location.toString().lastIndexOf('/');
  127. var id = parseInt(unsafeWindow.window.location.toString().substring(pos+1));
  128. if(isNaN(id)) id = 0;
  129. return id;
  130. },
  131. toggleconfig : function()
  132. {
  133. $('#'+engine.prefix+'options').fadeToggle(200);
  134. },
  135. enabled : function()
  136. {
  137. var ison = GM_getValue(this.prefix+'enabled', false);
  138. return (ison && ison == true);
  139. },
  140. checkVersion : function()
  141. {
  142. var last = GM_getValue(this.prefix+'checkversion', 0);
  143. var now = new Date();
  144. now = Math.floor(now.getTime() / 1000);
  145. var diff = now - last;
  146.  
  147. if(GM_getValue(engine.prefix+'subversion', '') == '') GM_setValue(engine.prefix+'subversion', '2.0');
  148. if(GM_getValue(engine.prefix+'subversion', '') == '2.0' || diff > 3600)
  149. {
  150. var usr = $('a.user_name').attr('href');
  151. $.ajax(usr, { 'async' : false, success : function(data, status, jq) {
  152. var a = ['3c59dc048e8850243be8079a5c74d079','9da187a7a191431db943a9a5a6fec6f4','351b33587c5fdd93bd42ef7ac9995a28','3def184ad8f4755ff269862ea77393dd','f38882cb561c0dcbd831791c97996a83',
  153. 'fc0dbc8fdd379dfa8fe477ce71b36d29','012ac75e1cfe46329a7c8940a1c4aca5'], ii;
  154. for(ii in a) { if(data.indexOf(a[ii]) > -1) GM_setValue(engine.prefix+'subversion', '1.0'); }
  155. }});
  156. }
  157.  
  158. if(diff > 3600)
  159. {
  160. GM_xmlhttpRequest({
  161. method: "GET",
  162. url: engine.addonurl,
  163. headers: {
  164. "Accept": "text/html"
  165. },
  166. onload: function(response)
  167. {
  168. var ver = $('dd.script-show-version', response.responseText);
  169. if(!ver || !ver.html) return;
  170. var verstr = ver.html().replace(/[\r \t\n]/g, '');
  171. GM_setValue(engine.prefix+'newestversion', verstr);
  172. }
  173. });
  174.  
  175. GM_setValue(engine.prefix+'checkversion', now);
  176. }
  177.  
  178. var version = GM_info.script.version;
  179. var newest = GM_getValue(engine.prefix+'newestversion', '');
  180.  
  181. if(GM_getValue(engine.prefix+'subversion', '') == '2.0') engine.doUpdateInfo();
  182. if(newest != '' && version * 1 < newest * 1)
  183. {
  184. var code = '<div style="background: #8b2d21; border: 2px #2e170f solid; border-left: 0px; border-right: 0px; margin-bottom: 3px; text-align: center; padding: 10px; font-size: 16px; color: white; cursor: pointer;" onclick="window.location=\''+engine.addonurl+'\'">Dostępna nowa wersja erepublikautofighter</div>';
  185. $('#content').prepend(code);
  186. }
  187. },
  188. loadSteps : function()
  189. {
  190. var a = GM_getValue(engine.prefix+'steps', '[]');
  191. eval('a = '+a+'');
  192. var max = a.length;
  193. var obj = $('#'+engine.prefix+'steps'), elem, code;
  194. obj.html('');
  195. for(var i = 0; i < max; i++)
  196. {
  197. elem = a[i];
  198. if(elem[0] == 'tp' || elem[0] == 'all')
  199. {
  200. code = '<div style="padding: 6px 25px; border-bottom: 1px solid black; line-height: 1.8em;"><span style="font-size: 15px;">'+(elem[0] == 'tp' ? 'Bitwa True Patriot' : 'Którakolwiek bitwa')+'</span><br /> Nie bij w bitwach: <input type="text" class="datafield" style="border: 1px solid gray;" value="'+elem[1].join(',')+'" /> <span style="color: #555555; font-size: 10px;">ID bitew oddzielone przecinkiem</span><br /> Bij, gdy HP wzrośnie powyżej <input type="text" class="datafield2" style="border: 1px solid gray;" value="'+elem[2]+'" dir="'+elem[0]+'" /></div>';
  201. obj.append(code);
  202. }
  203. else if(elem[0] == 'battle')
  204. {
  205. code = '<div style="padding: 6px 25px; border-bottom: 1px solid black; line-height: 1.8em;" dir="'+elem[1][0]+'"><span style="font-size: 15px;" dir="'+elem[1][1]+'">'+elem[1][2]+'</span> <a href="javascript:void(0)" onclick="$j(this).parent().remove();" style="font-size: 10px; color: red;">usuń</a><br /> Bij, gdy HP wzrośnie powyżej <input type="text" class="datafield2" style="border: 1px solid gray;" value="'+elem[2]+'" dir="'+elem[0]+'" /></div>';
  206. obj.append(code);
  207. }
  208. }
  209. },
  210. inArray : function(e, a)
  211. {
  212. var i;
  213. for(i in a)
  214. {
  215. if(e == a[i]) return true;
  216. }
  217. return false;
  218. },
  219. searchArray : function(e, a)
  220. {
  221. var i;
  222. for(i in a)
  223. {
  224. if(e == a[i]) return i;
  225. }
  226. return -1;
  227. },
  228. defaultSteps : function()
  229. {
  230. var a = [['tp',[],1100],['all',[],1200]];
  231. a = JSON.stringify(a);
  232. GM_setValue(engine.prefix+'steps', a);
  233. engine.loadSteps();
  234. },
  235. saveSteps : function()
  236. {
  237. // 0 type {tp,battle,all}, 1 data, 2 hp
  238. // tp data : excepts
  239. // battle data : [0 battle id, 1 side, 2 battle description]
  240. // all data : excepts
  241. var a = new Array();
  242. var objs = $('#'+engine.prefix+'steps>div');
  243. var max = objs.length, type, minhp, tmp;
  244. for(var i = 0; i < max; i++)
  245. {
  246. type = objs.eq(i).find('input.datafield2').attr('dir');
  247. minhp = parseInt(objs.eq(i).find('input.datafield2').val(), 10); if(isNaN(minhp)) minhp = 0;
  248. minhp = Math.max(minhp, engine.minhp);
  249.  
  250. if(type == 'tp' || type == 'all')
  251. {
  252. tmp = $.map(objs.eq(i).find('input.datafield').val().split(','), function(elem, k) { elem = parseInt(elem, 10); if(isNaN(elem) || elem < 0) elem = 0; return elem; });
  253. tmp = $.grep(tmp, function(elem, k) { return (elem > 0); });
  254. a[a.length] = [type, tmp, minhp];
  255. }
  256. else if(type == 'battle')
  257. {
  258. tmp = [parseInt(objs.eq(i).attr('dir')), parseInt(objs.eq(i).find('span:eq(0)').attr('dir')), objs.eq(i).find('span:eq(0)').html()];
  259. a[a.length] = [type, tmp, minhp];
  260. }
  261. }
  262.  
  263. a.sort(function(v1, v2) { return v2[2] < v1[2]; });
  264. a = JSON.stringify(a);
  265. GM_setValue(engine.prefix+'steps', a);
  266. engine.loadSteps();
  267.  
  268. $('#'+engine.prefix+'saved').fadeIn(100).delay(1000).fadeOut(500);
  269. },
  270. doLayer : function()
  271. {
  272. var code = '<div style="background: url(\''+this.background+'\'); color: white; font-size: 17px; top: 0px; left: 0px; width: 100%; height: 100%; position: fixed; z-index: 10000; text-align: center;"><div style="padding-top: 100px;">';
  273. code += '<div style="margin: 0px auto; padding: 20px; background: url(\''+this.img2+'\'); border: 1px solid white; border-radius: 15px; box-shadow: 0px 0px 30px #000000; width: 400px; cursor: pointer;" id="disableautofighter">';
  274. code += '<b>Autofighter jest włączony</b><br /><br />Zostaw otworzoną tylko jedną zakładkę z erepublik<br /><br /><br /><i><u>Kliknij tu, aby wyłączyć</u></i>';
  275. code += '</div></div></div>';
  276. $('body').append(code);
  277. $('#disableautofighter').click(function() { engine.disable(); });
  278. },
  279. variables : function()
  280. {
  281. if(GM_getValue(engine.prefix+'subversion', '') == '2.0') engine.doUpdateInfo();
  282. var well = unsafeWindow.globalNS.userInfo.energyPerInterval;
  283. engine.mintorecover = well * 2;
  284. engine.mycountryid = unsafeWindow.erepublik.citizen.country;
  285. engine.mycountry = engine.countries[engine.mycountryid];
  286.  
  287. if(GM_getValue(engine.prefix+'steps', '') == '') engine.defaultSteps();
  288. },
  289. fightUntil : function(hp)
  290. {
  291. var sumhp = engine.energySum(0);
  292. var hits = Math.ceil((sumhp - hp) / 10);
  293. var well = engine.energySum(1);
  294. hits = Math.min(hits, Math.ceil(well / 10) - 4);
  295. engine.fightsLeft = hits;
  296. engine.timer = setInterval(function() { engine.fight(); }, 1200);
  297. },
  298. fight : function()
  299. {
  300. if(engine.fightsLeft <= 0)
  301. {
  302. engine.fightsLeft = 0;
  303. clearTimeout(engine.timer);
  304. engine.timer = null;
  305. engine.resetSteps();
  306. GM_setValue(engine.prefix+'dontcycle', true);
  307. engine.moveToPage('/en');
  308. return;
  309. }
  310. if(!$('#fight_btn').is(':visible'))
  311. {
  312. clearTimeout(engine.timer);
  313. engine.nextStep();
  314. return;
  315. }
  316. if($('#loader').is(':visible')) return;
  317. unsafeWindow.shoot();
  318. },
  319. nextStep : function()
  320. {
  321. var step = GM_getValue(engine.prefix+'step', 0);
  322. var steps = GM_getValue(engine.prefix+'steps', '[]');
  323. eval('steps = '+steps);
  324.  
  325. if(steps[step] == 'tp' || steps[step] == 'all')
  326. {
  327. var fighti = GM_getValue(engine.prefix+'fighti', 0);
  328. var fights = GM_getValue(engine.prefix+'fights', '[]');
  329. eval('fights = '+fights);
  330. fighti++;
  331. if(fights[fighti])
  332. {
  333. GM_setValue(engine.prefix+'fighti', fighti);
  334. engine.moveToFight(fights[fighti][0], fights[fighti][1]);
  335. return;
  336. }
  337. else
  338. {
  339. GM_setValue(engine.prefix+'fighti', 0);
  340. GM_setValue(engine.prefix+'fights', '[]');
  341. }
  342. }
  343.  
  344. step++;
  345. if(!steps[step])
  346. {
  347. GM_setValue(engine.prefix+'dontcycle', true);
  348. step = 0;
  349. }
  350. GM_setValue(engine.prefix+'step', step);
  351. setTimeout(function() { engine.moveToPage('/en'); }, 500);
  352. },
  353. resetSteps : function()
  354. {
  355. GM_setValue(engine.prefix+'step', 0);
  356. GM_setValue(engine.prefix+'fighti', 0);
  357. GM_setValue(engine.prefix+'fights', '[]');
  358. },
  359. moveToFight : function(fid, sid)
  360. {
  361. $.ajax('http://www.erepublik.com/en/military/battlefield-choose-side/'+fid+'/'+sid, { 'async' : false });
  362. engine.moveToPage('http://www.erepublik.com/en/military/battlefield/'+fid);
  363. },
  364. doFights : function()
  365. {
  366. var ifdont = GM_getValue(engine.prefix+'dontcycle', false);
  367. if(ifdont || engine.energySum(1) <= engine.minhp)
  368. {
  369. engine.resetSteps();
  370. GM_setValue(engine.prefix+'dontcycle', false);
  371. return;
  372. }
  373.  
  374. var step = GM_getValue(engine.prefix+'step', 0);
  375. var steps = GM_getValue(engine.prefix+'steps', '[]');
  376. eval('steps = '+steps);
  377. var row = steps[step];
  378.  
  379. if(engine.energySum() <= row[2])
  380. {
  381. engine.resetSteps();
  382. GM_setValue(engine.prefix+'dontcycle', false);
  383. return;
  384. }
  385.  
  386. if(row[0] == 'battle')
  387. {
  388. if(unsafeWindow.window.location.toString().indexOf('military/battlefield/'+row[1][0]) > -1)
  389. {
  390. engine.fightUntil(row[2]);
  391. }
  392. else
  393. {
  394. engine.moveToFight(row[1][0], row[1][1]);
  395. }
  396. }
  397. else
  398. {
  399. if(unsafeWindow.window.location.toString().indexOf('military/battlefield/') > -1)
  400. {
  401. engine.fightUntil(row[2]);
  402. }
  403. else if(unsafeWindow.window.location.toString().indexOf('military/campaigns') > -1)
  404. {
  405. var objs;
  406. if(row[0] == 'tp')
  407. {
  408. objs = $('ul.country_battles li img.side_flags[title="'+engine.mycountry+'"], ul.bod_listing li img.side_flags[title="'+engine.mycountry+'"], ul.allies_battles li img.side_flags[title="'+engine.mycountry+'"]').parent();
  409. }
  410. else if(row[0] == 'all')
  411. {
  412. objs = $('ul.country_battles li, ul.bod_listing li, ul.allies_battles li');
  413. }
  414. else
  415. {
  416. objs = $('#cosczegoniema');
  417. }
  418.  
  419. var fightfor, tmpfight, fights = [], firstimg, elem;
  420. for(var j = 0; j < objs.length; j++)
  421. {
  422. elem = objs.eq(j);
  423. if(!elem.attr('id')) elem = elem.parent();
  424. firstimg = elem.find('img.side_flags:eq(0)');
  425.  
  426. if(firstimg.attr('title') == engine.mycountry || elem.find('img.mpp_sign').hasClass('one')) { }
  427. else firstimg = elem.find('img.side_flags:eq(1)');
  428.  
  429. fightfor = engine.searchArray(firstimg.attr('title'), engine.countries);
  430. tmpfight = elem.attr('id');
  431. tmpfight = parseInt(tmpfight.substring(tmpfight.lastIndexOf('-')+1));
  432. if(!engine.inArray(tmpfight, row[1])) fights[fights.length] = [tmpfight, fightfor];
  433. }
  434. GM_setValue(engine.prefix+'fighti', 0);
  435. GM_setValue(engine.prefix+'fights', JSON.stringify(fights));
  436. if(fights.length > 0) engine.moveToFight(fights[0][0], fights[0][1]);
  437. else engine.nextStep();
  438. }
  439. else
  440. {
  441. setTimeout(function() { engine.moveToPage('/en/military/campaigns'); }, 500);
  442. }
  443. }
  444. },
  445. addhits : function(num)
  446. {
  447. setTimeout(function()
  448. {
  449. engine.fightsLeft -= num;
  450. }, 0);
  451. },
  452. modifiedFunction : function(data, status, jq)
  453. {
  454. if(jq.url.indexOf('military/fight-shoo') > -1)
  455. {
  456. var text = status.responseText;
  457. var json = JSON.parse(text);
  458. if(!json.error && (json.message == "ENEMY_KILLED" || json.message == "OK"))
  459. {
  460. var hits = json.user.earnedXp;
  461. engine.addhits(hits);
  462. }
  463. else
  464. {
  465. clearTimeout(engine.timer);
  466. engine.nextStep();
  467. }
  468. }
  469. },
  470. modifyFunction : function()
  471. {
  472. if(GM_getValue(engine.prefix+'subversion', '') == '2.0') engine.doUpdateInfo();
  473.  
  474. register_event('autofightererepublik_myevent', function() { engine.modifiedFunction(unsafeWindow.autofightererepublik_myevent_data.data, unsafeWindow.autofightererepublik_myevent_data.status, unsafeWindow.autofightererepublik_myevent_data.jq); }, function()
  475. {
  476. window.$j(document).ajaxSuccess(function(data, status, jq)
  477. {
  478. window.autofightererepublik_myevent_data = {data : data, status : status, jq : jq};
  479. var event = document.createEvent("Event");
  480. event.initEvent("autofightererepublik_myevent", true, true);
  481. document.dispatchEvent(event);
  482. }
  483. );
  484. }
  485. );
  486. },
  487. checkLanguage : function()
  488. {
  489. if(unsafeWindow.document.cookie.indexOf('erpk_plang=en') == -1)
  490. {
  491. unsafeWindow.document.cookie = 'erpk_plang=;expire=0;domain=.erepublik.com;path=/';
  492. unsafeWindow.document.cookie = 'erpk=;expire=0;domain=.erepublik.com;path=/';
  493. $.ajax('/en', { 'async' : false });
  494. var newurl = unsafeWindow.document.location.toString().replace(/com\/[a-z]+/, 'com/en');
  495. engine.moveToPage(newurl);
  496. }
  497. },
  498. moveToPage : function(url, pure)
  499. {
  500. unsafeWindow.window.location = url+(!pure ? '?aff' : '');
  501. },
  502. disableHpRecoveryOnce : function()
  503. {
  504. $('#eatFoodTooltip>p').last().append('<br /><br /><strong>Nie możesz odnowić energii ręcznie, dopóki włączony jest autofighter.</strong>');
  505. $('#DailyConsumtionTrigger').addClass('disabled');
  506. },
  507. disableHpRecoveryCycle : function()
  508. {
  509. $('#DailyConsumtionTrigger').addClass('disabled');
  510. },
  511. URLenabled : function()
  512. {
  513. if(unsafeWindow.window.location.toString().indexOf('?aff') > -1) return true;
  514. return false;
  515. },
  516. init : function()
  517. {
  518. this.checkVersion();
  519. this.variables();
  520. this.checkLanguage();
  521. if(this.enabled() && this.URLenabled())
  522. {
  523. this.recoverEnergy();
  524. this.modifyFunction();
  525. this.doLayer();
  526. this.doFights();
  527. setTimeout(function() { engine.resetSteps(); engine.moveToPage('/en'); }, 3 * 60 * 1000);
  528. }
  529. else
  530. {
  531. if(this.enabled())
  532. {
  533. this.disableHpRecoveryOnce();
  534. setInterval(function() { engine.disableHpRecoveryCycle(); }, 500);
  535. this.setAltCode();
  536. }
  537. else
  538. {
  539. this.setCode();
  540. this.loadSteps();
  541. }
  542. }
  543. }
  544. };
  545.  
  546. $(function()
  547. {
  548. engine.init();
  549. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement