BumRush 1.0

By qContinuum Last update Aug 21, 2008 — Installed 511 times.
// ==UserScript==
// @name           BumRush
// @namespace      BumRush
// @description    BumRush
// @include        http://*.hobowars.com/game/*
// @include        http://hobowars.com/game/*
// ==/UserScript==

if(GM_getValue("enable_lockringthrow")==null)GM_setValue("enable_lockringthrow",true);if(GM_getValue("enable_grailprompt")==null)GM_setValue("enable_grailprompt",true);if(GM_getValue("enable_foodprompt")==null)GM_setValue("enable_foodprompt",true);if(GM_getValue("enable_hillautosignup")==null)GM_setValue("enable_hillautosignup",false);if(GM_getValue("enable_garageautoback")==null)GM_setValue("enable_garageautoback",true);if(GM_getValue("enable_hospitalautoheal")==null)GM_setValue("enable_hospitalautoheal",false);if(GM_getValue("hospitalautoheal_choice")==null)GM_setValue("hospitalautoheal_choice",0);if(GM_getValue("enable_cityautoexplore")==null)GM_setValue("enable_cityautoexplore",false);if(GM_getValue("enable_universitylocktrain")==null)GM_setValue("enable_universitylocktrain",false);if(GM_getValue("universitylocktrain_choice")==null)GM_setValue("universitylocktrain_choice",0);if(GM_getValue("university_solved")==null)GM_setValue("university_solved",false);if(GM_getValue("university_solving")==null)GM_setValue("university_solving",false);var args=getArgs(),layout=null,whiteBox,whiteBoxHTML="",menuBox,configActive=false,respectLevels=[[25000,"Homeless","Lowlife"],[50000,"Bum","Delinquent"],[100000,"Freeloader","Thug"],[200000,"Drifter","Outcast"],[400000,"Showered","Addict"],[800000,"Citizen","Tramp"],[1600000,"Worker","Criminal"],[3200000,"Medic","Mental Patient"],[5000000,"Preacher","Murderer"],[8000000,"Actor","Hit Man"],[14000000,"Officer","Mass Murderer"],[20000000,"Peacemaker","Politician"],[30000000,"John McClane","Freddy Kreuger"]],uniPuzzle=Array(Array(1,1,1,1),Array(1,1,1,1),Array(1,1,1,1),Array(1,1,1,1));if(setupLayout()){setupConfig();if(args["cmd"]==null||args["cmd"]==""){showNextRespectLevelInfo();if(GM_getValue("enable_lockringthrow"))lockRingThrow();if(GM_getValue("enable_grailprompt"))setupGrailPrompt();}else if(args["cmd"]=="food"){if(GM_getValue("enable_foodprompt")) setupFoodPrompts();}else if(args["cmd"]=="hospital"){if(GM_getValue("enable_hospitalautoheal")) doHospitalAutoheal();}else if(args["cmd"]=="hill"){if(args["do"]=="greg"&&GM_getValue("enable_hillautosignup")) doSuicideHillAutoSignup();else if(GM_getValue("enable_garageautoback")) doGarageAutoback();}else if(args["cmd"]=="explore"&&args["do"]=="move"){if(GM_getValue("enable_cityautoexplore")) doCityAutoExplore();}else if(args["cmd"]=="uni"){setupUniversity();}}function setupConfig(){var a=menuBox.innerHTML.indexOf("</li>");if(a==-1)return;menuBox.innerHTML=menuBox.innerHTML.substring(0,a+5)+"<li> <a id=\"BRConfigLink\" href=\"javascript:void(0);\">BumRush</a></li>"+menuBox.innerHTML.substring(a+5);document.getElementById("BRConfigLink").addEventListener("click",displayBRConfiguration,false)}function displayBRConfiguration(){if(configActive)return;configActive=true;whiteBoxHTML=whiteBox.innerHTML;whiteBox.innerHTML="<span style=\"font-size:30px;color:#0066cc;\">BumRush&nbsp;</span><span style=\"color:#888888;\">Version 1.0</span><br><div align=\"right\">Check <a href=\"http://userscripts.org/users/63615/scripts\">here</a> for the latest version</div><hr style=\"color:#888888;border:2px;border-style:dashed\" /><br class=\"clear\"><h1>Configuration</h1><br class=\"clear\"><br class=\"clear\"><h2>Cart</h2><br class=\"clear\"><input type=\"checkbox\" id=\"enable_foodprompt\""+((GM_getValue("enable_foodprompt")==true)?" checked=\"checked\"":"")+">Ask before eating food</input><br class=\"clear\"><br class=\"clear\"><br class=\"clear\"><h2>City</h2><br class=\"clear\"><input type=\"checkbox\" id=\"enable_cityautoexplore\""+((GM_getValue("enable_cityautoexplore")==true)?" checked=\"checked\"":"")+">Automatically Explore City</input><br class=\"clear\"><br class=\"clear\"><br class=\"clear\"><h2>Hospital</h2><br class=\"clear\"><input type=\"checkbox\" id=\"enable_hospitalautoheal\""+((GM_getValue("enable_hospitalautoheal")==true)?" checked=\"checked\"":"")+">Automatically heal from</input>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type=\"radio\" name=\"hospitalautohealchoice\" value=\"0\""+((GM_getValue("hospitalautoheal_choice")==0)?" checked=\"checked\"":"")+">Personal Funds</input>&nbsp;&nbsp;&nbsp;<input type=\"radio\" name=\"hospitalautohealchoice\" value=\"1\""+((GM_getValue("hospitalautoheal_choice")==1)?" checked=\"checked\"":"")+">Gang Funds</input><br class=\"clear\"><br class=\"clear\"><br class=\"clear\"><h2>Living Area</h2><br class=\"clear\"><input type=\"checkbox\" id=\"enable_lockringthrow\""+((GM_getValue("enable_lockringthrow")==true)?" checked=\"checked\"":"")+">Lock ring throw away link</input><br class=\"clear\"><input type=\"checkbox\" id=\"enable_grailprompt\""+((GM_getValue("enable_grailprompt")==true)?" checked=\"checked\"":"")+">Ask before using Hobo Grail</input><br class=\"clear\"><br class=\"clear\"><br class=\"clear\"><h2>Suicide Hill</h2><br class=\"clear\"><input type=\"checkbox\" id=\"enable_hillautosignup\""+((GM_getValue("enable_hillautosignup")==true)?" checked=\"checked\"":"")+">Automatically sign up for race when visiting Greg</input><br class=\"clear\"><input type=\"checkbox\" id=\"enable_garageautoback\""+((GM_getValue("enable_garageautoback")==true)?" checked=\"checked\"":"")+">Return to garage when modifying/selling and there is no back link</input><br class=\"clear\"><br class=\"clear\"><br class=\"clear\"><h2>University</h2><br class=\"clear\"><input type=\"checkbox\" id=\"enable_universitylocktrain\""+((GM_getValue("enable_universitylocktrain")==true)?" checked=\"checked\"":"")+">Lock training to only </input>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type=\"radio\" name=\"universitylocktrainchoice\" value=\"0\""+((GM_getValue("universitylocktrain_choice")==0)?" checked=\"checked\"":"")+">Strength</input>&nbsp;&nbsp;&nbsp;<input type=\"radio\" name=\"universitylocktrainchoice\" value=\"1\""+((GM_getValue("universitylocktrain_choice")==1)?" checked=\"checked\"":"")+">Power</input>&nbsp;&nbsp;&nbsp;<input type=\"radio\" name=\"universitylocktrainchoice\" value=\"2\""+((GM_getValue("universitylocktrain_choice")==2)?" checked=\"checked\"":"")+">Intelligence</input>&nbsp;&nbsp;&nbsp;<input type=\"radio\" name=\"universitylocktrainchoice\" value=\"3\""+((GM_getValue("universitylocktrain_choice")==3)?" checked=\"checked\"":"")+">Speed</input><br class=\"clear\"><br class=\"clear\"><br class=\"clear\"><center><button id=\"BRConfigOKButton\">OK</button><button id=\"BRConfigCancelButton\">Cancel</button></center><br class=\"clear\"><h1>Other Features</h1><br class=\"clear\"><br class=\"clear\"><h2>Living Area:</h2><br class=\"clear\">- Next respect level and points needed until that level are shown<br class=\"clear\"><br class=\"clear\"><br class=\"clear\"><h2>University:</h2><br class=\"clear\">- Auto-calculation of highest points for current puzzle<br class=\"clear\">- Puzzle solver";document.getElementById("BRConfigOKButton").addEventListener("click",saveBRConfiguration,false);document.getElementById("BRConfigCancelButton").addEventListener("click",closeBRConfiguration,false)}function saveBRConfiguration(){inputs=whiteBox.getElementsByTagName('input');for(var a=0;a<inputs.length;a++)if(inputs[a].type=="checkbox")GM_setValue(inputs[a].id,inputs[a].checked);if(document.getElementsByName('hospitalautohealchoice')[0].checked==true)GM_setValue("hospitalautoheal_choice",0);else GM_setValue("hospitalautoheal_choice",1);if(document.getElementsByName('universitylocktrainchoice')[0].checked==true)GM_setValue("universitylocktrain_choice",0);else if(document.getElementsByName('universitylocktrainchoice')[1].checked==true)GM_setValue("universitylocktrain_choice",1);else if(document.getElementsByName('universitylocktrainchoice')[2].checked==true)GM_setValue("universitylocktrain_choice",2);else GM_setValue("universitylocktrain_choice",3);closeBRConfiguration()}function closeBRConfiguration(){if(whiteBoxHTML!=null&&whiteBoxHTML.length>0)whiteBox.innerHTML=whiteBoxHTML;configActive=false}function doSuicideHillAutoSignup(){if(macroCheck())return;var a=whiteBox.innerHTML.indexOf("race?  You have");if(a==-1)return;a=whiteBox.innerHTML.substring(a).indexOf("</b>")+whiteBox.innerHTML.substring(0,a).length-1;if(whiteBox.innerHTML.substring(a,a+1)<1)return;var b=document.getElementsByTagName('form');if(b.length!=1)return;for(var c=0;c<b.length;c++)if(b[c].name=="form1")setTimeout(function(){document.getElementsByTagName('form')[0].submit()},Math.floor(Math.random()*1000))}function doCityAutoExplore(){if(macroCheck())return;var a=[],b=whiteBox.getElementsByTagName('a');for(var c=0;c<b.length;c++)if(b[c].href.indexOf("&cmd=explore&do=move&x=")>-1)a[a.length]=b[c].href;if(a.length!=8)return;var d=a[Math.floor(Math.random()*(a.length-1))];if(d.length<1){alert('Something went wrong while trying to auto-explore...');return}setTimeout(function(){location.href=d},Math.floor(Math.random()*1000))}function doHospitalAutoheal(){if(macroCheck())return;var a=document.getElementsByTagName('a');for(var b=0;b<a.length;b++){if(a[b].text=="I need a good healing, heal me to full health..."&&GM_getValue("hospitalautoheal_choice")==0){var c=a[b].href;setTimeout(function(){location.href=c},Math.floor(Math.random()*1000))}else if(a[b].text=="Let my gang cover part of the cost"&&GM_getValue("hospitalautoheal_choice")==1){var c=a[b].href;setTimeout(function(){location.href=c},Math.floor(Math.random()*1000))}}}function doGarageAutoback(){if(macroCheck())return;if(args["do"]=="unequip_all"||args["do"]=="rename2"||args["do"]=="equip_upg"||(args["do"]=="sell_upg"&&args["doo"]=="1")||(args["do"]=="sell_cart"&&args["doo"]=="1")){var a=location.href.split("?")[0];setTimeout(function(){location.href=a+"?sr="+args["sr"]+"&cl="+((args["cl"]=="9")?"1":parseInt(args["cl"])+1)+"&cmd=hill&do=garage"},Math.floor(Math.random()*1000))}}function lockRingThrow(){if(macroCheck())return;var a=whiteBox.innerHTML.indexOf("do=throw_away");if(a==-1)return;a=whiteBox.innerHTML.substring(0,a);whiteBox.innerHTML=whiteBox.innerHTML.substring(0,a.lastIndexOf('[')+1)+'<strike>T</strike>'+whiteBox.innerHTML.substring(whiteBox.innerHTML.substring(a.length).indexOf(']')+a.length)}function getRespect(){var a=whiteBox.innerHTML.indexOf('Respect: ');if(a!=-1){a=whiteBox.innerHTML.substring(a);a=a.substring(a.indexOf('>')+1);a=a.substring(0,a.indexOf('<')).replace(/\,/g,'');return a}else return false}function showNextRespectLevelInfo(){if(macroCheck())return;var a=getRespect();if(!a)return;var b=whiteBox.innerHTML.indexOf('Respect: ')+4+whiteBox.innerHTML.substring(whiteBox.innerHTML.indexOf('Respect: ')).indexOf('<br>');var c='';var d;var e;for(var f=0;f<=respectLevels.length;f++){if(f==respectLevels.length){d=f;break}if(respectLevels[f][0]>Math.abs(a)){d=f;e=respectLevels[d][0]-Math.abs(a);break}}if(a<0)c="Next Level: <font color=\"#FF1100\">"+((d==respectLevels.length)?"(None)</font><br>":respectLevels[d][2]+"</font><br>[<font color=\"#FF1100\">-"+addCommas(e)+"</font>] Until Next<br>");else c="Next Level: <font color=\"#009900\">"+((d==respectLevels.length)?"(None)</font><br>":respectLevels[d][1]+"</font><br>[<font color=\"#009900\">"+addCommas(e)+"</font>] Until Next<br>");whiteBox.innerHTML=whiteBox.innerHTML.substring(0,b)+c+whiteBox.innerHTML.substring(b)}function addCommas(a){a+='';var b=/(\d+)(\d{3})/;while(b.test(a))a=a.replace(b,'$1'+','+'$2');return a}function setupGrailPrompt(){if(macroCheck())return;var a=document.getElementsByTagName('a');for(var b=0;b<a.length;b++)if(a[b].href.length>10&&a[b].href.substring(a[b].href.length-10)=="&cmd=grail")a[b].href="javascript:if(confirm('Use the Hobo Grail?')) location.href='"+a[b].href+"'; void(0);"}function setupFoodPrompts(){if(macroCheck())return;var a=document.getElementsByTagName('a');for(var b=0;b<a.length;b++)if(a[b].text=="Consume")a[b].href="javascript:if(confirm('Are you sure you want to eat this?')) location.href='"+a[b].href+"'; void(0);"}function setupUniversity(){if(macroCheck())return;loadUniversityPuzzle();if(GM_getValue("university_currentpuzzle")!=puzzleToString(uniPuzzle)){solveUniversityPuzzle()}if(GM_getValue("enable_universitylocktrain"))lockUniversityTrainLinks();showUniversityScore();if(whiteBox.innerHTML.indexOf("<center><b><font color=\"red\">You do not have $50 on you.</font></b></center>")!=-1||whiteBox.innerHTML.indexOf("<center><b><font color=\"red\">You do not have 10 T.</font></b></center>")!=-1)return;if(GM_getValue("university_solving")==true)doNextUniversityMove();else showUniversitySolveButton()}function showUniversityScore(){var a=whiteBox.innerHTML.indexOf("Gain: <font");if(a==-1||GM_getValue("university_maxscore")==null)return;whiteBox.innerHTML=whiteBox.innerHTML.substring(0,a)+"Max Points: <font size=\"2\" color=\"#006600\">"+GM_getValue("university_maxscore")+"</font><br>"+whiteBox.innerHTML.substring(a)}function showUniversitySolveButton(){var a=whiteBox.innerHTML.indexOf("<br><br>NB! Training costs");if(a==-1||GM_getValue("university_maxscore")==null)return;if(getUniversityPuzzleScore()<GM_getValue("university_maxscore")){whiteBox.innerHTML=whiteBox.innerHTML.substring(0,a)+"<br><br><center><button id=\"start_solve\">Solve</button></center>"+whiteBox.innerHTML.substring(a);document.getElementById("start_solve").addEventListener("click",universityStartSolve,false)}else whiteBox.innerHTML=whiteBox.innerHTML.substring(0,a)+"<br><br><center><button id=\"start_solve\" disabled=\"disabled\">Solved</button></center>"+whiteBox.innerHTML.substring(a)}function lockUniversityTrainLinks(){var a=document.getElementsByTagName('a');for(var b=0;b<a.length;b++){if(a[b].href.indexOf("&cmd=uni&do=str")!=-1&&GM_getValue("universitylocktrain_choice")!=0)a[b].style.visibility="hidden";if(a[b].href.indexOf("&cmd=uni&do=pow")!=-1&&GM_getValue("universitylocktrain_choice")!=1)a[b].style.visibility="hidden";if(a[b].href.indexOf("&cmd=uni&do=int")!=-1&&GM_getValue("universitylocktrain_choice")!=2)a[b].style.visibility="hidden";if(a[b].href.indexOf("&cmd=uni&do=spd")!=-1&&GM_getValue("universitylocktrain_choice")!=3)a[b].style.visibility="hidden"}}function universityStartSolve(){GM_setValue("university_solving",true);doNextUniversityMove()}function doNextUniversityMove(){var c={};var a=document.getElementsByTagName('a');for(var b=0;b<a.length;b++){if(a[b].href.indexOf("&do=col&col=1")!=-1)c["E"]=a[b].href;else if(a[b].href.indexOf("&do=col&col=2")!=-1)c["F"]=a[b].href;else if(a[b].href.indexOf("&do=col&col=3")!=-1)c["G"]=a[b].href;else if(a[b].href.indexOf("&do=col&col=4")!=-1)c["H"]=a[b].href;else if(a[b].href.indexOf("&do=row&row=1")!=-1)c["D"]=a[b].href;else if(a[b].href.indexOf("&do=row&row=2")!=-1)c["C"]=a[b].href;else if(a[b].href.indexOf("&do=row&row=3")!=-1)c["B"]=a[b].href;else if(a[b].href.indexOf("&do=row&row=4")!=-1)c["A"]=a[b].href}if(GM_getValue("university_solution").length==0){solveUniversityPuzzle();showUniversitySolveButton();return}var d = c[GM_getValue("university_solution").substring(0,1)];if(d.length<1){solveUniversityPuzzle();showUniversitySolveButton();return}setNextPuzzle(GM_getValue("university_solution").substring(0,1));GM_setValue("university_solution",GM_getValue("university_solution").substring(1));setTimeout(function(){location.href = d},Math.floor(Math.random()*1000))}function setNextPuzzle(a){if(a=="A"||a=="B"||a=="C"||a=="D"){var y;switch(a){case"A":y=3;break;case"B":y=2;break;case"C":y=1;break;case"D":y=0}for(x=0;x<4;x++)((uniPuzzle[y][x]==2)?uniPuzzle[y][x]=0:uniPuzzle[y][x]++)}else{var x;switch(a){case"E":x=0;break;case"F":x=1;break;case"G":x=2;break;case"H":x=3}for(y=0;y<4;y++)((uniPuzzle[y][x]==2)?uniPuzzle[y][x]=0:uniPuzzle[y][x]++)}GM_setValue("university_currentpuzzle",puzzleToString(uniPuzzle))}function getUniversityPuzzleScore(){var a=0;for(var x=0;x<4;x++)for(var y=0;y<4;y++)switch(uniPuzzle[x][y]){case 0:a--;break;case 2:a++}return a}function loadUniversityPuzzle(){var a=whiteBox.getElementsByTagName('img'),x=0,y=0;for(var b=0;b<a.length;b++){if(a[b].title=="yellow"&&a[b].src.indexOf('/yellow.gif')!=-1){uniPuzzle[y][x]=1;x++}else if(a[b].title=="green"&&a[b].src.indexOf('/green.gif')!=-1){uniPuzzle[y][x]=2;x++}else if(a[b].title=="red"&&a[b].src.indexOf('/red.gif')!=-1){uniPuzzle[y][x]=0;x++}if(x>3){x=0;y++}}}function puzzleToString(a){var b="";for(var x=0;x<4;x++)for(var y=0;y<4;y++)b+=""+a[x][y];return b}function stringToPuzzle(a){var b=Array(Array(1,1,1,1),Array(1,1,1,1),Array(1,1,1,1),Array(1,1,1,1));for(var x=0;x<4;x++)for(var y=0;y<4;y++)b[x][y]=a.substring((x*4)+y,1)+0;return b}function solveUniversityPuzzle(){var c,moves,bestMoves=0,bestScore=0,moveString="";var d=0,C2=0,C3=0,C4=0,R1=0,R2=0,R3=0,R4=0;for(var i=0;i<=2;++i){for(var j=0;j<=2;++j){for(var k=0;k<=2;++k){for(var l=0;l<=2;++l){for(var m=0;m<=2;++m){for(var n=0;n<=2;++n){for(var o=0;o<=2;++o){for(var p=0;p<=2;++p){var e=0;var f=Array(i,j,k,l);var g=Array(m,n,o,p);for(var a=0;a<4;++a){for(var b=0;b<4;++b){c=uniPuzzle[a][b]+f[a]+g[b];while(c>2){c-=3}e+=c}}e-=16;moves=i+j+k+l+m+n+o+p;if((e>bestScore)||(e==bestScore&&moves<bestMoves)){bestMoves=moves;bestScore=e;R1=i;R2=j;R3=k;R4=l;d=m;C2=n;C3=o;C4=p}}}}}}}}}if(R1>0)for(var i=0;i<R1;i++)moveString+="D";if(R2>0)for(var i=0;i<R2;i++)moveString+="C";if(R3>0)for(var i=0;i<R3;i++)moveString+="B";if(R4>0)for(var i=0;i<R4;i++)moveString+="A";if(d>0)for(var i=0;i<d;i++)moveString+="E";if(C2>0)for(var i=0;i<C2;i++)moveString+="F";if(C3>0)for(var i=0;i<C3;i++)moveString+="G";if(C4>0)for(var i=0;i<C4;i++)moveString+="H";GM_setValue("university_maxscore",bestScore);GM_setValue("university_solution",moveString);GM_setValue("university_currentpuzzle",puzzleToString(uniPuzzle));GM_setValue("university_solving",false)}function setupLayout(){var a=document.getElementsByTagName('img');for(var b=0;b<a.length;b++){if(a[b].src.indexOf("/hobowars_logo_s.gif")!=-1){layout=0;break}else if(a[b].src.indexOf("l/logo.jpg")!=-1){layout=1;break}}switch(layout){case 0:var c=document.getElementsByTagName('div');for(var d=0;d<c.length;d++)if(c[d].className=="tabpage"){whiteBox=c[d];break}menuBox=document.getElementById("sideMenu");break;case 1:whiteBox=document.getElementById("whitebox");menuBox=document.getElementById("menu");break;default:return false}return true}function getArgs(){var a={};var b=document.location.href;var c=b.substring(b.indexOf("?")+1);var d=c.split("&");for(k in d){var e=d[k].split("=");a[e[0]]=e[1]}return a}function macroCheck(){var a=document.getElementsByTagName('img');for(var b=0;b<a.length;b++)if(a[b].src.indexOf("/captcha.php?")!=-1)return true;return false}