Advertisement
Guest User

Untitled

a guest
Nov 16th, 2017
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.35 KB | None | 0 0
  1. // ==UserScript==
  2. // @name KoC Auto Spender
  3. // @namespace x
  4. // @description Auto Spender RC 2.07
  5. // @include http://*kingsofchaos.com/*
  6. // @grant GM_getValue
  7. // @grant GM_setValue
  8. // @grant GM_addStyle
  9. // @grant GM_xmlhttpRequest
  10. // @grant GM_log
  11. // ==/UserScript==
  12.  
  13. // ---------------------------------------------------
  14. // No need to edit below this.
  15. // ---------------------------------------------------
  16.  
  17. // Initiate Variables
  18. var turing;
  19. var p;
  20. var cinter = GM_getValue("cinter") * 60 * 1000;
  21. var buywut = GM_getValue("buywut");
  22. var username = GM_getValue("username");
  23. var password = GM_getValue("password");
  24. var autologin = GM_getValue("autologin");
  25. var now = new Date();
  26. var hour = now.getHours();
  27. var mins = now.getMinutes();
  28. var time = Math.abs(hour+(mins/100));
  29.  
  30. // Define Weapons
  31. if ( buywut>0) {
  32. if ( buywut == 72 ) { buyname = 'Chariot'; buycost = 450000; }
  33. if ( buywut == 70 ) { buyname = 'Blackpowder Missile'; buycost = 1000000; }
  34. if ( buywut == 51 ) { buyname = 'Dragonskin'; buycost = 200000; }
  35. if ( buywut == 71 ) { buyname = 'Invisiblity Shield'; buycost = 1000000; }
  36. if ( buywut == 75 ) { buyname = 'Nunchaku'; buycost = 1000000; }
  37. if ( buywut == 74 ) { buyname = 'Lookout Tower'; buycost = 1000000; }
  38. if ( buywut == 73 ) { buyname = 'Skeleton Key'; buycost = 600000; }
  39. if ( buywut == 3 ) { buyname = 'Knife'; buycost = 1000; }
  40. if ( buywut == 58 ) { buyname = 'Rope'; buycost = 40000; }
  41. if ( buywut == 63 ) { buyname = 'Dirk'; buycost = 75000; }
  42. if ( buywut == 65 ) { buyname = 'Cloak'; buycost = 140000; }
  43. if ( buywut == 67 ) { buyname = 'Grappling Hook'; buycost = 250000; }
  44. } else { buyname = 'Dragonskin'; buycost = 200000; }
  45.  
  46. // Start your Engines
  47. if (hour >= 6) {
  48. if (cinter > 0) {
  49. if(document.URL.match("error"))
  50. {
  51. login();
  52. }
  53. if(document.URL.match("armory"))
  54. {
  55. armory();
  56. }
  57. } else { alert("Error ?? You need to set an interval - Go to Settings"); }
  58. } else {
  59. 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.");
  60. setTimeout(navarmory, 1800000);
  61. }
  62.  
  63. // Functions
  64. function armory()
  65. {
  66. var gold = FindText(document.body.innerHTML, 'Gold:<font color="#250202">', '<').replace(/,/g,'');
  67. gold = gold.replace(/\n/g, '');
  68. gold = gold.replace(/\t/g, '');
  69. gold = gold.replace(/,/g, '');
  70. gold = gold.replace('M', '000000');
  71. gold = parseInt(gold);
  72. var cgold = addCommas(gold);
  73.  
  74. if (FindText(document.body.innerHTML, 'repair_all_weapons" ', '="Repair all weapons for') == "value") {
  75. var repCost = FindText(document.body.innerHTML, 'repair_all_weapons" value="Repair all weapons for ', ' Gold" type="submit">');
  76. repCost = repCost.replace(/,/g, '');
  77. var randint = Math.floor(Math.random()*60);
  78. var repairval = FindText(document.body.innerHTML, 'repair_all_weapons" value="', '" type="submit">');
  79. randint = Math.floor((randint+60)*1000);
  80. if (repCost > gold) {
  81. 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.");
  82. setTimeout(navarmory, randint);
  83. } else {
  84. p = "repair_all_weapons="+repairval;
  85. post("http://www.kingsofchaos.com/armory.php",p,function(html){
  86. 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.");
  87. setTimeout(navarmory, 1);
  88. })
  89. }
  90. } else {
  91. gold = Math.floor(gold/buycost);
  92. get("http://www.kingsofchaos.com/armory.php", function(r){
  93. var random = Math.floor((Math.random()*cinter) + (Math.random()*cinter));
  94. if (gold>0) {
  95. turing = FindText(r,'name="turing" value="','"');
  96. p = "buy_weapon["+buywut+"]=" + gold + "&turing=" + turing + "&hash="
  97. post("http://www.kingsofchaos.com/armory.php",p,function(html){
  98. 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.");
  99. setTimeout(navarmory, random);
  100.  
  101. })
  102. } 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); }
  103.  
  104. })
  105.  
  106. }
  107.  
  108. }
  109.  
  110. function navarmory()
  111. {
  112. window.location.href = "/armory.php";
  113. }
  114.  
  115. function login()
  116. {
  117. if (autologin == "yes" && username && password) {
  118. var logintime = Math.floor((Math.random()*10)*1000);
  119. p = "usrname="+username+"&peeword="+password;
  120. post("http://www.kingsofchaos.com/login.php",p,function(html){
  121. 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...");
  122. setTimeout(navarmory, logintime);
  123. })
  124. }
  125. }
  126.  
  127. DisplayEdit("<div id='getOptions'>Settings</div>");
  128. document.getElementById("getOptions").addEventListener('click', getOpt, true);
  129.  
  130. function getOpt()
  131. {
  132. h4xed = 1;
  133. var newhtml = '<br/><input type="button" onClick="window.location.reload()" value="Back to Kings of Chaos">';
  134. newhtml += '<center>';
  135.  
  136. newhtml += '<table class="table_lines" border="0" cellspacing="0" cellpadding="6" width="600">';
  137. newhtml += '<tr><th colspan="2">Current Settings</th></tr>';
  138. 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>';
  139. newhtml += '<tr><td><b>Spending Preferences</b></td><td><a href="#">' + buyname + '(' + buywut + ')</a>. Cost is ' + addCommas(buycost) + ' gold each.</i></td></tr>';
  140. newhtml += '<tr><td><b>Username</b></td>';
  141. if (username) {
  142. newhtml += '<td><input type="text" size="16" value="' + username + '" id="username_set"> <input type="button" value="Set" id="set_username"></td></tr>';
  143. } else {
  144. newhtml += '<td><input type="text" size="16" value="?" id="username_set"> <input type="button" value="Set" id="set_username"></td></tr>';
  145. }
  146. newhtml += '<tr><td><b>Password</b></td>';
  147. if (password) {
  148. newhtml += '<td><input type="password" size="16" value="' + password + '" id="password_set"> <input type="button" value="Set" id="set_password"></td></tr>';
  149. } else {
  150. newhtml += '<td><input type="text" size="16" value="?" id="password_set"> <input type="button" value="Set" id="set_password"></td></tr>';
  151. }
  152. newhtml += '<tr><td><b>Auto-Login (on logout)</b></td><td>';
  153. if (autologin == "yes") {
  154. newhtml += 'Enabled <input type="button" value="Toggle OFF" id="autologin_toggle">';
  155. } else {
  156. newhtml += 'Disabled <input type="button" value="Toggle ON" id="autologin_toggle">';
  157. }
  158. newhtml += '</td></tr>';
  159. newhtml += '</table>';
  160.  
  161. newhtml += '<br/>';
  162. newhtml += '<table width="100%"><tr><td align="right" valign="top">';
  163.  
  164. newhtml += '<table class="table_lines" border="0" cellspacing="0" cellpadding="6" width="600">';
  165. newhtml += '<tr><th colspan="2">Interval Settings</th></tr>';
  166. newhtml += '<tr><td><input type="button" value="Short" id="set_int_10"></td><td>Averages around every 10 to 20 minutes.</td></tr>';
  167. newhtml += '<tr><td><input type="button" value="Medium" id="set_int_35"></td><td>Average around every 35 to 70 minutes.</td></tr>';
  168. newhtml += '<tr><td><input type="button" value="Long" id="set_int_75"></td><td>Averages around every 75 to 150 minutes.</td></tr>';
  169. 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>';
  170. newhtml += '</table>';
  171.  
  172. newhtml += '</td><td align="left" valign="top">';
  173.  
  174. newhtml += '<table class="table_lines" border="0" cellspacing="0" cellpadding="6" width="600">';
  175. newhtml += '<tr><th colspan="2">Spending Preferences</th></tr>';
  176.  
  177. newhtml += '<tr>';
  178. newhtml += '<td><b>Strike Weapons List</b></td>';
  179. newhtml += '<td>';
  180. newhtml += '<select id="wepid_str">';
  181. newhtml += '<option value="3">Knives</option>';
  182. newhtml += '<option value="72">Chariot</option>';
  183. newhtml += '<option value="70">Blackpowder Missile</option>';
  184. newhtml += '</select> ';
  185. newhtml += '<input type="button" value="Set" id="buybut_str">';
  186. newhtml += '</td>';
  187. newhtml += '</tr>';
  188.  
  189. newhtml += '<tr>';
  190. newhtml += '<td><b>Defense Weapons List</b></td>';
  191. newhtml += '<td>';
  192. newhtml += '<select id="wepid_def">';
  193. newhtml += '<option value="51">Dragonskin</option>';
  194. newhtml += '<option value="71">Invisibility Shield</option>';
  195. newhtml += '</select> ';
  196. newhtml += '<input type="button" value="Set" id="buybut_def">';
  197. newhtml += '</td>';
  198. newhtml += '</tr>';
  199.  
  200. newhtml += '<tr>';
  201. newhtml += '<td><b>Spy Tools List</b></td>';
  202. newhtml += '<td>';
  203. newhtml += '<select id="wepid_spy">';
  204. newhtml += '<option value="58">Rope</option>';
  205. newhtml += '<option value="63">Dirk</option>';
  206. newhtml += '<option value="65">Cloak</option>';
  207. newhtml += '<option value="67">Grappling Hook</option>';
  208. newhtml += '<option value="73">Skeleton Key</option>';
  209. newhtml += '<option value="75">Nunchaku</option>';
  210. newhtml += '</select> ';
  211. newhtml += '<input type="button" value="Set" id="buybut_spy">';
  212. newhtml += '</td>';
  213. newhtml += '</tr>';
  214.  
  215. newhtml += '<tr>';
  216. newhtml += '<td><b>Sentry Tools List</b></td>';
  217. newhtml += '<td>';
  218. newhtml += '<select id="wepid_sentry">';
  219. newhtml += '<option value="74">Lookout Tower</option>';
  220. newhtml += '</select> ';
  221. newhtml += '<input type="button" value="Set" id="buybut_sentry">';
  222. newhtml += '</td>';
  223. newhtml += '</tr>';
  224.  
  225. newhtml += '</table>';
  226.  
  227. newhtml += '</td></tr></table></center>';
  228. document.body.innerHTML = newhtml;
  229. document.addEventListener('click', function(event) {
  230. if(event.target.id == "set_custom") { // custom interval
  231. var custint = document.getElementById('customint');
  232. if(isInteger(custint.value) && custint.value > 0) {
  233. GM_setValue("cinter",custint.value);
  234. window.location.href = "/base.php";
  235. alert('Interval setting changed successfully.');
  236. } else {
  237. alert('Invalid integer: ' + custint.value);
  238. }
  239. }
  240. if(event.target.id == "set_username") {
  241. var user = document.getElementById('username_set');
  242. GM_setValue("username",user.value);
  243. window.location.href = "/base.php";
  244. alert('Username changed successfully.');
  245. }
  246. if(event.target.id == "set_password") {
  247. var pass = document.getElementById('password_set');
  248. GM_setValue("password",pass.value);
  249. window.location.href = "/base.php";
  250. alert('Password changed successfully.');
  251. }
  252. if(event.target.id == "autologin_toggle") {
  253. var tog_opt = document.getElementById('autologin_toggle');
  254. tog_opt = tog_opt.value.split(" ");
  255. if (tog_opt[1] == "ON") {
  256. tog_opt = "yes";
  257. } else if (tog_opt[1] == "OFF") {
  258. tog_opt = 0;
  259. }
  260. GM_setValue("autologin",tog_opt);
  261. window.location.href = "/base.php";
  262. alert('Autologin setting changed successfully.');
  263. }
  264. if(FindText(event.target.id, 'buy', '_') == "but") { // weapon setting
  265. var buytype = event.target.id.split("_");
  266. var weptype = document.getElementById('wepid_' + buytype[1]);
  267. GM_setValue("buywut",weptype.value);
  268. window.location.href = "/base.php";
  269. alert('Spending setting changed successfully.');
  270. }
  271. if(FindText(event.target.id, 'set', 'int_') == "_") { // interval presets
  272. var intwat = event.target.id.split("_");
  273. GM_setValue("cinter",intwat[2]);
  274. window.location.href = "/base.php";
  275. alert('Interval setting changed successfully.');
  276. }
  277. }, true);
  278.  
  279. if(h4xed == 1){
  280. GM_openInTab(event.target);
  281. }
  282. }
  283.  
  284. function post(url,data,cb){
  285. GM_xmlhttpRequest({
  286. method: "POST",
  287. url: url,
  288. headers:{'Content-type':'application/x-www-form-urlencoded'},
  289. data:encodeURI(data),
  290. onload: function(xhr) { cb(xhr.responseText); }
  291. });
  292. }
  293.  
  294.  
  295. function get(url, cb) {
  296. GM_xmlhttpRequest({
  297. method: "GET",
  298. url: url,
  299. onload: function(xhr) {
  300. cb(xhr.responseText);
  301. }
  302. });
  303. }
  304.  
  305.  
  306. function FindText(str, str1, str2)
  307. {
  308. var pos1 = str.indexOf(str1);
  309. if (pos1 == -1) return '';
  310.  
  311. pos1 += str1.length;
  312.  
  313. var pos2 = str.indexOf(str2, pos1);
  314. if (pos2 == -1) return '';
  315.  
  316. return str.substring(pos1, pos2);
  317. }
  318.  
  319. function DisplayMessage(message)
  320. {
  321. var gm_button=document.createElement('div');
  322. gm_button.setAttribute('name','gm-button');
  323. gm_button.setAttribute('id','gm-button');
  324. 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;');
  325. var gm_paragraph=document.createElement('p');
  326. gm_paragraph.setAttribute('id','GM_Message');
  327. gm_paragraph.setAttribute('style','font:normal normal normal 12px Arial,Helvetica,sans-serif;color:#FFFFFF;text-decoration:none;margin:0;padding:0;');
  328. gm_paragraph.innerHTML = message;
  329.  
  330. var gm_span_1=document.createElement('span');
  331. gm_span_1.setAttribute('id','gm-span-1');
  332. gm_span_1.setAttribute('style','cursor:pointer;');
  333.  
  334. document.getElementsByTagName('body')[0].appendChild(gm_button);
  335. gm_button.appendChild(gm_paragraph);
  336. gm_paragraph.appendChild(gm_span_1);
  337. }
  338.  
  339. function DisplayEdit(message)
  340. {
  341. var gm_button=document.createElement('div');
  342. gm_button.setAttribute('name','gm-button');
  343. gm_button.setAttribute('id','gm-button');
  344. gm_button.setAttribute('style','position:fixed;top:10px;left:10px;background-color:#000000;border:2px solid #000000;padding:5px;text-align:left;');
  345. var gm_paragraph=document.createElement('p');
  346. gm_paragraph.setAttribute('id','GM_Message');
  347. gm_paragraph.setAttribute('style','font:normal normal normal 12px Arial,Helvetica,sans-serif;color:#FFFFFF;text-decoration:none;margin:0;padding:0;');
  348. gm_paragraph.innerHTML = message;
  349.  
  350. var gm_span_1=document.createElement('span');
  351. gm_span_1.setAttribute('id','gm-span-1');
  352. gm_span_1.setAttribute('style','cursor:pointer;');
  353.  
  354. document.getElementsByTagName('body')[0].appendChild(gm_button);
  355. gm_button.appendChild(gm_paragraph);
  356. gm_paragraph.appendChild(gm_span_1);
  357. }
  358. function DisplayOptions(message)
  359. {
  360. var gm_button=document.createElement('div');
  361. gm_button.setAttribute('name','gm-button');
  362. gm_button.setAttribute('id','gm-button');
  363. 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;');
  364. var gm_paragraph=document.createElement('p');
  365. gm_paragraph.setAttribute('id','GM_Message');
  366. gm_paragraph.setAttribute('style','font:normal normal normal 12px Arial,Helvetica,sans-serif;color:#FFFFFF;text-decoration:none;margin:0;padding:0;');
  367. gm_paragraph.innerHTML = message;
  368.  
  369. var gm_span_1=document.createElement('span');
  370. gm_span_1.setAttribute('id','gm-span-1');
  371. gm_span_1.setAttribute('style','cursor:pointer;');
  372.  
  373. document.getElementsByTagName('body')[0].appendChild(gm_button);
  374. gm_button.appendChild(gm_paragraph);
  375. gm_paragraph.appendChild(gm_span_1);
  376. }
  377. function displayTime() {
  378. var currentTime = new Date();
  379.  
  380. // Formats the time
  381. var timeString = twoDigitNumber(currentTime.getHours())
  382. + ":" + twoDigitNumber(currentTime.getMinutes())
  383. + ":" + twoDigitNumber(currentTime.getSeconds());
  384.  
  385. //parent.innerHTML = timeString;
  386. return timeString;
  387. }
  388. function twoDigitNumber(number) {
  389. if (number >= 0 && number < 10) {
  390. return "0" + number;
  391. }
  392.  
  393. return number;
  394. }
  395. function addCommas(sValue) // for duration function
  396. {
  397. sValue = String(sValue);
  398. var sRegExp = new RegExp('(-?[0-9]+)([0-9]{3})');
  399. while(sRegExp.test(sValue)) {
  400. sValue = sValue.replace(sRegExp, '$1,$2');
  401. }
  402. return sValue;
  403. }
  404.  
  405. function isInteger(s) {
  406. return (s.toString().search(/^-?[0-9]+$/) == 0);
  407. }
  408.  
  409. if(document.title.match("Problem"))
  410. {
  411. 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!");
  412. window.location.reload();
  413. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement