Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name KoC Auto Spender
- // @namespace x
- // @description Auto Spender RC 2.07
- // @include http://*kingsofchaos.com/*
- // @grant GM_getValue
- // @grant GM_setValue
- // @grant GM_addStyle
- // @grant GM_xmlhttpRequest
- // @grant GM_log
- // ==/UserScript==
- // ---------------------------------------------------
- // No need to edit below this.
- // ---------------------------------------------------
- // Initiate Variables
- var turing;
- var p;
- var cinter = GM_getValue("cinter") * 60 * 1000;
- var buywut = GM_getValue("buywut");
- var username = GM_getValue("username");
- var password = GM_getValue("password");
- var autologin = GM_getValue("autologin");
- var now = new Date();
- var hour = now.getHours();
- var mins = now.getMinutes();
- var time = Math.abs(hour+(mins/100));
- // Define Weapons
- if ( buywut>0) {
- if ( buywut == 72 ) { buyname = 'Chariot'; buycost = 450000; }
- if ( buywut == 70 ) { buyname = 'Blackpowder Missile'; buycost = 1000000; }
- if ( buywut == 51 ) { buyname = 'Dragonskin'; buycost = 200000; }
- if ( buywut == 71 ) { buyname = 'Invisiblity Shield'; buycost = 1000000; }
- if ( buywut == 75 ) { buyname = 'Nunchaku'; buycost = 1000000; }
- if ( buywut == 74 ) { buyname = 'Lookout Tower'; buycost = 1000000; }
- if ( buywut == 73 ) { buyname = 'Skeleton Key'; buycost = 600000; }
- if ( buywut == 3 ) { buyname = 'Knife'; buycost = 1000; }
- if ( buywut == 58 ) { buyname = 'Rope'; buycost = 40000; }
- if ( buywut == 63 ) { buyname = 'Dirk'; buycost = 75000; }
- if ( buywut == 65 ) { buyname = 'Cloak'; buycost = 140000; }
- if ( buywut == 67 ) { buyname = 'Grappling Hook'; buycost = 250000; }
- } else { buyname = 'Dragonskin'; buycost = 200000; }
- // Start your Engines
- if (hour >= 6) {
- if (cinter > 0) {
- if(document.URL.match("error"))
- {
- login();
- }
- if(document.URL.match("armory"))
- {
- armory();
- }
- } else { alert("Error ?? You need to set an interval - Go to Settings"); }
- } else {
- DisplayMessage(displayTime()+" It's "+time+" right now.<br/>"+displayTime()+" Time is between 00:00 and 06:00.<br/>"+displayTime()+" We're \"sleeping\" right now.<br/>"+displayTime()+" Trying again in a little bit.");
- setTimeout(navarmory, 1800000);
- }
- // Functions
- function armory()
- {
- var gold = FindText(document.body.innerHTML, 'Gold:<font color="#250202">', '<').replace(/,/g,'');
- gold = gold.replace(/\n/g, '');
- gold = gold.replace(/\t/g, '');
- gold = gold.replace(/,/g, '');
- gold = gold.replace('M', '000000');
- gold = parseInt(gold);
- var cgold = addCommas(gold);
- if (FindText(document.body.innerHTML, 'repair_all_weapons" ', '="Repair all weapons for') == "value") {
- var repCost = FindText(document.body.innerHTML, 'repair_all_weapons" value="Repair all weapons for ', ' Gold" type="submit">');
- repCost = repCost.replace(/,/g, '');
- var randint = Math.floor(Math.random()*60);
- var repairval = FindText(document.body.innerHTML, 'repair_all_weapons" value="', '" type="submit">');
- randint = Math.floor((randint+60)*1000);
- if (repCost > gold) {
- DisplayMessage(displayTime()+" Detected gold to be "+cgold+".<br/>"+displayTime()+" Repair cost is "+addCommas(repCost)+" gold.<br/>"+displayTime()+" Insufficient funds. Req +"+addCommas(Math.floor(repCost-gold))+".<br/>"+displayTime()+" Refreshing in 1 min, and a few seconds.");
- setTimeout(navarmory, randint);
- } else {
- p = "repair_all_weapons="+repairval;
- post("http://www.kingsofchaos.com/armory.php",p,function(html){
- DisplayMessage(displayTime()+" Detected gold to be "+cgold+".<br/>"+displayTime()+" Repair cost is "+addCommas(repCost)+" gold.<br/>"+displayTime()+" Attempting to repair all.<br/>"+displayTime()+" Refreshing in a second.");
- setTimeout(navarmory, 1);
- })
- }
- } else {
- gold = Math.floor(gold/buycost);
- get("http://www.kingsofchaos.com/armory.php", function(r){
- var random = Math.floor((Math.random()*cinter) + (Math.random()*cinter));
- if (gold>0) {
- turing = FindText(r,'name="turing" value="','"');
- p = "buy_weapon["+buywut+"]=" + gold + "&turing=" + turing + "&hash="
- post("http://www.kingsofchaos.com/armory.php",p,function(html){
- DisplayMessage(displayTime()+" Located /armory.php. (logged in)<br/>"+displayTime()+" Detected gold to be "+cgold+".<br/>"+displayTime()+" Bought "+gold+" "+buyname+".<br/>"+displayTime()+" Spending again in ~" + Math.floor(((random/1000)/60)-0) + "min.");
- setTimeout(navarmory, random);
- })
- } else { DisplayMessage(displayTime()+" Located /armory.php. (logged in)<br/>"+displayTime()+" Detected gold to be "+cgold+".<br/>"+displayTime()+" Insufficient gold for "+buyname+".<br/>"+displayTime()+" Spending again in ~" + Math.floor(((random/1000)/60)-0) + "min."); setTimeout(navarmory, random); }
- })
- }
- }
- function navarmory()
- {
- window.location.href = "/armory.php";
- }
- function login()
- {
- if (autologin == "yes" && username && password) {
- var logintime = Math.floor((Math.random()*10)*1000);
- p = "usrname="+username+"&peeword="+password;
- post("http://www.kingsofchaos.com/login.php",p,function(html){
- DisplayMessage(displayTime()+" Located /error.php. (logged out)<br/>"+displayTime()+" Login details sent to server.<br/>"+displayTime()+" Refreshing in "+Math.floor(logintime/1000)+" sec.<br/>"+displayTime()+" Hold still...");
- setTimeout(navarmory, logintime);
- })
- }
- }
- DisplayEdit("<div id='getOptions'>Settings</div>");
- document.getElementById("getOptions").addEventListener('click', getOpt, true);
- function getOpt()
- {
- h4xed = 1;
- var newhtml = '<br/><input type="button" onClick="window.location.reload()" value="Back to Kings of Chaos">';
- newhtml += '<center>';
- newhtml += '<table class="table_lines" border="0" cellspacing="0" cellpadding="6" width="600">';
- newhtml += '<tr><th colspan="2">Current Settings</th></tr>';
- newhtml += '<tr><td><b>Interval Settings</b></td><td>Around every <i>'+ Math.floor(((cinter/1000)/60)*1) +' to '+ Math.floor(((cinter/1000)/60)*2) +'mins</b>.</i></td></tr>';
- newhtml += '<tr><td><b>Spending Preferences</b></td><td><a href="#">' + buyname + '(' + buywut + ')</a>. Cost is ' + addCommas(buycost) + ' gold each.</i></td></tr>';
- newhtml += '<tr><td><b>Username</b></td>';
- if (username) {
- newhtml += '<td><input type="text" size="16" value="' + username + '" id="username_set"> <input type="button" value="Set" id="set_username"></td></tr>';
- } else {
- newhtml += '<td><input type="text" size="16" value="?" id="username_set"> <input type="button" value="Set" id="set_username"></td></tr>';
- }
- newhtml += '<tr><td><b>Password</b></td>';
- if (password) {
- newhtml += '<td><input type="password" size="16" value="' + password + '" id="password_set"> <input type="button" value="Set" id="set_password"></td></tr>';
- } else {
- newhtml += '<td><input type="text" size="16" value="?" id="password_set"> <input type="button" value="Set" id="set_password"></td></tr>';
- }
- newhtml += '<tr><td><b>Auto-Login (on logout)</b></td><td>';
- if (autologin == "yes") {
- newhtml += 'Enabled <input type="button" value="Toggle OFF" id="autologin_toggle">';
- } else {
- newhtml += 'Disabled <input type="button" value="Toggle ON" id="autologin_toggle">';
- }
- newhtml += '</td></tr>';
- newhtml += '</table>';
- newhtml += '<br/>';
- newhtml += '<table width="100%"><tr><td align="right" valign="top">';
- newhtml += '<table class="table_lines" border="0" cellspacing="0" cellpadding="6" width="600">';
- newhtml += '<tr><th colspan="2">Interval Settings</th></tr>';
- newhtml += '<tr><td><input type="button" value="Short" id="set_int_10"></td><td>Averages around every 10 to 20 minutes.</td></tr>';
- newhtml += '<tr><td><input type="button" value="Medium" id="set_int_35"></td><td>Average around every 35 to 70 minutes.</td></tr>';
- newhtml += '<tr><td><input type="button" value="Long" id="set_int_75"></td><td>Averages around every 75 to 150 minutes.</td></tr>';
- newhtml += '<tr><td><b>Custom Integer (mins)</b></td><td><input type="text" style="text-align: center;" value="5" id="customint" size="3"> <input type="button" value="Set" id="set_custom"></td></tr>';
- newhtml += '</table>';
- newhtml += '</td><td align="left" valign="top">';
- newhtml += '<table class="table_lines" border="0" cellspacing="0" cellpadding="6" width="600">';
- newhtml += '<tr><th colspan="2">Spending Preferences</th></tr>';
- newhtml += '<tr>';
- newhtml += '<td><b>Strike Weapons List</b></td>';
- newhtml += '<td>';
- newhtml += '<select id="wepid_str">';
- newhtml += '<option value="3">Knives</option>';
- newhtml += '<option value="72">Chariot</option>';
- newhtml += '<option value="70">Blackpowder Missile</option>';
- newhtml += '</select> ';
- newhtml += '<input type="button" value="Set" id="buybut_str">';
- newhtml += '</td>';
- newhtml += '</tr>';
- newhtml += '<tr>';
- newhtml += '<td><b>Defense Weapons List</b></td>';
- newhtml += '<td>';
- newhtml += '<select id="wepid_def">';
- newhtml += '<option value="51">Dragonskin</option>';
- newhtml += '<option value="71">Invisibility Shield</option>';
- newhtml += '</select> ';
- newhtml += '<input type="button" value="Set" id="buybut_def">';
- newhtml += '</td>';
- newhtml += '</tr>';
- newhtml += '<tr>';
- newhtml += '<td><b>Spy Tools List</b></td>';
- newhtml += '<td>';
- newhtml += '<select id="wepid_spy">';
- newhtml += '<option value="58">Rope</option>';
- newhtml += '<option value="63">Dirk</option>';
- newhtml += '<option value="65">Cloak</option>';
- newhtml += '<option value="67">Grappling Hook</option>';
- newhtml += '<option value="73">Skeleton Key</option>';
- newhtml += '<option value="75">Nunchaku</option>';
- newhtml += '</select> ';
- newhtml += '<input type="button" value="Set" id="buybut_spy">';
- newhtml += '</td>';
- newhtml += '</tr>';
- newhtml += '<tr>';
- newhtml += '<td><b>Sentry Tools List</b></td>';
- newhtml += '<td>';
- newhtml += '<select id="wepid_sentry">';
- newhtml += '<option value="74">Lookout Tower</option>';
- newhtml += '</select> ';
- newhtml += '<input type="button" value="Set" id="buybut_sentry">';
- newhtml += '</td>';
- newhtml += '</tr>';
- newhtml += '</table>';
- newhtml += '</td></tr></table></center>';
- document.body.innerHTML = newhtml;
- document.addEventListener('click', function(event) {
- if(event.target.id == "set_custom") { // custom interval
- var custint = document.getElementById('customint');
- if(isInteger(custint.value) && custint.value > 0) {
- GM_setValue("cinter",custint.value);
- window.location.href = "/base.php";
- alert('Interval setting changed successfully.');
- } else {
- alert('Invalid integer: ' + custint.value);
- }
- }
- if(event.target.id == "set_username") {
- var user = document.getElementById('username_set');
- GM_setValue("username",user.value);
- window.location.href = "/base.php";
- alert('Username changed successfully.');
- }
- if(event.target.id == "set_password") {
- var pass = document.getElementById('password_set');
- GM_setValue("password",pass.value);
- window.location.href = "/base.php";
- alert('Password changed successfully.');
- }
- if(event.target.id == "autologin_toggle") {
- var tog_opt = document.getElementById('autologin_toggle');
- tog_opt = tog_opt.value.split(" ");
- if (tog_opt[1] == "ON") {
- tog_opt = "yes";
- } else if (tog_opt[1] == "OFF") {
- tog_opt = 0;
- }
- GM_setValue("autologin",tog_opt);
- window.location.href = "/base.php";
- alert('Autologin setting changed successfully.');
- }
- if(FindText(event.target.id, 'buy', '_') == "but") { // weapon setting
- var buytype = event.target.id.split("_");
- var weptype = document.getElementById('wepid_' + buytype[1]);
- GM_setValue("buywut",weptype.value);
- window.location.href = "/base.php";
- alert('Spending setting changed successfully.');
- }
- if(FindText(event.target.id, 'set', 'int_') == "_") { // interval presets
- var intwat = event.target.id.split("_");
- GM_setValue("cinter",intwat[2]);
- window.location.href = "/base.php";
- alert('Interval setting changed successfully.');
- }
- }, true);
- if(h4xed == 1){
- GM_openInTab(event.target);
- }
- }
- function post(url,data,cb){
- GM_xmlhttpRequest({
- method: "POST",
- url: url,
- headers:{'Content-type':'application/x-www-form-urlencoded'},
- data:encodeURI(data),
- onload: function(xhr) { cb(xhr.responseText); }
- });
- }
- function get(url, cb) {
- GM_xmlhttpRequest({
- method: "GET",
- url: url,
- onload: function(xhr) {
- cb(xhr.responseText);
- }
- });
- }
- function FindText(str, str1, str2)
- {
- var pos1 = str.indexOf(str1);
- if (pos1 == -1) return '';
- pos1 += str1.length;
- var pos2 = str.indexOf(str2, pos1);
- if (pos2 == -1) return '';
- return str.substring(pos1, pos2);
- }
- function DisplayMessage(message)
- {
- var gm_button=document.createElement('div');
- gm_button.setAttribute('name','gm-button');
- gm_button.setAttribute('id','gm-button');
- gm_button.setAttribute('style','position:fixed;bottom:10px;right:10px;width:300px;height:65px;background-color:#000000;border:2px solid #000000;padding:5px;text-align:left;');
- var gm_paragraph=document.createElement('p');
- gm_paragraph.setAttribute('id','GM_Message');
- gm_paragraph.setAttribute('style','font:normal normal normal 12px Arial,Helvetica,sans-serif;color:#FFFFFF;text-decoration:none;margin:0;padding:0;');
- gm_paragraph.innerHTML = message;
- var gm_span_1=document.createElement('span');
- gm_span_1.setAttribute('id','gm-span-1');
- gm_span_1.setAttribute('style','cursor:pointer;');
- document.getElementsByTagName('body')[0].appendChild(gm_button);
- gm_button.appendChild(gm_paragraph);
- gm_paragraph.appendChild(gm_span_1);
- }
- function DisplayEdit(message)
- {
- var gm_button=document.createElement('div');
- gm_button.setAttribute('name','gm-button');
- gm_button.setAttribute('id','gm-button');
- gm_button.setAttribute('style','position:fixed;top:10px;left:10px;background-color:#000000;border:2px solid #000000;padding:5px;text-align:left;');
- var gm_paragraph=document.createElement('p');
- gm_paragraph.setAttribute('id','GM_Message');
- gm_paragraph.setAttribute('style','font:normal normal normal 12px Arial,Helvetica,sans-serif;color:#FFFFFF;text-decoration:none;margin:0;padding:0;');
- gm_paragraph.innerHTML = message;
- var gm_span_1=document.createElement('span');
- gm_span_1.setAttribute('id','gm-span-1');
- gm_span_1.setAttribute('style','cursor:pointer;');
- document.getElementsByTagName('body')[0].appendChild(gm_button);
- gm_button.appendChild(gm_paragraph);
- gm_paragraph.appendChild(gm_span_1);
- }
- function DisplayOptions(message)
- {
- var gm_button=document.createElement('div');
- gm_button.setAttribute('name','gm-button');
- gm_button.setAttribute('id','gm-button');
- gm_button.setAttribute('style','position:fixed;top:10px;left:10px;width:300px;height:200px;background-color:#000000;border:2px solid #000000;padding:5px;text-align:left;');
- var gm_paragraph=document.createElement('p');
- gm_paragraph.setAttribute('id','GM_Message');
- gm_paragraph.setAttribute('style','font:normal normal normal 12px Arial,Helvetica,sans-serif;color:#FFFFFF;text-decoration:none;margin:0;padding:0;');
- gm_paragraph.innerHTML = message;
- var gm_span_1=document.createElement('span');
- gm_span_1.setAttribute('id','gm-span-1');
- gm_span_1.setAttribute('style','cursor:pointer;');
- document.getElementsByTagName('body')[0].appendChild(gm_button);
- gm_button.appendChild(gm_paragraph);
- gm_paragraph.appendChild(gm_span_1);
- }
- function displayTime() {
- var currentTime = new Date();
- // Formats the time
- var timeString = twoDigitNumber(currentTime.getHours())
- + ":" + twoDigitNumber(currentTime.getMinutes())
- + ":" + twoDigitNumber(currentTime.getSeconds());
- //parent.innerHTML = timeString;
- return timeString;
- }
- function twoDigitNumber(number) {
- if (number >= 0 && number < 10) {
- return "0" + number;
- }
- return number;
- }
- function addCommas(sValue) // for duration function
- {
- sValue = String(sValue);
- var sRegExp = new RegExp('(-?[0-9]+)([0-9]{3})');
- while(sRegExp.test(sValue)) {
- sValue = sValue.replace(sRegExp, '$1,$2');
- }
- return sValue;
- }
- function isInteger(s) {
- return (s.toString().search(/^-?[0-9]+$/) == 0);
- }
- if(document.title.match("Problem"))
- {
- DisplayMessage(displayTime()+" 404 Error, possibly disconnect?<br/>"+displayTime()+" Attempting to reconnect in a seconds.<br/>"+displayTime()+" Just hold still...<br/>"+displayTime()+" Srsly be patient, it will go!");
- window.location.reload();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement