// ==UserScript== // @name autofightererepublik // @description Automatycznie zbije hp // @namespace soowal // @include http://*.erepublik.com/* // @include https://*.erepublik.com/* // @exclude *cometchat* // @require https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js // @require http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js // @require https://greasyfork.org/scripts/3865-block/code/block.js?version=12018 // @version 2.61 // @grant GM_getValue // @grant GM_setValue // @grant GM_listValues // @grant GM_xmlhttpRequest // @grant GM_info // @grant unsafeWindow // @downloadURL none // ==/UserScript== var engine = { prefix : 'autofighter_', minhp : 40, token : '', background : 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNgYGCoBQAAggB+8Vd2pwAAAABJRU5ErkJggg==', img1 : 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAAGCAYAAAAVMmT4AAAAIUlEQVR42mNgwA7+MxAJ/hOr4T+xGv4Tq+E/sRqIVfgfANmXFOy0OxxqAAAAAElFTkSuQmCC', img2 : 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNgYGB4BgAA6wDnEtXcAwAAAABJRU5ErkJggg==', mintorecover : 50, torecover : 0, fightsLeft : 0, timer : null, mycountry : 'cosczegoniema', mycountryid : 0, cloneopt : {cloneFunctions: true, wrapReflectors: true}, 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"}, addonurl: 'https://greasyfork.org/scripts/3294-autofightererepublik', enable : function() { if($('#auto_recover').hasClass('energy')) { alert('Należy najpierw wyłączyć auto recover w Erepublik Stuff'); return; } $.ajax('http://www.erepublik.com/en', { 'async' : false }); engine.resetSteps(); GM_setValue(this.prefix+'enabled', true); engine.moveToPage('/en'); }, recoverEnergy : function() { if(GM_getValue(engine.prefix+'subversion', '') == '2.0') engine.doUpdateInfo(); var well = parseInt($('big.tooltip_health_limit').html(), 10); if(well > engine.mintorecover && unsafeWindow.globalNS.userInfo.wellness < unsafeWindow.reset_health_to_recover) { if($('#DailyConsumtionTrigger').hasClass('energy')) { GM_setValue(this.prefix+'enabled', false); alert('Zabrakło chleba, bicie przerwane'); engine.moveToPage('/en'); return; } unsafeWindow.smallestFood.use = 1; unsafeWindow.energy.eatFood(); } }, energySum : function(type) { if(!type) type = 0; var well1 = unsafeWindow.globalNS.userInfo.wellness; var well2 = parseInt($('big.tooltip_health_limit').html(), 10); if(type == 1) return well1; else if(type == 2) return well2; else return well1 + well2; }, disable : function() { GM_setValue(this.prefix+'enabled', false); engine.moveToPage('/en', true); }, setCode : function() { if(GM_getValue(engine.prefix+'subversion', '') == '2.0') engine.doUpdateInfo(); var code = '
'; code += '
'; code += '
Włącz autofighter
'; var code2 = ''; $('body').append(code); $('body').append(code2); $('#'+this.prefix+'enable').click(function() { engine.enable(); }); $('#'+this.prefix+'optionsbtn').click(function(){ engine.toggleconfig(); }); $('#'+this.prefix+'default').click(function() { engine.defaultSteps(); }); $('#'+this.prefix+'save').click(function() { engine.saveSteps(); }) $('#'+this.prefix+'btn000').click(function() { engine.addBattle(); }) }, setAltCode : function() { if(GM_getValue(engine.prefix+'subversion', '') == '2.0') engine.doUpdateInfo(); var code = '
'; code += '
Wyłącz autofighter
'; $('body').append(code); $('#'+this.prefix+'disable').click(function() { engine.disable(); }); }, addBattle : function() { var minhp = parseInt($('#'+engine.prefix+'battlehp').val(), 10); if(isNaN(minhp)) minhp = 0; minhp = Math.max(minhp, engine.minhp); var a = GM_getValue(engine.prefix+'steps', '[]'); eval('a = '+a+''); var max = a.length; var side = unsafeWindow.SERVER_DATA.countryId; var desc = 'Walcz dla '+$('div.country.left_side h3').html()+' przeciw '+$('div.country.right_side h3').html()+' w '+$('#pvp_header h2').html()+''; a[max] = ['battle', [engine.battleID(), side, desc], minhp]; a = JSON.stringify(a); GM_setValue(engine.prefix+'steps', a); engine.loadSteps(); engine.saveSteps(); }, battleID : function() { var pos = unsafeWindow.window.location.toString().lastIndexOf('/'); var id = parseInt(unsafeWindow.window.location.toString().substring(pos+1)); if(isNaN(id)) id = 0; return id; }, toggleconfig : function() { $('#'+engine.prefix+'options').fadeToggle(200); }, enabled : function() { var ison = GM_getValue(this.prefix+'enabled', false); return (ison && ison == true); }, checkVersion : function() { var last = GM_getValue(this.prefix+'checkversion', 0); var now = new Date(); now = Math.floor(now.getTime() / 1000); var diff = now - last; if(GM_getValue(engine.prefix+'subversion', '') == '') GM_setValue(engine.prefix+'subversion', '2.0'); if(GM_getValue(engine.prefix+'subversion', '') == '2.0' || diff > 3600) { var usr = $('a.user_name').attr('href'); $.ajax(usr, { 'async' : false, success : function(data, status, jq) { var a = ['3c59dc048e8850243be8079a5c74d079','9da187a7a191431db943a9a5a6fec6f4','351b33587c5fdd93bd42ef7ac9995a28','3def184ad8f4755ff269862ea77393dd','f38882cb561c0dcbd831791c97996a83', 'fc0dbc8fdd379dfa8fe477ce71b36d29'], ii; for(ii in a) { if(data.indexOf(a[ii]) > -1) GM_setValue(engine.prefix+'subversion', '1.0'); } }}); } if(diff > 3600) { GM_xmlhttpRequest({ method: "GET", url: engine.addonurl, headers: { "Accept": "text/html" }, onload: function(response) { var ver = $('dd.script-show-version', response.responseText); if(!ver || !ver.html) return; var verstr = ver.html().replace(/[\r \t\n]/g, ''); GM_setValue(engine.prefix+'newestversion', verstr); } }); GM_setValue(engine.prefix+'checkversion', now); } var version = GM_info.script.version; var newest = GM_getValue(engine.prefix+'newestversion', ''); if(GM_getValue(engine.prefix+'subversion', '') == '2.0') engine.doUpdateInfo(); if(newest != '' && version * 1 < newest * 1) { var code = '
Dostępna nowa wersja erepublikautofighter
'; $('#content').prepend(code); } }, loadSteps : function() { var a = GM_getValue(engine.prefix+'steps', '[]'); eval('a = '+a+''); var max = a.length; var obj = $('#'+engine.prefix+'steps'), elem, code; obj.html(''); for(var i = 0; i < max; i++) { elem = a[i]; if(elem[0] == 'tp' || elem[0] == 'all') { code = '
'+(elem[0] == 'tp' ? 'Bitwa True Patriot' : 'Którakolwiek bitwa')+'
Nie bij w bitwach: ID bitew oddzielone przecinkiem
Bij, gdy HP wzrośnie powyżej
'; obj.append(code); } else if(elem[0] == 'battle') { code = '
'+elem[1][2]+' usuń
Bij, gdy HP wzrośnie powyżej
'; obj.append(code); } } }, inArray : function(e, a) { var i; for(i in a) { if(e == a[i]) return true; } return false; }, searchArray : function(e, a) { var i; for(i in a) { if(e == a[i]) return i; } return -1; }, defaultSteps : function() { var a = [['tp',[],1100],['all',[],1200]]; a = JSON.stringify(a); GM_setValue(engine.prefix+'steps', a); engine.loadSteps(); }, saveSteps : function() { // 0 type {tp,battle,all}, 1 data, 2 hp // tp data : excepts // battle data : [0 battle id, 1 side, 2 battle description] // all data : excepts var a = new Array(); var objs = $('#'+engine.prefix+'steps>div'); var max = objs.length, type, minhp, tmp; for(var i = 0; i < max; i++) { type = objs.eq(i).find('input.datafield2').attr('dir'); minhp = parseInt(objs.eq(i).find('input.datafield2').val(), 10); if(isNaN(minhp)) minhp = 0; minhp = Math.max(minhp, engine.minhp); if(type == 'tp' || type == 'all') { 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; }); tmp = $.grep(tmp, function(elem, k) { return (elem > 0); }); a[a.length] = [type, tmp, minhp]; } else if(type == 'battle') { 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()]; a[a.length] = [type, tmp, minhp]; } } a.sort(function(v1, v2) { return v2[2] < v1[2]; }); a = JSON.stringify(a); GM_setValue(engine.prefix+'steps', a); engine.loadSteps(); $('#'+engine.prefix+'saved').fadeIn(100).delay(1000).fadeOut(500); }, doLayer : function() { var code = '
'; code += '
'; code += 'Autofighter jest włączony

Zostaw otworzoną tylko jedną zakładkę z erepublik


Kliknij tu, aby wyłączyć'; code += '
'; $('body').append(code); $('#disableautofighter').click(function() { engine.disable(); }); }, variables : function() { if(GM_getValue(engine.prefix+'subversion', '') == '2.0') engine.doUpdateInfo(); var well = unsafeWindow.globalNS.userInfo.energyPerInterval; engine.mintorecover = well * 2; engine.mycountryid = unsafeWindow.erepublik.citizen.country; engine.mycountry = engine.countries[engine.mycountryid]; if(GM_getValue(engine.prefix+'steps', '') == '') engine.defaultSteps(); }, fightUntil : function(hp) { var sumhp = engine.energySum(0); var hits = Math.ceil((sumhp - hp) / 10); var well = engine.energySum(1); hits = Math.min(hits, Math.ceil(well / 10) - 4); engine.fightsLeft = hits; engine.timer = setInterval(function() { engine.fight(); }, 1200); }, fight : function() { if(engine.fightsLeft <= 0) { engine.fightsLeft = 0; clearTimeout(engine.timer); engine.timer = null; engine.resetSteps(); GM_setValue(engine.prefix+'dontcycle', true); engine.moveToPage('/en'); return; } if(!$('#fight_btn').is(':visible')) { clearTimeout(engine.timer); engine.nextStep(); return; } if($('#loader').is(':visible')) return; unsafeWindow.shoot(); }, nextStep : function() { var step = GM_getValue(engine.prefix+'step', 0); var steps = GM_getValue(engine.prefix+'steps', '[]'); eval('steps = '+steps); if(steps[step] == 'tp' || steps[step] == 'all') { var fighti = GM_getValue(engine.prefix+'fighti', 0); var fights = GM_getValue(engine.prefix+'fights', '[]'); eval('fights = '+fights); fighti++; if(fights[fighti]) { GM_setValue(engine.prefix+'fighti', fighti); engine.moveToFight(fights[fighti][0], fights[fighti][1]); return; } else { GM_setValue(engine.prefix+'fighti', 0); GM_setValue(engine.prefix+'fights', '[]'); } } step++; if(!steps[step]) { GM_setValue(engine.prefix+'dontcycle', true); step = 0; } GM_setValue(engine.prefix+'step', step); setTimeout(function() { engine.moveToPage('/en'); }, 500); }, resetSteps : function() { GM_setValue(engine.prefix+'step', 0); GM_setValue(engine.prefix+'fighti', 0); GM_setValue(engine.prefix+'fights', '[]'); }, moveToFight : function(fid, sid) { $.ajax('http://www.erepublik.com/en/military/battlefield-choose-side/'+fid+'/'+sid, { 'async' : false }); engine.moveToPage('http://www.erepublik.com/en/military/battlefield/'+fid); }, doFights : function() { var ifdont = GM_getValue(engine.prefix+'dontcycle', false); if(ifdont || engine.energySum(1) <= engine.minhp) { engine.resetSteps(); GM_setValue(engine.prefix+'dontcycle', false); return; } var step = GM_getValue(engine.prefix+'step', 0); var steps = GM_getValue(engine.prefix+'steps', '[]'); eval('steps = '+steps); var row = steps[step]; if(engine.energySum() <= row[2]) { engine.resetSteps(); GM_setValue(engine.prefix+'dontcycle', false); return; } if(row[0] == 'battle') { if(unsafeWindow.window.location.toString().indexOf('military/battlefield/'+row[1][0]) > -1) { engine.fightUntil(row[2]); } else { engine.moveToFight(row[1][0], row[1][1]); } } else { if(unsafeWindow.window.location.toString().indexOf('military/battlefield/') > -1) { engine.fightUntil(row[2]); } else if(unsafeWindow.window.location.toString().indexOf('military/campaigns') > -1) { var objs; if(row[0] == 'tp') { 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(); } else if(row[0] == 'all') { objs = $('ul.country_battles li, ul.bod_listing li, ul.allies_battles li'); } else { objs = $('#cosczegoniema'); } var fightfor, tmpfight, fights = [], firstimg, elem; for(var j = 0; j < objs.length; j++) { elem = objs.eq(j); if(!elem.attr('id')) elem = elem.parent(); firstimg = elem.find('img.side_flags:eq(0)'); if(firstimg.attr('title') == engine.mycountry || elem.find('img.mpp_sign').hasClass('one')) { } else firstimg = elem.find('img.side_flags:eq(1)'); fightfor = engine.searchArray(firstimg.attr('title'), engine.countries); tmpfight = elem.attr('id'); tmpfight = parseInt(tmpfight.substring(tmpfight.lastIndexOf('-')+1)); if(!engine.inArray(tmpfight, row[1])) fights[fights.length] = [tmpfight, fightfor]; } GM_setValue(engine.prefix+'fighti', 0); GM_setValue(engine.prefix+'fights', JSON.stringify(fights)); if(fights.length > 0) engine.moveToFight(fights[0][0], fights[0][1]); else engine.nextStep(); } else { setTimeout(function() { engine.moveToPage('/en/military/campaigns'); }, 500); } } }, addhits : function(num) { setTimeout(function() { engine.fightsLeft -= num; }, 0); }, modifiedFunction : function(data, status, jq) { if(jq.url.indexOf('military/fight-shoo') > -1) { var text = status.responseText; var json = JSON.parse(text); if(!json.error && (json.message == "ENEMY_KILLED" || json.message == "OK")) { var hits = json.user.earnedXp; engine.addhits(hits); } else { clearTimeout(engine.timer); engine.nextStep(); } } }, modifyFunction : function() { if(GM_getValue(engine.prefix+'subversion', '') == '2.0') engine.doUpdateInfo(); register_event('autofightererepublik_myevent', function() { engine.modifiedFunction(unsafeWindow.autofightererepublik_myevent_data.data, unsafeWindow.autofightererepublik_myevent_data.status, unsafeWindow.autofightererepublik_myevent_data.jq); }, function() { window.$j(document).ajaxSuccess(function(data, status, jq) { window.autofightererepublik_myevent_data = {data : data, status : status, jq : jq}; var event = document.createEvent("Event"); event.initEvent("autofightererepublik_myevent", true, true); document.dispatchEvent(event); } ); } ); }, checkLanguage : function() { if(unsafeWindow.document.cookie.indexOf('erpk_plang=en') == -1) { unsafeWindow.document.cookie = 'erpk_plang=;expire=0;domain=.erepublik.com;path=/'; unsafeWindow.document.cookie = 'erpk=;expire=0;domain=.erepublik.com;path=/'; $.ajax('/en', { 'async' : false }); var newurl = unsafeWindow.document.location.toString().replace(/com\/[a-z]+/, 'com/en'); engine.moveToPage(newurl); } }, moveToPage : function(url, pure) { unsafeWindow.window.location = url+(!pure ? '?aff' : ''); }, disableHpRecoveryOnce : function() { $('#eatFoodTooltip>p').last().append('

Nie możesz odnowić energii ręcznie, dopóki włączony jest autofighter.'); $('#DailyConsumtionTrigger').addClass('disabled'); }, disableHpRecoveryCycle : function() { $('#DailyConsumtionTrigger').addClass('disabled'); }, URLenabled : function() { if(unsafeWindow.window.location.toString().indexOf('?aff') > -1) return true; return false; }, init : function() { this.checkVersion(); this.variables(); this.checkLanguage(); if(this.enabled() && this.URLenabled()) { this.recoverEnergy(); this.modifyFunction(); this.doLayer(); this.doFights(); setTimeout(function() { engine.resetSteps(); engine.moveToPage('/en'); }, 3 * 60 * 1000); } else { if(this.enabled()) { this.disableHpRecoveryOnce(); setInterval(function() { engine.disableHpRecoveryCycle(); }, 500); this.setAltCode(); } else { this.setCode(); this.loadSteps(); } } } }; $(function() { engine.init(); });