Created
June 21, 2020 22:07
-
-
Save Kreijstal/5d2196a97b7e3ef9f2c71cca1e7437c6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* This is a JavaScript Scratchpad. | |
* | |
* Enter some JavaScript, then Right Click or choose from the Execute Menu: | |
* 1. Run to evaluate the selected text (Ctrl+r), | |
* 2. Inspect to bring up an Object Inspector on the result (Ctrl+i), or, | |
* 3. Display to insert the result in a comment after the selection. (Ctrl+l) | |
*/ | |
function getS(NUE){wosh=[];var l;Array.prototype.forEach.call((function(){var arr = [],nl=document.getElementsByClassName("botTitle");l=nl.length | |
for(var i = 0, n; n = nl[i]; ++i) arr.push(n);return arr.sort(function(a,b){return b.parentNode.parentNode.getElementsByClassName('botLVL')[0].childNodes[2].textContent-a.parentNode.parentNode.getElementsByClassName('botLVL')[0].childNodes[2].textContent})})(), function (a) { | |
var b = a.getElementsByTagName('a')[0]; | |
HTTP(b.href, function (xhr) { | |
var div = document.createElement('div'), | |
s = ""; | |
div.innerHTML = xhr.responseText; | |
Array.prototype.forEach.call(div.getElementsByClassName('col-xs-4'), function (a) { | |
s += a.textContent.trim()+" " | |
}); | |
//console.log("https://battlebots.co/js/backend_op/battles/battle_create_preview_bot.php?id=7325"+b.href.match(/[0-9]+$/)[0]); | |
HTTP("https://battlebots.co/js/backend_op/battles/battle_create_preview_bot.php?id="+NUE+"&id2="+b.href.match(/[0-9]+$/)[0], function (xhr) { | |
var div2 = document.createElement('div'); | |
div2.innerHTML = xhr.responseText; | |
if(wosh.push([div2.getElementsByTagName('script')[0].innerHTML.match(/>.*</)[0],b.href,b.textContent,s,div.getElementsByClassName('botLVL')[0].textContent])==l){ | |
wosh.sort(function(a,b){return b[b.length-1].match(/[0-9]+/)[0]-a[a.length-1].match(/[0-9]+/)[0]}).forEach(function(a){console.log(a)}) | |
} | |
}); | |
}) | |
});} | |
function HTTP(url, callback, method, post, headers) { | |
//headers is an object like this {Connection:"keep-alive"} | |
function createXMLHttpRequest() { | |
if (typeof XMLHttpRequest != 'undefined') { | |
return new XMLHttpRequest(); | |
} else if (typeof window.ActiveXObject != 'undefined') { | |
try { | |
return new ActiveXObject('Msxml2.XMLHTTP.4.0'); | |
} catch (e) { | |
try { | |
return new ActiveXObject('MSXML2.XMLHTTP'); | |
} catch (e) { | |
try { | |
return new ActiveXObject('Microsoft.XMLHTTP'); | |
} catch (e) { | |
return null; | |
} | |
} | |
} | |
} | |
} | |
function looProp(object, callback) { | |
var a; | |
for (a in object) { | |
if (object.hasOwnProperty(a)) callback.call(object, a, object[a]); | |
} | |
} | |
method = method || 'GET'; | |
var xhr = createXMLHttpRequest(); | |
if (xhr) { | |
xhr.open(method, url, true); | |
looProp(headers, function (a, b) { | |
xhr.setRequestHeader(a, b) | |
}) | |
xhr.onloadend = function () { | |
if (xhr.readyState == xhr.DONE) { | |
callback(xhr) | |
} | |
}; | |
xhr.send(post); | |
return xhr; | |
} else { | |
return null; | |
} | |
} | |
function getBotStats(x,callbak,l){ | |
//console.log("shit",l) | |
if(isNaN(l)){l=0}else{l++} | |
HTTP("https://battlebots.co/bot?id="+x,function(e){ | |
if(e.status===0){if(l>400){alertify.alert("There's no internet or something is very wrong");callbak(null)}else getBotStats(x,callbak,l)}else{ | |
var k=document.createElement("div"),stuff={},h,d,c | |
k.innerHTML=e.responseText; | |
Array.prototype.some.call((d=document.getElementsByTagName('strong')),function(a,b){if(a.getAttribute("data-userdata-credits")===""){c=parseInt(d[b].textContent.replace(/,/,"")) | |
return true}}) | |
stuff.credits=c | |
stuff.id=x; | |
stuff.title=k.getElementsByClassName("botTitle")[0].textContent; | |
stuff.level=k.getElementsByClassName("botLVL")[0].childNodes[1].textContent.trim(); | |
stuff.image=k.getElementsByClassName("botIMG")[0].children[0].src; | |
stuff.available=(h=k.getElementsByClassName('botData')[0].children[2])&&h.textContent | |
stuff.DMG=(h=k.getElementsByClassName("botDMG")[0])&&h.textContent.trim(); | |
stuff.energy=(h=k.getElementsByClassName("botEnergy")[0])&&h.textContent.trim(); | |
stuff.isBusy=(/charging|repairing/.test(k.getElementsByClassName('bot')[0].className)) | |
stuff.countdown=(h=k.getElementsByClassName("countdowner")[0])&&h.getAttribute("data-time") | |
stuff.energyToBattle=+k.getElementsByClassName("botPageInfo")[0].getElementsByClassName("label")[0].childNodes[0].textContent | |
stuff.cityNode=(h=k.getElementsByTagName('h4')[0].getElementsByTagName('a')[0])&&+h.href.split('=')[1] | |
//console.log(k.getElementsByTagName('h4')[0].getElementsByTagName('a')[0]) | |
callbak(stuff)} | |
}); | |
} | |
function doJob(attaker,defendants){//Battle attack with defendants as soon as possiblu, don't care about results, yet. | |
var isBusy=true,i=0; | |
function rechek(){var asd;getBotStats(attaker,checkIfAttackerIsReady);alertify.log("RECHECK "+i)} | |
function checkIfAttackerIsReady(a){if(a===null){setTimeout(recheck,10000);return false}if(a.credits<50&&wtf++<MAXSPEND){HTTP("https://battlebots.co/market?purchase=true&type=resources&value=credits500",Function())}if(isBusy=a.isBusy){alertify.log(a.title+" seems busy :"+(1000*((+a.countdown))-Date.now())/1000+" seconds");setTimeout(rechek,((asd=1000*((+a.countdown))-Date.now()))>0?asd:2000);return false} | |
if((a.DMG!="100"&&(a.DMG!="0"?!Math.floor(Math.random()*5):true))){fixBot(attaker,function(){alertify.log("DAMAGE:"+a.DMG+" ,attempt to fix bot "+attaker),isBusy=true,setTimeout(rechek,10000)});return false} | |
var y=a.energy.split('/') | |
if(y[0]!==y[1]&&(+y[0]+a.energyToBattle>=0?!Math.floor(Math.random()*10):true)){rechargeBot(attaker,function(){alertify.log("I MAY HAVE SPEND "+(y[1]-y[0])*5+" credits recharging bot!!"),isBusy=true;setTimeout(rechek,30000)}) | |
return false} | |
getBotStats(defendants[i++],checkIfDefendantIsReady);i%=defendants.length; | |
} | |
function checkIfDefendantIsReady(defender){ | |
if(defender===null){setTimeout(recheck,10000)} | |
if(isDefenderAvailable=/battle/i.test(defender.available)){ | |
if(!isBusy){battle(attaker,defender.id,function(){alertify.log("HUEHUEHUEHUEHUEHUEHUEHUE")});isBusy=true} | |
}else{alertify.log(defender.title+" is not availabe for battle")} | |
setTimeout(rechek,1000) | |
} | |
function fixBot(id,c){ | |
HTTP("//battlebots.co/js/backend_op/bots/bot_repair.php?id="+id,c); | |
} | |
function rechargeBot(id,c){HTTP("//battlebots.co/js/backend_op/bots/bot_charge.php?id="+id,c)}; | |
function battle(id1,id2,c){HTTP("//battlebots.co/battle?offenderID="+id1+"&defenderID="+id2,c) | |
} | |
rechek() | |
} | |
wtf=0;MAXSPEND=0; | |
(function repair(){var k=arguments.callee;HTTP("//battlebots.co/mybots?repairall",function(){setTimeout(k,60000*10)})})() | |
doJob(8081,[5205,248,3664,591,1075,2465,5780,3041,4038,2709,5400,4212,8082,2315,2578,4152,6626,5200,6230,6331,7701,2824,5796,3965,7320,2813,6616,7134,5041,5918,454,437,5853,1188,566,426,2781,348,991,6354,6978,2119,1020,2178]) | |
doJob(7293,[728,944,2072,1123,5346,69,775,453,7325,4103,661,1922,319,1346,484,374,737,1046]) | |
doJob(7743,[4212,8082,2315,2578,4152,6626,5200,6230,6331,7701,2824,5796,3965,7320,2813,6616,7134,5041,5918,454,437,5853,1188,566,426,2781,348,991,6354,6978,2119,1020,2178]) | |
doJob(7252,[944,2072,1123,69,775,248,5205,89,360,338,2332,1855,443,2447,4185,65,1221,7589,705,2296,5782,8032,86,3800,674,355,309,5827,1117]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment