Advertisement
Guest User

deadfish slaymod

a guest
Jan 30th, 2016
394
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 150.78 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Dead Fish slaymod
  3. // @namespace koc.dead.fish
  4. // @include http://www.kingsofchaos.com/*
  5. // @exclude http://*.kingsofchaos.com/confirm.login.php*
  6. // @exclude http://*.kingsofchaos.com/security.php*
  7. // @exclude http://www.kingsofchaos.com/error.php
  8. // @grant GM_xmlhttpRequest
  9. // @grant GM_setValue
  10. // @grant GM_getValue
  11. // @grant GM_deleteValue
  12. // @grant GM_openInTab
  13. // @grant GM_addStyle
  14.  
  15. // ==/UserScript==
  16.  
  17. // Google Chrome Support
  18. var isChrome = /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor);
  19. if (isChrome) {
  20. this.GM_getValue=function (key,def) {
  21. return localStorage[key] || def;
  22. };
  23. this.GM_setValue=function (key,value) {
  24. return localStorage[key]=value;
  25. };
  26. this.GM_deleteValue=function (key) {
  27. return delete localStorage[key];
  28. };
  29. }
  30.  
  31. if(DetectRunningInstance() == true)
  32. {
  33. alert("You are running multiple instances of the DF script!\nManually remove the duplicates from Greasemonkey menu.");
  34. }
  35.  
  36.  
  37. var tbgerr = 1;
  38. var hitorange = 300;
  39. var hitred = 400;
  40.  
  41. var DF_version = 30;
  42. var DF_server = "http://146.185.180.19/aaa/script/";
  43.  
  44. var DF_username = GM_getValue("DF_username", "");
  45. var DF_password = GM_getValue("DF_password", "");
  46. var DF_statid = GM_getValue("DF_statid", "");
  47.  
  48. var soldiers; // used on some pages like train.php, mercs.php
  49. var mercs; // available mercs
  50. var bfPlayers = []; // list of stats for players on the current bf
  51.  
  52. var gold = GetGold();
  53. var url = document.location.toString();
  54.  
  55.  
  56. var weaponList = ["Blackpowder Missile", "Invisibility Shield", "Chariot", "Dragonskin", "Nunchaku", "Lookout Tower", "Skeleton Key", "Guard Dog", "Grappling Hook"];
  57.  
  58.  
  59. if(document.body.innerHTML.indexOf("logout.php") < 0
  60. || document.body.innerHTML.indexOf("is a registered trademark of Kings of Chaos") < 0)
  61. {
  62. //logged out or incomplete page
  63. }
  64.  
  65. checkVersion();
  66.  
  67. AddMenuItems();
  68.  
  69. AddBfSearch();
  70.  
  71. CheckExpForNextTech();
  72.  
  73. if(url.indexOf("/base.php") > 0)
  74. {
  75. BasePHP();
  76. }
  77. else if(url.indexOf("/armory.php") > 0)
  78. {
  79. ArmoryPHP();
  80. }
  81. else if(url.indexOf("/train.php") > 0)
  82. {
  83. TrainPHP();
  84. }
  85. else if(url.indexOf("/mercs.php") > 0)
  86. {
  87. MercsPHP();
  88. }
  89. else if(url.indexOf("/stats.php") > 0)
  90. {
  91. if (url.match("targetlist")){
  92. //alert2('On Target');
  93.  
  94. setTimeout(function() {
  95. targetsfield();
  96. }, 1000);
  97. }
  98.  
  99. StatsPHP();
  100. }
  101. else if(url.indexOf("/attack.php") > 0)
  102. {
  103. AttackPHP();
  104. }
  105. else if(url.indexOf("/inteldetail.php") > 0)
  106. {
  107. InteldetailPHP();
  108. }
  109. else if(url.indexOf("/detail.php") > 0)
  110. {
  111. DetailPHP();
  112. }
  113. else if(url.indexOf("/battlefield.php") > 0)
  114. {
  115. BattlefieldPHP();
  116. }
  117. else if(url.indexOf("/conquest.php") > 0)
  118. {
  119. ConquestPHP();
  120. }
  121. else if(url.indexOf("/writemail.php") > 0)
  122. {
  123. WritemailPHP();
  124. }
  125. else if(url.indexOf("/attacklog.php") > 0)
  126. {
  127. AttackLogPHP();
  128. }
  129. else if(url.indexOf("/inbox.php") > 0)
  130. {
  131. InboxPHP();
  132. }
  133. else if(url.indexOf("/recruit.php") > 0)
  134. {
  135. RecruitPHP();
  136. }
  137.  
  138. //scroll into the content (on detail php, it scrolls itself)
  139. if(GM_getValue("DF_OptionScrollIntoContent", 1) != 0 && url.indexOf("/detail.php") < 0)
  140. {
  141. document.getElementsByTagName('table')[2].scrollIntoView();
  142. }
  143.  
  144. // If any traces left, disable.
  145. // Disable hotkeys as per mods request
  146. GM_setValue("DF_OptionKS", 0);
  147.  
  148. // Disable armory/train/mercs buy helper
  149. GM_setValue("DF_OptionBH", 1);
  150.  
  151. // Disable autoredirect
  152. GM_setValue("DF_OptionARD", 0);
  153.  
  154.  
  155. /*****************************************************************************/
  156. /********************************* PAGES *************************************/
  157. /*****************************************************************************/
  158. function BasePHP()
  159. {
  160. var statid = GetText("b>Name</b", "id=", "\"");
  161. var username = GetText("b>Name</b", "\">", "<");
  162. var uniqid = GetText("uniqid=", "\"");
  163.  
  164. GM_setValue("DF_username", username);
  165. GM_setValue("DF_statid", statid);
  166. GM_setValue("DF_uniqid", uniqid);
  167.  
  168. // Display the custom div on top
  169. GM_xmlhttpRequest(
  170. {
  171. method: "GET",
  172. url: DF_server + "checkstatus.php?whoami=" + username + "&password=" + DF_password + "&userid=" + statid + "&recruitid=" + uniqid,
  173. onload: function(r)
  174. {
  175. if(r.status == 200)
  176. {
  177. //alert(r.responseText); // For Debugging
  178. if(r.responseText == "Unregistered")
  179. {
  180. var customDiv = document.createElement("div");
  181. customDiv.innerHTML = "<br><center><table class=table_lines width=100%><tr><th style=\"border-color: darkred; background-color:red; height: 4ex;\">You haven't registered a Dead Fish account!</th></tr>"
  182. + "<tr><td><a href=# id=registerDF onClick=\"return false;\">Click here</a> to register your DF account. Please choose an unique password"
  183. + "<br><br>If this is not working, contact <a href=http://www.kingsofchaos.com/stats.php?id=4401644>wAaArgasm</a>, <a href=http://www.kingsofchaos.com/stats.php?id=4441770>TrollGate</a> or <a href=http://www.kingsofchaos.com/stats.php?id=4447414>Pheo</a> via KoC pm.</td></tr>"
  184. + "</table></center><br><br>";
  185. document.getElementsByClassName("content")[0].insertBefore(customDiv, document.getElementsByClassName('table_lines')[0]);
  186.  
  187. document.getElementById('registerDF').addEventListener('click', function(){ BasePHP_OnRegisterDF(username, statid, uniqid, DF_password); }, false);
  188. GM_setValue("DF_eligable", 0);
  189. }
  190. else if(r.responseText == "Invalid Password")
  191. {
  192. var customDiv = document.createElement("div");
  193. customDiv.innerHTML = "<br><center><table class=table_lines width=100%><tr><th style=\"border-color: darkred; background-color:red; height: 4ex;\">Your Dead Fish password is invalid!</th></tr>"
  194. + "<tr><td>Click <a href=# id=putDFPassword onClick=\"return false;\">here</a> to re-enter your DF password."
  195. + "<br><br>If you do not remember your DF password, contact <a href=http://www.kingsofchaos.com/stats.php?id=4436620>Falcon_Punch_AaA</a>, <a href=http://www.kingsofchaos.com/stats.php?id=4410144>Satellite</a>, <a href=http://www.kingsofchaos.com/stats.php?id=4408105>jfl888888</a> or <a href=http://www.kingsofchaos.com/stats.php?id=4401644>wAaArgasm</a> via KoC pm.</td></tr>"
  196. + "</table></center><br><br>";
  197. document.getElementsByClassName("content")[0].insertBefore(customDiv, document.getElementsByClassName('table_lines')[0]);
  198.  
  199. document.getElementById('putDFPassword').addEventListener('click', function(){ BasePHP_OnputDFPassword(username, DF_password); }, false);
  200. GM_setValue("DF_eligable", 0);
  201. }
  202. else if(r.responseText == "Not Activated")
  203. {
  204. var customDiv = document.createElement("div");
  205. customDiv.innerHTML = "<br><center><table class=table_lines width=100%><tr><th style=\"border-color: darkorange; background-color:orange; height: 4ex;\">Your Dead Fish account is not activated!</th></tr>"
  206. + "<tr><td>If this is taking too long, contact <a href=http://www.kingsofchaos.com/stats.php?id=4436620>Falcon_Punch_AaA</a>, <a href=http://www.kingsofchaos.com/stats.php?id=4410144>Satellite</a>, <a href=http://www.kingsofchaos.com/stats.php?id=4408105>jfl888888</a> or <a href=http://www.kingsofchaos.com/stats.php?id=4401644>wAaArgasm</a> via KoC pm.</td></tr>"
  207. + "</table></center><br><br>";
  208. document.getElementsByClassName("content")[0].insertBefore(customDiv, document.getElementsByClassName('table_lines')[0]);
  209. GM_setValue("DF_eligable", 0);
  210. }
  211. else
  212. {
  213. var customDiv = document.createElement("div");
  214. customDiv.innerHTML = r.responseText.indexOf("<div id=\"x\">") >= 0 ? r.responseText : "<center><b>Server is currently down. Please wait a few minutes.</b></center><br>";
  215.  
  216. document.getElementsByClassName("content")[0].insertBefore(customDiv, document.getElementsByClassName('table_lines')[0]);
  217. GM_setValue("DF_eligable", 1);
  218. }
  219. }
  220. }
  221. });
  222.  
  223.  
  224. var MilOverviewTable = GetTable("Military Overview");
  225. if (MilOverviewTable) {
  226. var projIncomeRow = GetTableRow(MilOverviewTable, 0, "<b>Projected Income");
  227. if (projIncomeRow >= 0) {
  228. var projIncome = GetTextIn(MilOverviewTable.rows[projIncomeRow].cells[1].innerHTML, "", " ").replace(/,/g, "");
  229. MilOverviewTable.insertRow(projIncomeRow + 1).innerHTML = "<td><b>Hourly Income</b></td><td>" + AddCommas(Math.floor((projIncome * 60)).toString()) + " Gold (in 60 mins)</td>"
  230. }
  231. }
  232.  
  233. // Update own stats
  234. var sa = GetText(">Strike Action<", "\">", "<").replace(/,/g, "");
  235. var da = GetText(">Defensive Action<", "\">", "<").replace(/,/g, "");
  236. var spy = GetText(">Spy Rating<", "\">", "<").replace(/,/g, "");
  237. var sentry = GetText(">Sentry Rating<", "\">", "<").replace(/,/g, "");
  238. var officerBonus = GetText("in today (x ",")");
  239. GM_setValue("DF_currentOfficerBonus", officerBonus);
  240. GM_xmlhttpRequest({
  241. method: "GET",
  242. url: DF_server + "backbone.php?code=selfupdate&whoami=" + username + "&password=" + DF_password + "&whoamid=" + statid + "&sa=" + sa + "&da=" + da + "&spy=" + spy + "&sentry=" + sentry + "&officerbonus=" + officerBonus
  243. });
  244.  
  245. // Add the DF options button
  246. var table = GetTag('th', "Preferences").parentNode.parentNode;
  247. table.insertRow(2).innerHTML = "<td align=center><a style=\"cursor:pointer\" id=bOpenDFOptions>DF Options</a>";
  248. document.getElementById('bOpenDFOptions').addEventListener('click', BasePHP_OnToggleDFOptions, false);
  249.  
  250. // Add the DF options
  251. var dfOptions = "<table width=100% class=table_lines cellspacing=0 cellpadding=8><tr><th colspan=2>DF Options</th></tr>"
  252. + "<tr><td align=right><label for=dfOptionArmoryDetail>Add Armory Detail Stats</label></td><td><input type=checkbox id=dfOptionArmoryDetail " + (GM_getValue("DF_OptionArmoryDetail", 1) == 0 ? "" : "checked") + "></input></td></tr>"
  253. + "<tr><td align=right><label for=dfOptionScrollIntoContent>Scroll into the content</label></td><td><input type=checkbox id=dfOptionScrollIntoContent " + (GM_getValue("DF_OptionScrollIntoContent", 1) == 0 ? "" : "checked") + "></input></td></tr>"
  254. + "<tr><td align=right><label for=dfOptionEconomicDevelopment>Remove Economic Development</label></td><td><input type=checkbox id=dfOptionEconomicDevelopment " + (GM_getValue("DF_OptionEconomicDevelopment", 1) == 0 ? "" : "checked") + "></input></td></tr>"
  255. + "<tr><td align=right><label for=dfOptionSpecialEffects>Special effects</label></td><td><input type=checkbox id=dfOptionSpecialEffects " + (GM_getValue("DF_OptionSpecialEffects", 1) == 0 ? "" : "checked") + "></input></td></tr>"
  256. + "<tr><td align=right><label for=dfOptionShowLastMsgSent>Show last msg sent</label></td><td><input type=checkbox id=dfOptionShowLastMsgSent " + (GM_getValue("DF_OptionShowLastMsgSent", 1) == 0 ? "" : "checked") + "></input></td></tr>"
  257. + "<tr><td align=right>Password</td><td><input id=dfOptionPassword value=\"" + GM_getValue("DF_password", "") + "\"></input></td></tr>"
  258. + "<tr><td colspan=2 align=right style=\"border-bottom:0; padding:2em;\"><button id=bSaveDFOptions>Save</button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<button id=bCancelDFOptions>Cancel</button></td></tr>"
  259. + "</table>";
  260.  
  261. var dfOptionsContainerDiv = document.createElement('div');
  262. dfOptionsContainerDiv.innerHTML = "<div id=ddfOptionsContainer style=\"display:none; position:fixed; width:100%; height:100%; left:0; top:0; background-color:gray; opacity:0.50; z-index:10;\"></div>";
  263.  
  264. var dfOptionsDiv = document.createElement('div');
  265. dfOptionsDiv.innerHTML = "<div id=ddfOptions style=\"display:none; position:fixed; width:60ex; height:25em; left:50%; margin-left:-30ex; top:50%; margin-top:-10em; background-color:black; z-index:15; padding:10px;\">" + dfOptions + "</div>";
  266.  
  267. document.body.appendChild(dfOptionsContainerDiv);
  268. document.body.appendChild(dfOptionsDiv);
  269.  
  270. document.getElementById('bSaveDFOptions').addEventListener('click', BasePHP_OnSaveDFOptions, false);
  271. document.getElementById('bCancelDFOptions').addEventListener('click', BasePHP_OnToggleDFOptions, false);
  272.  
  273. // Expand/collapse tables
  274. ExpandCollapseTable("Grow Your Army");
  275. ExpandCollapseTable("Notice from Commander");
  276. ExpandCollapseTable("Recent Attacks on You");
  277. ExpandCollapseTable("Military Overview");
  278. ExpandCollapseTable("Military Effectiveness");
  279. ExpandCollapseTable("Previous Logins");
  280. ExpandCollapseTable("Preferences");
  281. ExpandCollapseTable("Officers");
  282. }
  283.  
  284. function ArmoryPHP()
  285. {
  286.  
  287. if(GM_getValue("DF_eligable", 0) == 0)
  288. {
  289. return;
  290. }
  291.  
  292. // Update own stats
  293. var sa = GetText(">Strike Action<", "\">", "<").replace(/,/g, "");
  294. var da = GetText(">Defensive Action<", "\">", "<").replace(/,/g, "");
  295. var spy = GetText(">Spy Rating<", "\">", "<").replace(/,/g, "");
  296. var sentry = GetText(">Sentry Rating<", "\">", "<").replace(/,/g, "");
  297.  
  298. GM_xmlhttpRequest(
  299. {
  300. method: "GET",
  301. url: DF_server + "backbone.php?code=selfupdate&whoami=" + DF_username + "&password=" + DF_password + "&whoamid=" + DF_statid + "&sa=" + sa + "&da=" + da + "&spy=" + spy + "&sentry=" + sentry
  302. });
  303.  
  304. // Read current weapons and tools
  305. var weaponsTable = GetTable("Current Weapon Inventory");
  306. var toolsTable = GetTable("Current Tool Inventory");
  307. var buyWeaponsTable = GetTable("Buy Weapons");
  308.  
  309. var weapons = []; // holds the number of current weapons+tools (length is same as the global weaponList)
  310. var totalSellValue = 0;
  311. var totalInvestedValue = 0;
  312.  
  313. var totalAttackWeapons = 0;
  314. var totalDefenseWeapons = 0;
  315. var totalSpyTools = 0;
  316. var totalSentryTools = 0;
  317.  
  318. for(var i = 0; i < weaponList.length; i++)
  319. {
  320. weapons.push(0);
  321. }
  322.  
  323. var passedDefenseWeapons = 0;
  324. var idxDefenseWeaponsTh = -1;
  325.  
  326. for(var i = 0; i < weaponsTable.rows.length; i++)
  327. {
  328. if(weaponsTable.rows[i].cells.length < 4) continue;
  329.  
  330. var wepName = weaponsTable.rows[i].cells[0].innerHTML;
  331.  
  332. if(wepName == "Defense Weapons")
  333. {
  334. passedDefenseWeapons = 1;
  335. idxDefenseWeaponsTh = i;
  336. continue;
  337. }
  338.  
  339. var wepCount = parseInt( weaponsTable.rows[i].cells[1].innerHTML.replace(/,/g, "") );
  340. var wepSell = parseInt( GetTextIn(weaponsTable.rows[i].cells[3].innerHTML, "Sell for ", " Gold").replace(/,/g, "") );
  341.  
  342. if(isNaN(wepCount) == false && isNaN(wepSell) == false)
  343. {
  344. totalSellValue += (wepCount * wepSell);
  345. }
  346.  
  347. var j = GetTableRow(buyWeaponsTable, 0, wepName);
  348. if(j >= 0)
  349. {
  350. var wepCost = parseInt( buyWeaponsTable.rows[j].cells[2].innerHTML.replace(/,/g, "") );
  351. if(isNaN(wepCount) == false && isNaN(wepCost) == false)
  352. {
  353. totalInvestedValue += (wepCount * wepCost);
  354. }
  355. }
  356.  
  357. var idx = weaponList.indexOf(wepName);
  358. if(idx >= 0)
  359. {
  360. weapons[idx] = wepCount;
  361. }
  362.  
  363. if(passedDefenseWeapons == 0)
  364. {
  365. totalAttackWeapons += wepCount;
  366. }
  367. else
  368. {
  369. totalDefenseWeapons += wepCount;
  370. }
  371.  
  372.  
  373. }
  374.  
  375. // same for the tools
  376. var passedSentryTools = 0;
  377. var idxSentryToolsTh = -1;
  378.  
  379. for(var i = 0; i < toolsTable.rows.length; i++)
  380. {
  381. if(toolsTable.rows[i].cells.length < 4) continue;
  382.  
  383. var wepName = toolsTable.rows[i].cells[0].innerHTML;
  384.  
  385. if(wepName == "Sentry Tools")
  386. {
  387. passedSentryTools = 1;
  388. idxSentryToolsTh = i;
  389. continue;
  390. }
  391.  
  392.  
  393.  
  394. var wepCount = parseInt( toolsTable.rows[i].cells[1].innerHTML.replace(/,/g, "") );
  395. var wepSell = parseInt( GetTextIn(toolsTable.rows[i].cells[3].innerHTML, "Sell for ", " Gold").replace(/,/g, "") );
  396.  
  397. if(isNaN(wepCount) == false && isNaN(wepSell) == false)
  398. {
  399. totalSellValue += (wepCount * wepSell);
  400. }
  401.  
  402.  
  403. var j = GetTableRow(buyWeaponsTable, 0, wepName);
  404. if(j >= 0)
  405. {
  406. var wepCost = parseInt( buyWeaponsTable.rows[j].cells[2].innerHTML.replace(/,/g, "") );
  407. if(isNaN(wepCount) == false && isNaN(wepCost) == false)
  408. {
  409. totalInvestedValue += (wepCount * wepCost);
  410. }
  411. }
  412.  
  413. var idx = weaponList.indexOf(wepName);
  414. if(idx >= 0)
  415. {
  416. weapons[idx] = wepCount;
  417. }
  418.  
  419. if(passedSentryTools == 0)
  420. {
  421. if(isNaN(wepCount) == false && isNaN(wepSell) == false)
  422. {
  423. totalSpyTools += wepCount;
  424. }
  425. }
  426. else
  427. {
  428. if(isNaN(wepCount) == false && isNaN(wepSell) == false)
  429. {
  430. totalSentryTools += wepCount;
  431. }
  432. }
  433.  
  434. }
  435.  
  436. // show the aat and sell value (weapons)
  437. if(weaponsTable.rows.length > 2)
  438. {
  439. weaponsTable.rows[1].innerHTML = weaponsTable.rows[1].innerHTML.replace("Weapons</th>", "Weapons</th><th class=subh align=right>AAT</th>");
  440. }
  441.  
  442. for(var i = 2; i < weaponsTable.rows.length; i++)
  443. {
  444. if(weaponsTable.rows[i].cells.length < 4) continue;
  445.  
  446. var wepName = weaponsTable.rows[i].cells[0].innerHTML;
  447. if(wepName == "Defense Weapons")
  448. {
  449. weaponsTable.rows[i].innerHTML = weaponsTable.rows[i].innerHTML.replace("Weapons</th>", "Weapons</th><th class=subh align=right>AAT</th>");
  450. continue;
  451. }
  452.  
  453. var wepCount = parseInt( weaponsTable.rows[i].cells[1].innerHTML.replace(/,/g, "") );
  454. var wepSell = parseInt( GetTextIn(weaponsTable.rows[i].cells[3].innerHTML, "Sell for ", " Gold").replace(/,/g, "") );
  455. var sellValue = wepCount * wepSell;
  456.  
  457. var j = GetTableRow(buyWeaponsTable, 0, wepName);
  458. var wepCost = parseInt( buyWeaponsTable.rows[j].cells[2].innerHTML.replace(/,/g, "") );
  459.  
  460. var aat = parseInt( Math.floor(totalInvestedValue / (wepCost * 400)) );
  461.  
  462. weaponsTable.rows[i].insertCell(1).innerHTML = AddCommas(Math.min(aat, wepCount).toString());
  463. weaponsTable.rows[i].cells[1].setAttribute('align', "right");
  464. if(GM_getValue("DF_OptionArmoryDetail", 1) != 0)
  465. {
  466. weaponsTable.rows[i].cells[0].innerHTML = weaponsTable.rows[i].cells[0].innerHTML + "<br><span style='padding-left: 5px; color: #FFCC00; font-size: 80%;'>Sell value: " + addCommas(sellValue) + "</span>";
  467. }
  468. }
  469.  
  470. // show the aat and sell value (tools)
  471. if(toolsTable.rows.length > 2)
  472. {
  473. toolsTable.rows[1].innerHTML = toolsTable.rows[1].innerHTML.replace("Tools</th>", "Tools</th><th class=subh align=right>AAT</th>");
  474. }
  475.  
  476. for(var i = 2; i < toolsTable.rows.length; i++)
  477. {
  478. if(toolsTable.rows[i].cells.length < 4) continue;
  479.  
  480. var wepName = toolsTable.rows[i].cells[0].innerHTML;
  481. if(wepName == "Sentry Tools")
  482. {
  483. toolsTable.rows[i].innerHTML = toolsTable.rows[i].innerHTML.replace("Tools</th>", "Tools</th><th class=subh align=right>AAT</th>");
  484. continue;
  485. }
  486.  
  487. var wepCount = parseInt( toolsTable.rows[i].cells[1].innerHTML.replace(/,/g, "") );
  488. var wepSell = parseInt( GetTextIn(toolsTable.rows[i].cells[3].innerHTML, "Sell for ", " Gold").replace(/,/g, "") );
  489. var sellValue = wepCount * wepSell;
  490.  
  491. var j = GetTableRow(buyWeaponsTable, 0, wepName);
  492. var wepCost = parseInt( buyWeaponsTable.rows[j].cells[2].innerHTML.replace(/,/g, "") );
  493.  
  494. var aat = parseInt( Math.floor(totalInvestedValue / (wepCost * 400)) );
  495.  
  496. toolsTable.rows[i].insertCell(1).innerHTML = AddCommas(Math.min(aat, wepCount).toString());
  497. toolsTable.rows[i].cells[1].setAttribute('align', "right");
  498. if(GM_getValue("DF_OptionArmoryDetail", 1) != 0)
  499. {
  500. toolsTable.rows[i].cells[0].innerHTML = toolsTable.rows[i].cells[0].innerHTML + "<br><span style='padding-left: 5px; color: #FFCC00; font-size: 80%;'>Sell value: " + addCommas(sellValue) + "</span>";
  501. }
  502. }
  503.  
  504. if(GM_getValue("DF_OptionArmoryDetail", 1) != 0)
  505. {
  506. // TO-DO: Merge this with above. So we don't have to do another loop
  507. // Add strength for each weapon
  508. var htmlHead = document.getElementsByTagName("head")[0].innerHTML;
  509. var myRace = FindText(FindText(htmlHead,'<link href="/images/css/common.css" rel="','css" r'),'/css/','.');
  510. var saBonus = 1;
  511. var daBonus = 1;
  512. var spyBonus = 1;
  513. var sentryBonus = 1;
  514.  
  515. switch(myRace)
  516. {
  517. case 'Humans': { spyBonus = 1.35; break;}
  518. case 'Dwarves': { daBonus = 1.4; break; }
  519. case 'Elves': { spyBonus = 1.45; break;}
  520. case 'Orcs': { daBonus = 1.2; saBonus = 1.35; break; }
  521. case 'Undead': { sentryBonus = 1.35; break;}
  522. }
  523.  
  524. var techMulti = GM_getValue("DF_currentTech", 1);
  525. var officerBonus = GM_getValue("DF_currentOfficerBonus", 1);
  526.  
  527. var myFortText = FindText(FindText(document.body.innerHTML,'Current Fortification','<td align="center">'),'<td>','</td>').split(" (")[0];
  528. var mySiegeText = FindText(FindText(document.body.innerHTML,'Current Siege Technolog','<td align="center">'),'<td>','</td>').split(" (")[0];
  529.  
  530. SiegeArray = SiegeList(mySiegeText).split('|');
  531. FortArray = FortList(myFortText).split('|');
  532. // Returns: Multiply | Next Upgrade | Next Price | Next Multiply
  533.  
  534. var siegeBonus = 0;
  535. var fortBonus = 0;
  536.  
  537. if(SiegeArray[0] != "Max")
  538. siegeBonus = SiegeArray[0];
  539. else {
  540. siegeBonus = 39.37;
  541. }
  542.  
  543. if(FortArray[0] != "Max")
  544. fortBonus = FortArray[0];
  545. else
  546. fortBonus = 35.53;
  547.  
  548. var strength = 0;
  549. var atDefenseWeapons = 0;
  550. var atSentryTools = 0;
  551.  
  552. for(var i = 2; i < weaponsTable.rows.length; i++)
  553. {
  554. var wepName = weaponsTable.rows[i].cells[0].innerHTML;
  555. //alert(wepName);
  556. if(wepName == "Defense Weapons")
  557. {
  558. atDefenseWeapons = 1;
  559. continue;
  560. }
  561. if(wepName.indexOf("repair") > 0)
  562. {
  563. continue;
  564. }
  565.  
  566. strength = weaponsTable.rows[i].cells[3].innerHTML.split("/")[1].replace(/,/g, "");
  567.  
  568. if(atDefenseWeapons == 0)
  569. weaponsTable.rows[i].cells[3].innerHTML = weaponsTable.rows[i].cells[3].innerHTML + "<div style=\"display: inline; color: #905000; font-size: 80%; cursor: help;\" title=\"The strength of 1 weapon\"><br>[" + addCommas(Math.round(strength * techMulti * officerBonus * saBonus * siegeBonus * 5)) + "]</div>";
  570. else
  571. weaponsTable.rows[i].cells[3].innerHTML = weaponsTable.rows[i].cells[3].innerHTML + "<div style=\"display: inline; color: #905000; font-size: 80%; cursor: help;\" title=\"The strength of 1 weapon\"><br>[" + addCommas(Math.round(strength * techMulti * officerBonus * daBonus * fortBonus * 5)) + "]</div>";
  572.  
  573. }
  574.  
  575. for(var i = 2; i < toolsTable.rows.length; i++)
  576. {
  577. if(toolsTable.rows[i].cells.length < 4) continue;
  578.  
  579. strength = toolsTable.rows[i].cells[3].innerHTML.replace(/,/g, "");
  580.  
  581. var wepName = toolsTable.rows[i].cells[0].innerHTML;
  582. if(wepName == "Sentry Tools")
  583. {
  584. atSentryTools = 1;
  585. continue;
  586. }
  587.  
  588. if(atSentryTools == 0)
  589. toolsTable.rows[i].cells[3].innerHTML = toolsTable.rows[i].cells[3].innerHTML + "<div style=\"display: inline; color: #905000; font-size: 80%; cursor: help;\" title=\"The strength of 1 weapon\"><br>[" + addCommas(Math.round(strength * officerBonus * techMulti * spyBonus * Math.pow(1.60,GM_getValue("Covert_Skill",15)))) + "]</div>";
  590. else
  591. toolsTable.rows[i].cells[3].innerHTML = toolsTable.rows[i].cells[3].innerHTML + "<div style=\"display: inline; color: #905000; font-size: 80%; cursor: help;\" title=\"The strength of 1 weapon\"><br>[" + addCommas(Math.round(strength * officerBonus * techMulti * sentryBonus * Math.pow(1.60,GM_getValue("Covert_Skill",15)))) + "]</div>";
  592. }
  593. }
  594.  
  595. // Show how much weapon is held
  596. soldiers = GetSoldiers();
  597.  
  598.  
  599.  
  600. if(totalAttackWeapons > 0)
  601. {
  602. var attackSoldiers = soldiers.tas + soldiers.tam + soldiers.us + soldiers.um;
  603. var unheld = totalAttackWeapons - attackSoldiers;
  604. if(unheld > 0)
  605. {
  606. weaponsTable.rows[1].cells[0].innerHTML += " <span style='color:red; border-left: 1px solid white'>&nbsp;Unheld: " + unheld + "</span>";
  607. }
  608. }
  609.  
  610. if(totalDefenseWeapons > 0)
  611. {
  612. var defenseSoldiers = soldiers.tds + soldiers.tdm + soldiers.us + soldiers.um;
  613. var unheld = totalDefenseWeapons - defenseSoldiers;
  614. if(unheld > 0)
  615. {
  616. weaponsTable.rows[idxDefenseWeaponsTh].cells[0].innerHTML += " <span style='color:red; border-left: 1px solid white'>&nbsp;Unheld: " + unheld + "</span>";
  617. }
  618. }
  619.  
  620. if(totalSpyTools > 0)
  621. {
  622. var unheld = totalSpyTools - soldiers.spy;
  623. if(unheld > 0)
  624. {
  625. toolsTable.rows[1].cells[0].innerHTML += " <span style='color:red; border-left: 1px solid white'>&nbsp;Unheld: " + unheld + "</span>";
  626. }
  627. }
  628.  
  629. if(totalSentryTools > 0)
  630. {
  631. var unheld = totalSentryTools - soldiers.sentry;
  632. if(unheld > 0)
  633. {
  634. toolsTable.rows[idxSentryToolsTh].cells[0].innerHTML += " <span style='color:red; border-left: 1px solid white'>&nbsp;Unheld: " + unheld + "</span>";
  635. }
  636. }
  637.  
  638.  
  639. // Fix the width of the weapons and tools table together
  640. if(!weaponsTable.rows[1].cells[0].value == 'There are no weapons in your inventory.')
  641. {
  642. weaponsTable.rows[1].cells[0].width = '20%';
  643. weaponsTable.rows[1].cells[1].width = '15%';
  644. weaponsTable.rows[1].cells[2].width = '15%';
  645. weaponsTable.rows[1].cells[3].width = '15%';
  646. weaponsTable.rows[1].cells[4].width = '35%';
  647. }
  648.  
  649. //alert(toolsTable.rows[1].cells[0].innerHTML);
  650. if(!toolsTable.rows[1].cells[0] == 'undefined') { toolsTable.rows[1].cells[0].width = '20%'; }
  651. if(!toolsTable.rows[1].cells[1] == 'undefined') { toolsTable.rows[1].cells[1].width = '15%'; }
  652. if(!toolsTable.rows[1].cells[2] == 'undefined') { toolsTable.rows[1].cells[2].width = '15%'; }
  653. if(!toolsTable.rows[1].cells[3] == 'undefined') { toolsTable.rows[1].cells[3].width = '15%'; }
  654. if(!toolsTable.rows[1].cells[4] == 'undefined') { toolsTable.rows[1].cells[4].width = '35%'; }
  655.  
  656. // Fix the centerization of strength in tools table
  657. for(var i = 0; i < toolsTable.rows.length; i++)
  658. {
  659. if(toolsTable.rows[i].cells.length >= 5)
  660. {
  661. toolsTable.rows[i].cells[3].align = "right";
  662.  
  663. // make the tools sell form 90% to align with the weapons
  664. var toolId = GetTextIn(toolsTable.rows[i].cells[4].innerHTML, "scrapsell[", "]");
  665. if(toolId == "")
  666. {
  667. continue;
  668. }
  669.  
  670. var e = document.getElementsByName("scrapsell[" + toolId + "]");
  671. if(e.length != 1)
  672. {
  673. continue;
  674. }
  675.  
  676. e[0].parentNode.parentNode.parentNode.parentNode.width = "90%";
  677. e[0].parentNode.parentNode.parentNode.parentNode.align = "center";
  678. }
  679. }
  680.  
  681. // Show the armory value
  682. toolsTable.insertRow(-1).innerHTML = "<td colspan=5></td>";
  683. toolsTable.insertRow(-1).innerHTML = "<td colspan=5 align=center style='background-color:#003333; border-bottom:0'><strong>Sell value: " + AddCommas(totalSellValue.toString()) + " Gold</strong><strong> - Buy value: " + AddCommas(totalInvestedValue.toString()) + " Gold</strong></td>";
  684.  
  685. // Check for loss
  686. var lostLog = [];
  687.  
  688. var nowDate = new Date();
  689. var now = nowDate.getTime();
  690.  
  691. var BPM = 0;
  692. var CH = 0;
  693. var DS = 0;
  694. var IS = 0;
  695.  
  696. for(var i = 0; i < weaponList.length; i++)
  697. {
  698. if(weaponList[i] == 'Invisibility Shield') { IS = weapons[i]; }
  699. if(weaponList[i] == 'Dragonskin') { DS = weapons[i]; }
  700. if(weaponList[i] == 'Blackpowder Missile') { BPM = weapons[i]; }
  701. if(weaponList[i] == 'Chariot') { CH = weapons[i]; }
  702.  
  703. var oldCount = GM_getValue("DF_armory_" + weaponList[i].replace(/ /g, "_"), -1);
  704. var soldCount = GM_getValue("DF_armory_" + weaponList[i].replace(/ /g, "_") + "_sold", 0);
  705.  
  706. oldCount -= soldCount;
  707.  
  708. if(weapons[i] < oldCount)
  709. {
  710. lostLog.push((oldCount - weapons[i]) + ":" + weaponList[i] + ":" + now);
  711. }
  712.  
  713. GM_setValue("DF_armory_" + weaponList[i].replace(/ /g, "_"), weapons[i]);
  714. GM_setValue("DF_armory_" + weaponList[i].replace(/ /g, "_") + "_sold", 0);
  715. }
  716.  
  717. // Keep the last 10 logs of lost weapons
  718. var lostLogGlobal = [];
  719.  
  720. for(var i = 0; i < 10; i++)
  721. {
  722. lostLogGlobal.push(GM_getValue("DF_lost_wep_log_" + i, "::"));
  723. }
  724.  
  725. // Add to the lost weapon log
  726. var lostLogTop = []; // to show at the top of the page
  727.  
  728. for(var i = 0; i < lostLog.length; i++)
  729. {
  730. lostLogGlobal.unshift(lostLog[i]);
  731.  
  732. var lostWepDetails = lostLog[i].split(":");
  733. lostLogTop.push("You are missing " + lostWepDetails[0] + " " + lostWepDetails[1] + (lostWepDetails[0] > 1 ? "s" : ""));
  734. }
  735.  
  736. if(lostLogTop.length > 0)
  737. {
  738. weaponsTable.insertRow(0).innerHTML = "<td colspan=5 style='background-color:red'><strong>" + lostLogTop.join("<br>") + "</strong></td>";
  739.  
  740. // Special effect, I made this, dont steal!
  741. if(GM_getValue("DF_OptionSpecialEffects", 1) != 0)
  742. {
  743. var bloodDiv = document.createElement('div');
  744. bloodDiv.setAttribute('style', "position:fixed; left:0; top:0; width:100%; height:100%; background-color:red; opacity:1.0; z-index:1000;");
  745. bloodDiv.setAttribute('id', "bloodDiv");
  746. document.body.appendChild(bloodDiv);
  747.  
  748. setTimeout(ArmoryPHP_ReduceBloodEffect, 100);
  749. }
  750. }
  751.  
  752.  
  753. if(GM_getValue("DF_OptionArmoryDetail", 1) != 0)
  754. {
  755. // When to upgrade (Added By Shane)
  756. var htmlHead = document.getElementsByTagName("head")[0].innerHTML;
  757. var myRace = FindText(FindText(htmlHead,'<link href="/images/css/common.css" rel="','css" r'),'/css/','.');
  758. var saBonus=1;
  759. var daBonus=1;
  760.  
  761. var techMulti = GM_getValue("DF_currentTech", 1);
  762. var officerBonus = GM_getValue("DF_currentOfficerBonus", 1);
  763.  
  764. switch(myRace)
  765. {
  766. case 'Dwarves': { daBonus = 1.4; break }
  767. case 'Orcs': { daBonus = 1.2;saBonus = 1.35; break }
  768. }
  769.  
  770. var upgradeTable = GetTable("Armory Autofill Preferences");
  771. upgradeTable.insertRow(-1).innerHTML = "<td colspan=3></td>";
  772. upgradeTable.insertRow(-1).innerHTML = "<th colspan=3>Upgrade Table</th>";
  773.  
  774. var myFort = FindText(FindText(document.body.innerHTML,'Current Fortification','<td align="center">'),'<td>','</td>').split(" (")[0]
  775. var mySiege = FindText(FindText(document.body.innerHTML,'Current Siege Technolog','<td align="center">'),'<td>','</td>').split(" (")[0]
  776.  
  777. FortArray = FortList(myFort).split('|');
  778. SiegeArray = SiegeList(mySiege).split('|');
  779. // Returns: Multiply | Next Upgrade | Next Price | Next Multiply
  780.  
  781. var BPMMsg = '';
  782. var CHMsg = '';
  783. var ISMsg = '';
  784. var DSMsg = '';
  785.  
  786. var attackSol = ((((soldiers.tas + soldiers.tam) * 5) * techMulti) * officerBonus);
  787. var defenceSol = ((((soldiers.tds + soldiers.tdm) * 5) * techMulti) * officerBonus);
  788. var untrainedSol = ((((soldiers.us + soldiers.um) * 4) * techMulti) * officerBonus);
  789.  
  790. if((!isNaN(BPM)) && (!isNaN(CH))) {
  791.  
  792. if(SiegeArray[1] != 'Max') // We have some upgrades left.
  793. {
  794. var currentSA = ((((BPM*SiegeArray[0])*1000)*6)*saBonus + ((((CH*SiegeArray[0])*600)*6)*saBonus)); // Forumla is correct.
  795.  
  796. var tmpcurrentSA = addCommas(Math.round((((currentSA * techMulti) * officerBonus) + attackSol) + untrainedSol));
  797.  
  798.  
  799. var sellBPM = Math.round(removeComma(SiegeArray[2]) / 700000);
  800. var sellCH = Math.round(removeComma(SiegeArray[2]) / 315000);
  801.  
  802. var newBPM = BPM-sellBPM; //New amount of BPM after selling for upgrade.
  803. var newCH = CH-sellCH;
  804.  
  805.  
  806. var newSA = (((newBPM*SiegeArray[3])*1000)*6)*saBonus + (((CH*SiegeArray[3])*600)*6)*saBonus;
  807. var newSACH = (((newCH*SiegeArray[3])*600)*6)*saBonus + (((BPM*SiegeArray[3])*1000)*6)*saBonus
  808.  
  809. if(currentSA < newSA)
  810. {
  811. if(sellBPM < BPM)
  812. {
  813. BPMMsg += "Sell " + sellBPM + " BPMs and buy " + SiegeArray[1];
  814. BPMMsg += "<br>You'll gain " + addCommas(Math.round(((newSA-currentSA) * techMulti)*officerBonus)) + " SA...";
  815. }else{
  816. BPMMsg += 'Its not profitable to buy ' + SiegeArray[1] + ' yet with BPMs';
  817. }
  818.  
  819. if(currentSA < newSACH)
  820. {
  821. if(sellCH < CH){
  822. CHMsg += "Sell " + sellCH + " Chariots and buy " + SiegeArray[1];
  823. CHMsg += "<br>You'll gain " + addCommas(Math.round(((newSACH-currentSA) * techMulti)*officerBonus)) + " SA...";
  824. }else{
  825. CHMsg += 'Its not profitable to buy ' + SiegeArray[1] + ' yet with CHs';
  826. }
  827. }else{
  828. CHMsg += 'Its not profitable to buy ' + SiegeArray[1] + ' yet with CHs';
  829. }
  830. }else{
  831. BPMMsg += 'Its not profitable to buy ' + SiegeArray[1] + ' yet with BPMs';
  832. if(currentSA < newSACH)
  833. {
  834. if(sellCH < CH)
  835. {
  836. CHMsg += "Sell " + sellCH + " Chariots and buy " + SiegeArray[1];
  837. CHMsg += "<br>You'll gain " + addCommas(Math.round(((newSACH-currentSA) * techMulti)*officerBonus)) + " SA...";
  838. }
  839. }else{
  840. CHMsg += 'Its not profitable to buy ' + SiegeArray[1] + ' yet with CHs';
  841. }
  842.  
  843. }
  844. }else{
  845. CHMsg = 'Already got all sa upgrades.';
  846. BPMMsg = 'Already got all sa upgrades.';
  847. }
  848. }else{
  849. CHMsg = "Couldn't detect your Chariots.";
  850. BPMMsg = "Couldn't detect your BPMs.";
  851. }
  852.  
  853.  
  854.  
  855.  
  856. if((!isNaN(IS)) && (!isNaN(DS))) {
  857. if(FortArray[1] != 'Max') // We have some upgrades left.
  858. {
  859. //alert((((1*FortArray[0])*256)*5)*daBonus); // 41,813,923
  860. var currentDA = ((((IS*FortArray[0])*1000)*6)*daBonus + (((DS*FortArray[0])*256)*6)*daBonus); // Forumla is correct.
  861. var tmpcurrentDA = addCommas(Math.round((((currentDA * techMulti) * officerBonus) + defenceSol) + untrainedSol));
  862.  
  863. var sellIS = Math.round(removeComma(FortArray[2]) / 700000);
  864. var sellDS = Math.round(removeComma(FortArray[2]) / 140000);
  865.  
  866. var newIS = IS-sellIS; //New amount ofIS after selling for upgrade.
  867. var newDS = DS-sellDS; //New amount of DS after selling for upgrade.
  868.  
  869. var newDA = ((((newIS*FortArray[3])*1000)*6)*daBonus + (((DS*FortArray[3])*256)*6)*daBonus); // Forumla is correct.
  870.  
  871. var newDADS = ((((newDS*FortArray[3])*256)*6)*daBonus + (((IS*FortArray[3])*1000)*6)*daBonus); // Forumla is correct.
  872.  
  873. if(currentDA < newDA)
  874. {
  875. if(newIS < IS){
  876. ISMsg += "Sell " + sellIS + " ISs and buy " + FortArray[1];
  877. ISMsg += "<br>You'll gain " + addCommas(Math.round(((newDA-currentDA) * techMulti)*officerBonus))+ " DA...";
  878. }else{
  879. ISMsg += 'Its not profitable to buy ' + FortArray[1] + ' yet with ISs';
  880. }
  881.  
  882. if(currentDA < newDADS)
  883. {
  884. if(sellDS < DS){
  885. DSMsg += "Sell " + sellDS + " Dragon Skins and buy " + FortArray[1];
  886. DSMsg += "<br>You'll gain " + addCommas(Math.round(((newDADS-currentDA) * techMulti)*officerBonus))+ " DA...";
  887. }else{
  888. DSMsg += 'Its not profitable to buy ' + FortArray[1] + ' yet with Dragon Skins';
  889. }
  890. }else{
  891. DSMsg += 'Its not profitable to buy ' + FortArray[1] + ' yet with Dragon Skins';
  892. }
  893. }else{
  894. ISMsg += 'Its not profitable to buy ' + FortArray[1] + ' yet with ISs';
  895. if(currentDA < newDADS)
  896. {
  897. if(sellDS < DS){
  898. DSMsg += "Sell " + sellDS + " DSs and buy " + FortArray[1];
  899. DSMsg += "<br>You'll gain " + addCommas(Math.round(((newDADS-currentDA) * techMulti)*officerBonus))+ " DA...";
  900. }else{
  901. DSMsg = 'Its not profitable to buy ' + FortArray[1] + ' with dragon skins';
  902. }
  903. }else{
  904. DSMsg = 'Its not profitable to buy ' + FortArray[1] + ' with dragon skins';
  905. }
  906. }
  907. }else{
  908. ISMsg = 'Already got all da upgrades.';
  909. DSMsg = 'Already got all da upgrades.';
  910. }
  911. }else{
  912. upgradeMsgDA = "Couldn't detect your IS [or] DS count";
  913. }
  914.  
  915. upgradeTable.insertRow(-1).innerHTML = "<td align=right>SA Upgrade</td>"
  916. + "<td align=left>BPM</td>"
  917. + "<td align=left>" + BPMMsg + "</td>";
  918.  
  919. upgradeTable.insertRow(-1).innerHTML = "<td align=right>SA Upgrade</td>"
  920. + "<td align=left>Chariots</td>"
  921. + "<td align=left>" + CHMsg + "</td>";
  922.  
  923. upgradeTable.insertRow(-1).innerHTML = "<td align=right>DA Upgrade</td>"
  924. + "<td align=left>IS</td>"
  925. + "<td align=left>" + ISMsg + "</td>";
  926.  
  927. upgradeTable.insertRow(-1).innerHTML = "<td align=right>DA Upgrade</td>"
  928. + "<td align=left>Dragon Skins</td>"
  929. + "<td align=left>" + DSMsg + "</td>";
  930.  
  931. upgradeTable.insertRow(-1).innerHTML = "<td colspan=3 align=center><button id=upgradeTest onClick=\"return false;\" style='width:9ex'>Read me</button></td>";
  932.  
  933. document.getElementById('upgradeTest').addEventListener('click', function(event) {
  934. var testUpgrade = "Upgrade Table is in its beta stage, to ensure people don't make mistakes; use this as a guildline\n\n";
  935. testUpgrade += "Your SA is: " + addCommas(sa) + "\n";
  936. testUpgrade += "Our formula calculated your SA to be: " + tmpcurrentSA + "\n";
  937. testUpgrade += "If these two values are similar; its safe to trust our upgrade suggestions.\n\n";
  938.  
  939. testUpgrade += "Your DA is: " + addCommas(da) + "\n";
  940. testUpgrade += "Our formula calculated your DA to be: " + tmpcurrentDA + "\n";
  941. testUpgrade += "If these two values are similar; its safe to trust our upgrade suggestions.\n\n";
  942.  
  943. testUpgrade += "\n\n\n If the numbers are highly wrong, please visit training page, and command centre so DF can store your officer bonus; and tech bonus.";
  944. testUpgrade += "\n\n Please note: Our formula only calculates big weapons, it doesn't include soldiers and small weapons.";
  945. alert(testUpgrade);
  946.  
  947. }, false);
  948. // End of when to upgrade.
  949. }
  950. // Lost weapons log
  951. var lostTable = GetTable("Armory Autofill Preferences");
  952. lostTable.insertRow(-1).innerHTML = "<td colspan=3></td>";
  953. lostTable.insertRow(-1).innerHTML = "<th colspan=3>Lost Weapons Log</th>";
  954.  
  955. var anyLossLogged = false;
  956.  
  957. for(var i = 0; i < 10; i++)
  958. {
  959. GM_setValue("DF_lost_wep_log_" + i, lostLogGlobal[i]);
  960.  
  961. if(lostLogGlobal[i].length > 2) // at least "::"
  962. {
  963. var lostWepDetails = lostLogGlobal[i].split(":");
  964.  
  965. // fix plural
  966. lostWepDetails[1] += (lostWepDetails[0] > 1 ? "s" : "");
  967.  
  968. // compute elapsed time
  969. var elapsed = now - parseInt(lostWepDetails[2]);
  970. lostWepDetails[2] = elapsed > 0 ? PrintableTime(elapsed) + " ago" : "NOW!";
  971.  
  972. if(elapsed == 0)
  973. {
  974. lostWepDetails[0] = "<strong style='color:red'>" + lostWepDetails[0] + "</strong>";
  975. lostWepDetails[1] = "<strong style='color:red'>" + lostWepDetails[1] + "</strong>";
  976. lostWepDetails[2] = "<strong style='color:red'>" + lostWepDetails[2] + "</strong>";
  977. }
  978.  
  979. lostTable.insertRow(-1).innerHTML = "<td align=right>" + lostWepDetails[0] + "</td>"
  980. + "<td align=left>" + lostWepDetails[1] + "</td>"
  981. + "<td align=left>" + lostWepDetails[2] + "</td>";
  982.  
  983. anyLossLogged = true;
  984. }
  985. }
  986.  
  987. if(!anyLossLogged)
  988. {
  989. lostTable.insertRow(-1).innerHTML = "<td colspan=3 align=center>Nothing has been logged yet.</td>";
  990. }
  991.  
  992. // Listen to sell buttons so that sells wont be logged as missing
  993. var sellButtons = document.getElementsByName('doscrapsell');
  994. for(var i = 0; i < sellButtons.length; i++)
  995. {
  996. sellButtons[i].addEventListener('click', ArmoryPHP_OnSellButton, false);
  997. }
  998.  
  999. // Add a clear button for the lost weapons log
  1000. lostTable.insertRow(-1).innerHTML = "<td colspan=3 align=center><button id=clearLostLog onClick=\"return false;\" style='width:9ex'>Clear</button></td>";
  1001. document.getElementById('clearLostLog').addEventListener('click', ArmoryPHP_OnClearLostLog, false);
  1002.  
  1003. // Add keyboard shortcut to repair all button
  1004. var repairBut = GetElement('input', "Repair all");
  1005. if(repairBut && GM_getValue("DF_OptionKS", 1) != 0 )
  1006. {
  1007. repairBut.value = repairBut.value.replace("Repair", "Repair (r)");
  1008.  
  1009. document.addEventListener('keyup',
  1010. function(e)
  1011. {
  1012. if(e.target.type == "text") return;
  1013. if(e.target.type == "textarea") return;
  1014. if(e.target.type == "select-one") return;
  1015.  
  1016. switch(e.keyCode)
  1017. {
  1018. case 82: // R
  1019. GetElement('input', "Repair (r)").click();
  1020. break;
  1021. }
  1022.  
  1023. }, false);
  1024. }
  1025.  
  1026. // Add helper buttons for buying, if enabled
  1027. if(GM_getValue("DF_OptionBH", 0) == 1)
  1028. {
  1029. buyWeaponsTable.rows[1].cells[3].setAttribute('colspan', 2);
  1030.  
  1031. for(var i = 2; i < buyWeaponsTable.rows.length; i++)
  1032. {
  1033. if(buyWeaponsTable.rows[i].cells[0].innerHTML.indexOf("Defense Weapons") >= 0)
  1034. {
  1035. buyWeaponsTable.rows[i].cells[3].setAttribute('colspan', 2);
  1036. continue;
  1037. }
  1038.  
  1039. if(buyWeaponsTable.rows[i].cells[0].innerHTML.indexOf("Spy Tools") >= 0)
  1040. {
  1041. buyWeaponsTable.rows[i].cells[3].setAttribute('colspan', 2);
  1042. continue;
  1043. }
  1044. if(buyWeaponsTable.rows[i].cells[0].innerHTML.indexOf("Sentry Tools") >= 0)
  1045. {
  1046. buyWeaponsTable.rows[i].cells[3].setAttribute('colspan', 2);
  1047. continue;
  1048. }
  1049.  
  1050. if(buyWeaponsTable.rows[i].cells[0].innerHTML.indexOf("Buy Tools") >= 0) continue;
  1051. if(buyWeaponsTable.rows[i].cells.length < 4) continue;
  1052.  
  1053. buybutId = GetTextIn(buyWeaponsTable.rows[i].cells[3].innerHTML, "name=\"", "\"");
  1054. buyWeaponsTable.rows[i].insertCell(4).innerHTML = "<button id=" + buybutId + " onClick='return false'>0</button>";
  1055. buyWeaponsTable.rows[i].cells[4].align = "center";
  1056. document.getElementById(buybutId).addEventListener('click', function(){ document.getElementsByName(this.id)[0].value = this.innerHTML; ArmoryPHP_UpdateWeaponButtons(); }, false);
  1057. document.getElementsByName(buybutId)[0].addEventListener('blur', ArmoryPHP_UpdateWeaponButtons, false);
  1058. }
  1059. }
  1060.  
  1061. if(GM_getValue("DF_OptionKS", 0) == 1)
  1062. {
  1063. // Add another buy button and a clear button at top of the weapons
  1064. buyWeaponsTable.insertRow(0).innerHTML = "<td colspan=5></td>";
  1065. buyWeaponsTable.insertRow(0).innerHTML = "<td colspan=5 align=center style='background-color:#222222; border-bottom:1px solid #555555'>"
  1066. + "<button id=buybut2 onClick='this.disabled=true; this.innerHTML=\"Buying...\"; document.buyform.buybut.click(); return false;' style='margin-right:-9ex'>Buy Weapons</button>"
  1067. + "<button id=clearButtonTop style='float:right; width:9ex; margin-right:6px;' onClick='return false;'>Clear</button></td>";
  1068. document.getElementById('clearButtonTop').addEventListener('click', ArmoryPHP_OnClearBuyButtons, false);
  1069. }
  1070.  
  1071. // Add a clean button to the bottom
  1072. buyWeaponsTable.rows[buyWeaponsTable.rows.length-1].cells[0].innerHTML += "<button id=clearButtonBottom style='float:right; width:9ex; margin-right:6px;' onClick='return false;'>Clear</button>";
  1073. document.getElementsByName('buybut')[0].style.marginRight = "-9ex";
  1074. document.getElementById('clearButtonBottom').addEventListener('click', ArmoryPHP_OnClearBuyButtons, false);
  1075. buyWeaponsTable.rows[buyWeaponsTable.rows.length-1].cells[0].style.backgroundColor = "#222222";
  1076.  
  1077. // Add a buying note on top of the buy table
  1078. buyWeaponsTable.insertRow(1).innerHTML = "<td style='background-color:#222222; border-bottom:0'>Buying:</td>"
  1079. + "<td id=BuyingNote colspan=2 style='background-color:#222222; border-bottom:0'>Nothing</td>"
  1080. + "<td colspan=2 style='background-color:#222222; border-bottom:0'><button id=buybut2 onClick='this.disabled=true; this.innerHTML=\"Buying...\"; document.buyform.buybut.click(); return false;' style='margin-right:-9ex'>Buy Weapons</button></td>";
  1081.  
  1082. ArmoryPHP_UpdateWeaponButtons();
  1083. }
  1084. function TrainPHP()
  1085. {
  1086. if(GM_getValue("DF_eligable", 0) == 0)
  1087. {
  1088. return;
  1089. }
  1090.  
  1091. soldiers = GetSoldiers();
  1092.  
  1093. // Put helper buttons for training, if enabled
  1094. if(GM_getValue("DF_OptionBH", 0) == 1)
  1095. {
  1096. AddSoldierButton("Attack Specialist", "assign_attack", TrainPHP_OnAssignSoldier);
  1097. AddSoldierButton("Defense Specialist", "assign_defense", TrainPHP_OnAssignSoldier);
  1098. AddSoldierButton("Spy", "assign_spy", TrainPHP_OnAssignSoldier);
  1099. AddSoldierButton("Sentry", "assign_sentry", TrainPHP_OnAssignSoldier);
  1100.  
  1101. document.getElementsByName('train[attacker]')[0].addEventListener('blur', TrainPHP_UpdateTrainingButtons, false);
  1102. document.getElementsByName('train[defender]')[0].addEventListener('blur', TrainPHP_UpdateTrainingButtons, false);
  1103. document.getElementsByName('train[spy]')[0].addEventListener('blur', TrainPHP_UpdateTrainingButtons, false);
  1104. document.getElementsByName('train[sentry]')[0].addEventListener('blur', TrainPHP_UpdateTrainingButtons, false);
  1105.  
  1106. TrainPHP_UpdateTrainingButtons();
  1107.  
  1108. }
  1109. // Fix the training table spannings
  1110.  
  1111. var t = GetTag('th', "Train Your Troops");
  1112. if(t) t.attributes.getNamedItem('colspan').value++;
  1113.  
  1114. t = GetTag('th', "Quantity");
  1115. if(t) t.setAttribute('colspan', 2);
  1116.  
  1117. t = GetElement('input', "Train!");
  1118. if(t) t.parentNode.attributes.getNamedItem('colspan').value++;
  1119.  
  1120. if(GM_getValue("DF_OptionBH", 0) != 1)
  1121. {
  1122. t = GetTag('td', "Attack Specialist");
  1123. if(t) t.parentNode.innerHTML += "<td>&nbsp;</td>";
  1124.  
  1125. t = GetTag('td', "Defense Specialist");
  1126. if(t) t.parentNode.innerHTML += "<td>&nbsp;</td>";
  1127.  
  1128. t = GetTag('td', "Spy");
  1129. if(t) t.parentNode.innerHTML += "<td>&nbsp;</td>";
  1130.  
  1131. t = GetTag('td', "Sentry");
  1132. if(t) t.parentNode.innerHTML += "<td>&nbsp;</td>";
  1133. }
  1134.  
  1135. t = GetTag('td', "Reassign Attack Specialist");
  1136. if(t) t.parentNode.innerHTML += "<td>&nbsp;</td>";
  1137.  
  1138. t = GetTag('td', "Reassign Defense Specialist");
  1139. if(t) t.parentNode.innerHTML += "<td>&nbsp;</td>";
  1140.  
  1141. // Add a clean button next to the train button
  1142. var input = GetElement('input', "Train!");
  1143.  
  1144. if(input)
  1145. {
  1146. input.parentNode.innerHTML += "<button style=\"margin-left: 6px\" id=clear_training onClick=\"return false;\">Clear</button>";
  1147. document.getElementById('clear_training').addEventListener('click', TrainPHP_ClearTraining, false);
  1148.  
  1149. // Colorize the buttons' row
  1150. input = GetElement('input', "Train!");
  1151. input.parentNode.style.backgroundColor = "#222222";
  1152. }
  1153.  
  1154. // Remove the ! from the Train button (no other spend button has it)
  1155. t = GetElement('input', "Train!");
  1156. if(t) t.value = "Train";
  1157.  
  1158. // Hide the list of techs
  1159. var th = GetTag('th', "Technological Development");
  1160.  
  1161. if(th)
  1162. {
  1163. var table = th.parentNode.parentNode;
  1164.  
  1165. if(table.rows.length > 3)
  1166.  
  1167. {
  1168. table.rows[2].cells[0].innerHTML += "<span id=toggle_techs style=\"float:right;\"><tt>-</tt></span>";
  1169. table.rows[2].addEventListener('click', TrainPHP_OnToggleTechs, false);
  1170. table.rows[2].style.cursor = 'pointer';
  1171.  
  1172. // By default, hide techs
  1173. TrainPHP_OnToggleTechs();
  1174. }
  1175. }
  1176.  
  1177. var x;
  1178. x = FindText(document.body.innerHTML,'upgrade_tech','strength');
  1179. if(x)
  1180. {
  1181. x = FindText(x, "(x "," ");
  1182. }
  1183. else
  1184. {
  1185. // Reseach button is gone, because of highest tech reached
  1186. x = 7.39;
  1187.  
  1188. }
  1189.  
  1190. GM_setValue("DF_currentTech", x);
  1191.  
  1192. // Get the required exp for the next tech
  1193. var t = GetElement('input', "Research!");
  1194. if(t)
  1195. {
  1196. var str = t.value.toString();
  1197. var pos = str.indexOf(" ", 11);
  1198. var exp = parseInt( str.substring(11, pos).replace(/,/g, ""), 10 );
  1199.  
  1200. GM_setValue("DF_nextTechExp", exp);
  1201. }
  1202. else
  1203. {
  1204. // highest tech reached?
  1205. GM_setValue("DF_nextTechExp", -1);
  1206. }
  1207.  
  1208. // Remove economic development
  1209. if(GM_getValue("DF_OptionEconomicDevelopment", 1) != 0)
  1210. {
  1211. GetTag('th', "Economic Development").parentNode.parentNode.style.display = "none";
  1212. }
  1213.  
  1214. }
  1215.  
  1216. function MercsPHP()
  1217. {
  1218. if(GM_getValue("DF_eligable", 0) == 0)
  1219. {
  1220. return;
  1221. }
  1222.  
  1223. soldiers = GetSoldiers();
  1224. mercs = GetAvailableMercs();
  1225.  
  1226. // Put helper buttons for training, if enabled
  1227. if(GM_getValue("DF_OptionBH", 0) == 1)
  1228. {
  1229. AddSoldierButton("Attack Specialist", "assign_attack", MercsPHP_OnAssignMerc);
  1230. AddSoldierButton("Defense Specialist", "assign_defense", MercsPHP_OnAssignMerc);
  1231. AddSoldierButton("Untrained", "assign_untrained", MercsPHP_OnAssignMerc);
  1232.  
  1233. document.getElementsByName('mercs[attack]')[0].addEventListener('blur', MercsPHP_UpdateMercButtons, false);
  1234. document.getElementsByName('mercs[defend]')[0].addEventListener('blur', MercsPHP_UpdateMercButtons, false);
  1235. document.getElementsByName('mercs[general]')[0].addEventListener('blur', MercsPHP_UpdateMercButtons, false);
  1236.  
  1237. MercsPHP_UpdateMercButtons();
  1238. }
  1239.  
  1240. // Fix the mercs table spannings and shorten some headers
  1241. var t = GetTag('th', "Buy Mercenaries");
  1242. if(t) t.attributes.getNamedItem('colspan').value++;
  1243.  
  1244. t = GetTag('th', "Quantity to Buy");
  1245. if(t) t.setAttribute('colspan', 2);
  1246.  
  1247. t = GetElement('input', "Buy");
  1248. if(t) t.parentNode.attributes.getNamedItem('colspan').value++;
  1249.  
  1250. t = GetTag('th', "Quantity Available");
  1251. if(t) t.innerHTML = "Available";
  1252.  
  1253. t = GetTag('th', "Quantity to Buy");
  1254. if(t) t.innerHTML = "Quantity";
  1255.  
  1256.  
  1257. // Fix a design bug (main contaioner table is not 100% width in mercs.php)
  1258. document.getElementsByTagName("table")[6].setAttribute('width', '100%');
  1259.  
  1260. // Add a clean button next to the buy button
  1261. var input = GetElement('input', "Buy");
  1262.  
  1263. if(input)
  1264. {
  1265. input.parentNode.innerHTML += "<button style=\"margin-left: 6px\" id=clear_mercs onClick=\"return false;\">Clear</button>";
  1266. document.getElementById('clear_mercs').addEventListener('click', MercsPHP_ClearMercs, false);
  1267.  
  1268. input = GetElement('input', "Buy");
  1269. input.parentNode.style.backgroundColor = "#222222";
  1270.  
  1271. if(document.body.innerHTML.indexOf("There are not enough mercenaries available") > 0)
  1272. {
  1273. MercsPHP_ClearMercs();
  1274. }
  1275. }
  1276.  
  1277. }
  1278.  
  1279.  
  1280. function StatsPHP()
  1281. {
  1282. if(GM_getValue("DF_eligable", 0) == 0)
  1283. {
  1284. return;
  1285. }
  1286.  
  1287. // Get the statid
  1288. var endPos = url.indexOf("&");
  1289. var statid = url.substring(41, endPos > 0 ? endPos : url.length);
  1290.  
  1291. if(!IsNumeric(statid))
  1292. {
  1293. CustomPage(statid);
  1294. return;
  1295. }
  1296.  
  1297. if(document.body.innerHTML.indexOf("Invalid User ID") > 0)
  1298. {
  1299. GM_xmlhttpRequest(
  1300. {
  1301. method: "GET",
  1302. url: DF_server + "backbone.php?code=inactive&whoami=" + DF_username + "&password=" + DF_password + "&whoamid=" + DF_statid + "&userid=" + statid,
  1303. onload: function(r)
  1304. {
  1305. if(r.status == 200)
  1306. {
  1307. if(r.responseText.indexOf("Access Denied") >= 0)
  1308. {
  1309. return;
  1310. }
  1311.  
  1312. if(r.responseText.length > 0)
  1313. {
  1314. var td = GetContentTD();
  1315.  
  1316. td.innerHTML = td.innerHTML.replace("<h3>Error</h3>\nInvalid User ID", r.responseText);
  1317. }
  1318. }
  1319. }
  1320. });
  1321.  
  1322. return;
  1323. }
  1324.  
  1325. var username = GetText(">Name:<", "<td>", "<").trim();
  1326. InteldetailPHP_CalcReconsLeft(username);
  1327. document.getElementsByName('spyrbut')[0].value = "Recon (" + GM_getValue("DF_recon_cnt_" + username, 15) + ")";
  1328.  
  1329. document.addEventListener('click', function(event) {
  1330.  
  1331. if(event.target.value)
  1332. {
  1333.  
  1334. if( event.target.value.length > 5)
  1335. {
  1336. var value = String(event.target.value);
  1337.  
  1338. var p = value.indexOf("Raid");
  1339. if(p)
  1340. {
  1341. document.cookie = "attackType=notRaid;";
  1342. }else{
  1343. document.cookie = "attackType=raid;";
  1344. }
  1345. }
  1346. }
  1347.  
  1348. }, true);
  1349.  
  1350. // Gather user specific information
  1351. var commander = GetText(">Commander:<", "<td>", "</td>");
  1352. if(commander != "None") commander = GetText(">Commander:<", "\">", "<");
  1353.  
  1354. var supreme = GetText(">Supreme Commander", "\">", "<");
  1355. if(supreme == "") supreme = "None";
  1356.  
  1357. var chain = GetText(">Chain Name:", "<td>", "</td>");
  1358. if(chain == "") chain = "None";
  1359.  
  1360. var alliance = GetText(">Alliances:", "<b>", "alliances.php?id=", ">", "<");
  1361. if(alliance == "") alliance = "None";
  1362.  
  1363. var treasury = GetText(">Treasury:", "<td>", "</td>").replace(/,/g, "");
  1364. if(treasury == "") treasury = "???";
  1365.  
  1366. var morale = GetText(">Army Morale:", "<td>", "</td>").replace(/,/g, "");
  1367.  
  1368. var race = GetText(">Race:", "<td>", "</td>");
  1369.  
  1370. var rank = GetText("b>Rank:", "<td>", "</td>").replace(/,/g, "");
  1371.  
  1372. var tff = GetText(">Army Size:", "<td>", "</td>").replace(/,/g, "");
  1373.  
  1374.  
  1375. // Add place holders for additional data, such as treasury, tbg, ...
  1376. var userTable = GetTag('th', "User Stats").parentNode.parentNode;
  1377. var treasuryRow = 0;
  1378. var allianceRow = 0;
  1379.  
  1380. for(i = 0; i < userTable.rows.length; i++)
  1381. {
  1382.  
  1383. if(userTable.rows[i].innerHTML.indexOf("Alliances") >= 0)
  1384. {
  1385. allianceRow = i;
  1386. }
  1387.  
  1388. if(userTable.rows[i].innerHTML.indexOf("Army Morale") >= 0)
  1389. {
  1390. if(treasury == "???")
  1391. {
  1392. treasuryRow = userTable.insertRow(i+1);
  1393.  
  1394. treasuryRow.insertCell(0).innerHTML = "<b>Treasury:</b>";
  1395. treasuryRow.insertCell(1).innerHTML = "Loading...";
  1396. }
  1397.  
  1398. var tbgRow = userTable.insertRow(i+2);
  1399. tbgRow.insertCell(0).innerHTML = "<b>TBG (1h):</b>";
  1400. tbgRow.insertCell(1).innerHTML = AddCommas( Math.floor(tff * 60 * (race == "Dwarves" ? 1.15 : (race == "Humans" ? 1.3 : 1))).toString() );
  1401.  
  1402. break;
  1403. }
  1404. }
  1405.  
  1406. // Add place holders for user's stats
  1407. var th = GetTag('th', "Recent Battles");
  1408. if(!th) th = GetTag('th', "Recent Intelligence");
  1409. if(!th) th = GetTag('th', "Officers");
  1410. if(!th) return;
  1411.  
  1412. var statsTableHtml = "<table width=100% class=table_lines cellspacing=0 cellpadding=6>"
  1413. + "<tr><th colspan=3>" + username + "'s Stats</th></tr>"
  1414. + "<tr><td width=30%><b>Strike Action</b></td><td align=right id=DB_sa width=40%>Loading...</td><td align=right id=DB_saTime>&nbsp;</td></tr>"
  1415. + "<tr><td><b>Defensive Action</b></td><td align=right id=DB_da>Loading...</td><td align=right id=DB_daTime>&nbsp;</td></tr>"
  1416. + "<tr><td><b>Spy Rating</b></td><td align=right id=DB_spy>Loading...</td><td align=right id=DB_spyTime>&nbsp;</td></tr>"
  1417. + "<tr><td><b>Sentry Rating</b></td><td align=right id=DB_sentry>Loading...</td><td align=right id=DB_sentryTime>&nbsp;</td></tr>"
  1418. + "</table><br /><br />";
  1419.  
  1420. var statsPlace = th.parentNode.parentNode.parentNode.parentNode;
  1421. statsPlace.innerHTML = statsTableHtml + statsPlace.innerHTML;
  1422.  
  1423. // Update the database and get details about this target (fill placeholders)
  1424. GM_xmlhttpRequest(
  1425. {
  1426. method: "GET",
  1427. url: DF_server + "backbone.php?code=statspage&whoami=" + DF_username + "&password=" + DF_password + "&whoamid=" + DF_statid + "&username=" + username + "&userid=" + statid + "&commander=" + commander + "&supremecommander=" + supreme + "&chain=" + chain + "&alliance=" + alliance + "&race=" + race + "&gold=" + treasury + "&morale=" + morale + "&rank=" + rank + "&tff=" + tff,
  1428. onload: function(r)
  1429. {
  1430. if(r.status == 200)
  1431. {
  1432.  
  1433. if(r.responseText.indexOf("Access Denied") >= 0)
  1434. {
  1435. return;
  1436. }
  1437.  
  1438. document.getElementById('DB_sa').innerHTML = GetTextIn(r.responseText, "[SA]", "[/SA]");
  1439. document.getElementById('DB_da').innerHTML = GetTextIn(r.responseText, "[DA]", "[/DA]");
  1440. document.getElementById('DB_spy').innerHTML = GetTextIn(r.responseText, "[SPY]", "[/SPY]");
  1441. document.getElementById('DB_sentry').innerHTML = GetTextIn(r.responseText, "[SENTRY]", "[/SENTRY]");
  1442.  
  1443. document.getElementById('DB_saTime').innerHTML = GetTextIn(r.responseText, "[aSA]", "[/aSA]");
  1444. document.getElementById('DB_daTime').innerHTML = GetTextIn(r.responseText, "[aDA]", "[/aDA]");
  1445. document.getElementById('DB_spyTime').innerHTML = GetTextIn(r.responseText, "[aSPY]", "[/aSPY]");
  1446. document.getElementById('DB_sentryTime').innerHTML = GetTextIn(r.responseText, "[aSENTRY]", "[/aSENTRY]");
  1447.  
  1448. var DB_gold = GetTextIn(r.responseText, "[GOLD]", "[/GOLD]");
  1449. var DB_goldTime = GetTextIn(r.responseText, "[aGOLD]", "[/aGOLD]");
  1450.  
  1451. // Update treasury
  1452. if(treasuryRow)
  1453. {
  1454. treasuryRow.cells[1].innerHTML = DB_gold + "<span style=\"margin-left: 20px;\">( " + DB_goldTime + " )</span>";
  1455. }
  1456.  
  1457.  
  1458. // Has alliance title or ap? Then display
  1459. var allianceTitle = GetTextIn(r.responseText, "[TITLE]", "[/TITLE]");
  1460. var alliancePoints = GetTextIn(r.responseText, "[AP]", "[/AP]");
  1461. if(allianceTitle)
  1462. {
  1463. allianceTitleRow = userTable.insertRow(allianceRow+2);
  1464.  
  1465. allianceTitleRow.insertCell(0).innerHTML = "<b>Alliance Title:</b>";
  1466. allianceTitleRow.insertCell(1).innerHTML = allianceTitle + " (" + alliancePoints + ")";
  1467.  
  1468. }
  1469.  
  1470.  
  1471.  
  1472. }
  1473. }
  1474. });
  1475.  
  1476. // Collapse the recent battles and intelligence
  1477. ExpandCollapseTable("Recent Battles");
  1478. ExpandCollapseTable("Recent Intelligence");
  1479.  
  1480. // Remove the ! from make commander button
  1481. var t = GetElement('input', "Make " + username + " my commander!");
  1482. if(t) t.value = "Make " + username + " my commander";
  1483.  
  1484. // Give Send Message button also 2px padding like the Make Commander button has
  1485. var sendMsgButton = GetElement('input', "Send Message");
  1486. if(sendMsgButton) sendMsgButton.style.padding = "2px";
  1487.  
  1488. // Add last message sent
  1489. if(GM_getValue("DF_OptionShowLastMsgSent", 1) == 1)
  1490. {
  1491. var lastMsgRow = GetElement('input', "Send Message").parentNode.parentNode.parentNode.parentNode;
  1492. if(GM_getValue("DF_msg_sent_content_" + username, "") != "") // if has msg sent
  1493. {
  1494. lastMsgRow.innerHTML += "<p style=\"font-size: small; margin-top: -15px\"><a href=\"#\" onClick=\"document.getElementById('PMBox').style.visibility = 'visible'; return false;\">Last Msg: " + AttackPHP_GetLastMsgSent(username) + "</a></p>";
  1495.  
  1496. // Box for showing PM
  1497. var PMBox = document.createElement('div');
  1498. PMBox.setAttribute('id', 'PMBox');
  1499. PMBox.style.visibility = 'hidden';
  1500. PMBox.style.position = 'absolute';
  1501. PMBox.style.left = '0';
  1502. PMBox.style.top = '0';
  1503. PMBox.style.width = '100%';
  1504. PMBox.style.height = window.outerHeight;
  1505. PMBox.style.textAlign = 'center';
  1506. PMBox.style.zIndex = '1000';
  1507. PMBox.style.backgroundColor = ' rgba(0,0,0,.75)';
  1508. PMBox.innerHTML = '<div style="width: 600px; margin: 300px auto; padding: 10px; text-align: center;"> \
  1509. <textarea cols="80" rows="12" style="padding: 10px;">' + GM_getValue("DF_msg_sent_content_" + username, "") + '</textarea><br> \
  1510. <input type="button" onclick="var PMBox = document.getElementById(\'PMBox\'); PMBox.style.visibility = \'hidden\';" value="Close" style="margin-top: 5px; width: 150px; height: 35px; cursor: pointer;"> \
  1511. </div>';
  1512. document.body.appendChild(PMBox);
  1513. }
  1514. else
  1515. {
  1516. lastMsgRow.innerHTML += "<p style=\"font-size: small; margin-top: -15px\">Last Msg: " + AttackPHP_GetLastMsgSent(username) + "</p>";
  1517. }
  1518. }
  1519.  
  1520. // Redesign the user table
  1521. var userTable = GetTag('th', "User Stats").parentNode.parentNode;
  1522.  
  1523. // Shorten supreme commander
  1524. if(userTable.rows[3].cells[0].innerHTML.indexOf("Supreme") >= 0)
  1525. {
  1526. userTable.rows[3].cells[0].innerHTML = "<b>Supreme:</b>";
  1527. }
  1528.  
  1529. // Merge rank and highest rank rows
  1530. var rowId = GetTableRow(userTable, 0, "Rank:");
  1531. if(rowId >= 0)
  1532. {
  1533. userTable.rows[rowId].cells[1].innerHTML += " &nbsp; ( " + userTable.rows[rowId + 1].cells[1].innerHTML + " )";
  1534. userTable.deleteRow(rowId + 1);
  1535. }
  1536.  
  1537. // Merge buddy status and buddy button rows
  1538. var rowId = GetTableRow(userTable, 0, "Buddy");
  1539. if(rowId >= 0)
  1540. {
  1541. var buddyStatus = userTable.rows[rowId].cells[1].innerHTML;
  1542. buddyStatus = buddyStatus.substring(0, buddyStatus.indexOf(">") + 1);
  1543. buddyStatus = buddyStatus.replace(">", ">&nbsp;&nbsp;");
  1544.  
  1545. var buddyForm = userTable.rows[rowId + 1].cells[0].innerHTML.replace("Recognize player as", "");
  1546. userTable.rows[rowId].innerHTML = "<td><b>Buddy Status:</b></td><td style='padding-top:20px;'>" + buddyForm.replace("post\">", "post\">" + buddyStatus) + "</td>";
  1547.  
  1548. userTable.deleteRow(rowId + 1);
  1549. userTable.deleteRow(rowId - 1); // remove the empty row
  1550. }
  1551.  
  1552. // Collapse the alliances except the primary
  1553. var rowId = GetTableRow(userTable, 0, "Alliances");
  1554. if(rowId >= 0)
  1555. {
  1556. var expandedAlliances = userTable.rows[rowId].cells[1].innerHTML;
  1557.  
  1558. var alliances = expandedAlliances.split(",");
  1559. var primaryAlliance = 0;
  1560.  
  1561. for(i = 0; i < alliances.length; i++)
  1562. {
  1563. if(alliances[i].indexOf("(Primary)") >= 0)
  1564. {
  1565. primaryAlliance = alliances[i];
  1566. break;
  1567. }
  1568. }
  1569.  
  1570. if(primaryAlliance)
  1571. {
  1572. userTable.rows[rowId].cells[1].innerHTML = primaryAlliance;
  1573.  
  1574. if(alliances.length > 1)
  1575. {
  1576. userTable.rows[rowId].cells[1].innerHTML += ", <a style=\"cursor:pointer;\" id=showAlliances>(+)</a>";
  1577.  
  1578. document.getElementById('showAlliances').addEventListener('click',
  1579. function()
  1580. {
  1581. this.parentNode.innerHTML = expandedAlliances;
  1582. }, false);
  1583. }
  1584. }
  1585. }
  1586.  
  1587. // Add shortcut to attack, raid, recon and sab
  1588. var listenKeyboard = GM_getValue("DF_OptionKS", 1);
  1589.  
  1590. var shortcuts = userTable.insertRow(1).insertCell(0);
  1591. shortcuts.innerHTML = "<table border=0 cellspacing=0 cellpadding=4 width=100%><tr><td width=25% style=\"border:0\"><button id=sAttack style=\"width:100%\" onClick=\"this.innerHTML = 'Attacking...'; this.disabled = true; document.getElementsByName('attackbut')[0].click();\">Attack" + (listenKeyboard == 0 ? "" : " (k)") + "</button></td>"
  1592. + "<td width=25% style=\"border:0\"><button id=sRaid style=\"width:100%\" onClick=\"this.innerHTML = 'Raiding...'; this.disabled = true; document.getElementsByName('attackbut')[1].click();\">Raid" + (listenKeyboard == 0 ? "" : " (p)") + "</button></td>"
  1593. + "<td width=25% style=\"border:0\"><button id=sRecon value=\"Recon\" style=\"width:100%\" onClick=\"this.innerHTML = 'Reconning...'; this.disabled = true; document.getElementsByName('spyrbut')[0].click();\">Recon" + (listenKeyboard == 0 ? "" : " (r)") + "</button></td>"
  1594. + "<td width=25% style=\"border:0\"><button id=sSab style=\"width:100%\" onClick=\"window.location = 'attack.php?id=" + statid + "#sab' \">Sabotage" + (listenKeyboard == 0 ? "" : " (s)") + "</button></td></tr></table>";
  1595.  
  1596. shortcuts.setAttribute('colspan', 2);
  1597. }
  1598.  
  1599. function InteldetailPHP()
  1600. {
  1601. if(GM_getValue("DF_eligable", 0) == 0)
  1602. {
  1603. return;
  1604. }
  1605.  
  1606. var doc = document.body.innerHTML;
  1607.  
  1608. var listenKeyboard = GM_getValue("DF_OptionKS", 1);
  1609.  
  1610. if(doc.indexOf("Your Chief of Intelligence dispatches") >= 0) // Sab
  1611. {
  1612. if(doc.indexOf("armory undetected,") >= 0) // Sab got through
  1613. {
  1614. var reportId = url.substring(54, url.length);
  1615. var sabbee = GetText("Your spies successfully enter ", "'s");
  1616. var weapon = GetText("attempt to sabotage", "weapons of type ", ".");
  1617. var amount = GetText("and destroy ", " of the ").replace(/,/g, "");
  1618. if(amount == "") amount = 0;
  1619.  
  1620. // Place holder for the logging
  1621. var but = GetElement('input', "Attack / Spy Again");
  1622. but.parentNode.innerHTML = but.parentNode.innerHTML + "<span id=logSab style=\"margin-left: 20px;\">Logging your sab...</span>";
  1623.  
  1624. GM_xmlhttpRequest(
  1625. {
  1626. method: "GET",
  1627. url: DF_server + "backbone.php?code=logsabs&whoami=" + DF_username + "&whoamid=" + DF_statid + "&password=" + DF_password + "&target=" + sabbee + "&weapon=" + weapon + "&amount=" + amount + "&rid=" + reportId,
  1628. onload: function(r)
  1629. {
  1630. if(r.status == 200)
  1631. {
  1632. document.getElementById('logSab').innerHTML = r.responseText;
  1633. }
  1634. }
  1635. });
  1636. }
  1637. else // Sab failed
  1638. {
  1639.  
  1640. }
  1641.  
  1642. }
  1643. else // Recon
  1644. {
  1645. if(doc.indexOf("with the information gathered") >= 0)
  1646. {
  1647. // Record recon
  1648. var reportId = url.substring(54, url.length);
  1649. var username = GetText("your spy sneaks into ", "'s camp");
  1650. var sa = GetText(">Strike Action:<", "\">", "<").replace(/,/g, "");
  1651. var da = GetText(">Defensive Action<", "\">", "<").replace(/,/g, "");
  1652. var spy = GetText(">Spy Rating<", "\">", "<").replace(/,/g, "");
  1653. var sentry = GetText(">Sentry Rating<", "\">", "<").replace(/,/g, "");
  1654. var coverts = GetText(">Covert Operatives:<", "\">", "<").replace(/,/g, "");
  1655. var turns = GetText(">Attack Turns:<", "\">", "<").replace(/,/g, "");
  1656. var treasury = GetText(">Treasury<", "\">", "<").replace(/,/g, "").replace(" Gold", "");
  1657. var statid = GetText("name=\"id\" value=\"", "\"");
  1658.  
  1659. // Reduce one recon count
  1660. AttackPHP_SetReconCnt(username);
  1661.  
  1662. var soldiers = GetText("<td>Soldiers</td>","</tr>").match(/[^><]+?(?=<|$)/g,"");
  1663. var sa_sol = soldiers[1];
  1664. var da_sol = soldiers[3];
  1665. var untrained = soldiers[5];
  1666.  
  1667. var table = GetTag('th', "Weapons").parentNode.parentNode;
  1668.  
  1669. var BPM = "???";
  1670. var IS = "???";
  1671. var DS = "???";
  1672. var CHR = "???";
  1673. var NUN = "???";
  1674. var LT = "???";
  1675. var SK = "???";
  1676. var GD = "???";
  1677. var GH = "???";
  1678. var TW = "???";
  1679. var CK = "???";
  1680.  
  1681. for(i = 2; i < table.rows.length; i++)
  1682. {
  1683. if(table.rows[i].cells.length < 4) continue;
  1684.  
  1685. var wepName = table.rows[i].cells[0].innerHTML;
  1686. var wepType = table.rows[i].cells[1].innerHTML;
  1687. var wepCount = table.rows[i].cells[2].innerHTML.replace(/,/g, "");
  1688. var wepStrength = table.rows[i].cells[3].innerHTML.replace(/,/g, "");
  1689. wepStrength = wepStrength.substring(wepStrength.indexOf("/") + 1, wepStrength.length);
  1690. if(wepStrength == "???") wepStrength = table.rows[i].cells[3].innerHTML.replace(/,/g, "").split("/")[0];
  1691.  
  1692. if(wepCount == "???") continue;
  1693.  
  1694. // Find the weapon directly from its name
  1695. if(wepName == "Blackpowder Missile")
  1696. {
  1697. BPM = wepCount;
  1698. }
  1699. else if(wepName == "Invisibility Shield")
  1700. {
  1701. IS = wepCount;
  1702. }
  1703. else if(wepName == "Dragonskin")
  1704. {
  1705. DS = wepCount;
  1706. }
  1707. else if(wepName == "Chariot")
  1708. {
  1709. CHR = wepCount;
  1710. }
  1711. else if(wepName == "Nunchaku")
  1712. {
  1713. NUN = wepCount;
  1714. }
  1715. else if(wepName == "Lookout Tower")
  1716. {
  1717. LT = wepCount;
  1718. }
  1719. else if(wepName == "Skeleton Key")
  1720. {
  1721. SK = wepCount;
  1722. }
  1723. else if(wepName == "Guard Dog")
  1724. {
  1725. GD = wepCount;
  1726. }
  1727. else if(wepName == "Grappling Hook")
  1728. {
  1729. GH = wepCount;
  1730. }
  1731. else if(wepName == "Tripwire")
  1732. {
  1733. TW = wepCount;
  1734. }
  1735. else if(wepName == "Cloak")
  1736. {
  1737. CK = wepCount;
  1738. }
  1739.  
  1740. // Find the weapon using type + strength
  1741. if(wepType == "Attack" && wepStrength == "1000")
  1742. {
  1743. BPM = wepCount;
  1744. }
  1745. else if(wepType == "Attack" && wepStrength == "600")
  1746. {
  1747. CHR = wepCount;
  1748. }
  1749. if(wepType == "Defend" && wepStrength == "1000")
  1750. {
  1751. IS = wepCount;
  1752. }
  1753. if(wepType == "Defend" && wepStrength == "256")
  1754. {
  1755. DS = wepCount;
  1756. }
  1757. if(wepType == "Spy" && wepStrength == "1000")
  1758. {
  1759. NUN = wepCount;
  1760. }
  1761. if(wepType == "Sentry" && wepStrength == "1000")
  1762. {
  1763. LT = wepCount;
  1764. }
  1765. if(wepType == "Spy" && wepStrength == "600")
  1766. {
  1767. SK = wepCount;
  1768. }
  1769. if(wepType == "Sentry" && wepStrength == "250")
  1770. {
  1771. GD = wepCount;
  1772. }
  1773. if(wepType == "Spy" && wepStrength == "250")
  1774. {
  1775. GH = wepCount;
  1776. }
  1777. if(wepType == "Sentry" && wepStrength == "140")
  1778. {
  1779. TW = wepCount;
  1780. }
  1781. if(wepType == "Spy" && wepStrength == "140")
  1782. {
  1783. CK = wepCount;
  1784. }
  1785. }
  1786.  
  1787. var weapons = "[bpm]" + BPM + "[/bpm][is]" + IS + "[/is][nun]" + NUN + "[/nun][lt]" + LT + "[/lt][ch]" + CHR + "[/ch][ds]" + DS + "[/ds][sk]" + SK + "[/sk][gd]" + GD + "[/gd][gh]" + GH + "[/gh][tw]" + TW + "[/tw][ck]" + CK + "[/ck]";
  1788.  
  1789. // Place holder for the logging
  1790. var th = GetTag('th', "Treasury");
  1791. th.parentNode.parentNode.innerHTML += "<tr><td></td></tr><tr><td style='padding-left: 4ex; border-bottom:0'><a href=attack.php?id=" + statid + "><button>Attack / Spy Again" + (listenKeyboard == 0 ? "" : " (rs)") + "</button></a><span id=logRecon style=\"margin-left: 20px;\">Logging your recon...</span></td></tr>";
  1792.  
  1793. GM_xmlhttpRequest(
  1794. {
  1795. method: "GET",
  1796. url: DF_server + "backbone.php?code=reconpage&whoami=" + DF_username + "&password=" + DF_password + "&whoamid=" + DF_statid + "&username=" + username + "&sa=" + sa + "&da=" + da + "&spy=" + spy + "&sentry=" + sentry + "&userid=" + statid + "&gold=" + treasury + "&coverts=" + coverts + "&turns=" + turns + "&weapons=" + weapons + "&untrained=" + untrained + "&rid=" + reportId,
  1797. onload: function(r)
  1798. {
  1799. if(r.status == 200)
  1800. {
  1801. document.getElementById('logRecon').innerHTML = r.responseText;
  1802. }
  1803. }
  1804. });
  1805. }
  1806. else // Recon Failed
  1807. {
  1808. var username = GetText("your spy sneaks into ", "'s camp");
  1809. AttackPHP_SetReconCnt(username);
  1810.  
  1811. }
  1812. }
  1813. }
  1814.  
  1815. function ConquestPHP()
  1816. {
  1817. if(GM_getValue("DF_eligable", 0) == 0)
  1818. {
  1819. return;
  1820. }
  1821. }
  1822.  
  1823. function AttackPHP()
  1824. {
  1825.  
  1826. if(GM_getValue("DF_eligable", 0) == 0)
  1827. {
  1828. return;
  1829. }
  1830.  
  1831. var doc = document.body.innerHTML;
  1832.  
  1833. // Get the statid
  1834. var endPos = url.indexOf("&");
  1835. var statid = url.substring(42, endPos > 0 ? endPos : url.length);
  1836.  
  1837. if(document.body.innerHTML.indexOf("Invalid User ID") > 0)
  1838. {
  1839. GM_xmlhttpRequest(
  1840. {
  1841. method: "GET",
  1842. url: DF_server + "backbone.php?code=inactive&whoami=" + DF_username + "&password=" + DF_password + "&whoamid=" + DF_statid + "&userid=" + statid,
  1843. onload: function(r)
  1844. {
  1845. if(r.status == 200)
  1846. {
  1847. if(r.responseText.indexOf("Access Denied") >= 0)
  1848. {
  1849. return;
  1850. }
  1851.  
  1852. if(r.responseText.length > 0)
  1853. {
  1854. var td = GetContentTD();
  1855.  
  1856. td.innerHTML = td.innerHTML.replace("<h3>Error</h3>\nInvalid User ID", r.responseText);
  1857. }
  1858. }
  1859. }
  1860. });
  1861.  
  1862. return;
  1863. }
  1864.  
  1865. var username = GetText("Target:", "\">", "<");
  1866. if(username == "") return;
  1867.  
  1868. var statid = GetText("Target:", "id=", "\">");
  1869. if(statid == "") return;
  1870.  
  1871. if(doc.indexOf("You can recon a player only 15 times") > 0)
  1872. {
  1873. GM_setValue("DF_recon_cnt_" + username, 0);
  1874. }
  1875.  
  1876. document.addEventListener('click', function(event) {
  1877. if(event.target.value)
  1878. {
  1879. var value = String(event.target.value);
  1880.  
  1881. var p = value.indexOf("Raid");
  1882.  
  1883. if(p)
  1884. {
  1885. document.cookie = "attackType=notRaid;";
  1886. }else{
  1887. document.cookie = "attackType=raid;";
  1888. }
  1889. }
  1890.  
  1891. }, true);
  1892.  
  1893. // Add how many recons left on target
  1894. InteldetailPHP_CalcReconsLeft(username);
  1895. document.getElementsByName('spyrbut')[0].value = "Recon (" + GM_getValue("DF_recon_cnt_" + username, 15) + ")";
  1896.  
  1897. // Fix the width of Target: to display the target's name properly
  1898. var t = GetTag('th', "Attack Mission");
  1899. if(t)
  1900. {
  1901. var table = t.parentNode.parentNode;
  1902. table.rows[1].cells[0].width = '50%';
  1903. }
  1904.  
  1905. // Add another sab button and change the original sab button to 'sab' instead of 'send spies'
  1906. var th = GetTag('th', "Sabotage Mission");
  1907. if(th) th.parentNode.parentNode.insertRow(1).innerHTML = "<td colspan=2 align=center><input name=spybut0 onclick=\"document.spy.spybut0.value='Sabotaging..'; document.spy.spybut0.disabled=true; document.spy.submit();\" type=submit value=\"Sab!\"></td>";
  1908. document.getElementsByName('spybut')[0].value = "Sab!";
  1909.  
  1910. if(doc.indexOf("has already suffered heavy losses") >= 0)
  1911. {
  1912. GM_xmlhttpRequest(
  1913. {
  1914. method: "GET",
  1915. url: DF_server + "backbone.php?code=maxed&whoami=" + DF_username + "&whoamid=" + DF_statid + "&password=" + DF_password + "&target=" + username
  1916. });
  1917. }
  1918.  
  1919. // Put an additional +1 / +5 button next to the weapon amount in sab form
  1920. document.getElementsByName('numsab')[0].parentNode.innerHTML += "<button style=\"margin-left: 20px;\" onClick=\"document.spy.numsab.value = parseInt(document.spy.numsab.value, 10) + 1; return false;\">+1</button>"
  1921. + "<button style=\"margin-left: 20px;\" onClick=\"document.spy.numsab.value = parseInt(document.spy.numsab.value, 10) + 5; return false;\">+5</button>";
  1922.  
  1923. // Put an additional +1 button next to the number of spies
  1924. document.getElementsByName('numspies')[0].parentNode.innerHTML += "<button style=\"margin-left: 20px;\" onClick=\"document.spy.numspies.value = parseInt(document.spy.numspies.value, 10) + 1; return false;\">+1</button>";
  1925.  
  1926. // Add place holders for user's stats and move your stats above the personnel table
  1927. var th = GetTag('th', "<span ");
  1928. var statsPlace = th.parentNode.parentNode.parentNode.parentNode;
  1929.  
  1930. var statsTableHtml = "<table width=100% class=table_lines cellspacing=0 cellpadding=6>"
  1931. + "<tr><th colspan=3>" + username + "'s Stats</th></tr>"
  1932. + "<tr><td width=30%><b>Strike Action</b></td><td align=right id=DB_sa width=40%>Loading...</td><td align=right id=DB_saTime>&nbsp;</td></tr>"
  1933. + "<tr><td><b>Defensive Action</b></td><td align=right id=DB_da>Loading...</td><td align=right id=DB_daTime>&nbsp;</td></tr>"
  1934. + "<tr><td><b>Spy Rating</b></td><td align=right id=DB_spy>Loading...</td><td align=right id=DB_spyTime>&nbsp;</td></tr>"
  1935. + "<tr><td><b>Sentry Rating</b></td><td align=right id=DB_sentry>Loading...</td><td align=right id=DB_sentryTime>&nbsp;</td></tr>"
  1936. + "<tr style='background-color:#111100;'><td><b>Recent Gold</b></td><td align=right id=DB_gold>Loading...</td><td align=right id=DB_goldTime>&nbsp;</td></tr>"
  1937. + "</table><br /><br />";
  1938.  
  1939. var inventoryTableHtml = "<table width=100% class=table_lines border=0 cellspacing=0 cellpadding=6>"
  1940. + "<tr><th colspan=5>" + username + "'s Inventory</th></tr>"
  1941. + "<tr><th class=subh width=30%>Weapon</th><th class=subh colspan=2>Quantity</th><th class=subh width=20%>AAT</th><th class=subh width=1%>&nbsp;</th></tr>"
  1942. + "<tr><td>Blackpowder Missile</td><td align=right id=DB_bpm>Loading...</td><td left=right id=DB_bpmTime>&nbsp;</td><td align=center id=DB_bpmAat>Loading...</td><td><button weapon=bpm name=removeWeapon>X</button></td>"
  1943. + "<tr><td>Chariot</td><td align=right id=DB_ch>Loading...</td><td align=left id=DB_chTime>&nbsp;</td><td align=center id=DB_chAat>Loading...</td><td><button weapon=chr name=removeWeapon>X</button></td>"
  1944. + "<tr><td>Invisibility Shield</td><td align=right id=DB_is>Loading...</td><td align=left id=DB_isTime>&nbsp;</td><td align=center id=DB_isAat>Loading...</td><td><button weapon=ivs name=removeWeapon>X</button></td>"
  1945. + "<tr><td>Dragonskin</td><td align=right id=DB_ds>Loading...</td><td align=left id=DB_dsTime>&nbsp;</td><td align=center id=DB_dsAat>Loading...</td><td><button weapon=ds name=removeWeapon>X</button></td>"
  1946. + "<tr><td>Nunchaku</td><td align=right id=DB_nun>Loading...</td><td align=left id=DB_nunTime>&nbsp;</td><td align=center id=DB_nunAat>Loading...</td><td><button weapon=nun name=removeWeapon>X</button></td>"
  1947. + "<tr><td>Lookout Tower</td><td align=right id=DB_lt>Loading...</td><td align=left id=DB_ltTime>&nbsp;</td><td align=center id=DB_ltAat>Loading...</td><td><button weapon=lt name=removeWeapon>X</button></td>"
  1948. + "<tr><td>Skeleton Key</td><td align=right id=DB_sk>Loading...</td><td align=left id=DB_skTime>&nbsp;</td><td align=center id=DB_skAat>Loading...</td><td><button weapon=sk name=removeWeapon>X</button></td>"
  1949. + "<tr><td>Guard Dog</td><td align=right id=DB_gd>Loading...</td><td align=left id=DB_gdTime>&nbsp;</td><td align=center id=DB_gdAat>Loading...</td><td><button weapon=gd name=removeWeapon>X</button></td>"
  1950. + "<tr><td>Grappling Hook</td><td align=right id=DB_gh>Loading...</td><td align=left id=DB_ghTime>&nbsp;</td><td align=center id=DB_ghAat>Loading...</td><td><button weapon=gh name=removeWeapon>X</button></td>"
  1951. + "<tr><td>Tripwire</td><td align=right id=DB_tw>Loading...</td><td align=left id=DB_twTime>&nbsp;</td><td align=center id=DB_twAat>Loading...</td><td><button weapon=tw name=removeWeapon>X</button></td>"
  1952. + "<tr><td>Cloak</td><td align=right id=DB_ck>Loading...</td><td align=left id=DB_ckTime>&nbsp;</td><td align=center id=DB_ckAat>Loading...</td><td><button weapon=ck name=removeWeapon>X</button></td>"
  1953. + "</table>";
  1954.  
  1955.  
  1956. // Remove the Personnel table, which is useless
  1957. var personnelTableHtml = GetTag('th', "<span").parentNode.parentNode.innerHTML;
  1958. statsPlace.innerHTML = statsPlace.innerHTML.replace(personnelTableHtml, "<br>");
  1959.  
  1960. statsPlace.innerHTML = statsTableHtml + inventoryTableHtml + statsPlace.innerHTML;
  1961.  
  1962.  
  1963. // Add place holders for the target's inventory and the last sab
  1964. var sabotageTable = GetTag('th', "Sabotage Mission").parentNode.parentNode;
  1965.  
  1966. var lastSabRow = sabotageTable.insertRow(sabotageTable.rows.length - 1);
  1967. lastSabRow.insertCell(0).innerHTML = "Last Sab";
  1968. lastSabRow.insertCell(1).innerHTML = "Loading...";
  1969. lastSabRow.cells[0].width = "50%";
  1970.  
  1971. // Add Message Button
  1972. if(GM_getValue("DF_OptionShowLastMsgSent", 1) == 1)
  1973. {
  1974. var lastMsgRow = sabotageTable.insertRow(sabotageTable.rows.length);
  1975. lastMsgRow.insertCell(0).innerHTML = '<button onclick=\"window.location = \'http://www.kingsofchaos.com/writemail.php?to=' + statid + '\'; return false;\">Send Message</button>';
  1976. if(GM_getValue("DF_msg_sent_content_" + username, "") != "") // if has msg sent
  1977. {
  1978. lastMsgRow.insertCell(1).innerHTML = "<a href=\"#\" onClick=\"document.getElementById('PMBox').style.visibility = 'visible'; return false;\">Last Msg: " + AttackPHP_GetLastMsgSent(username) + "</a>";
  1979.  
  1980. // Box for showing PM
  1981. var PMBox = document.createElement('div');
  1982. PMBox.setAttribute('id', 'PMBox');
  1983. PMBox.style.visibility = 'hidden';
  1984. PMBox.style.position = 'absolute';
  1985. PMBox.style.left = '0';
  1986. PMBox.style.top = '0';
  1987. PMBox.style.width = '100%';
  1988. PMBox.style.height = window.outerHeight;
  1989. PMBox.style.textAlign = 'center';
  1990. PMBox.style.zIndex = '1000';
  1991. PMBox.style.backgroundColor = ' rgba(0,0,0,.75)';
  1992. PMBox.innerHTML = '<div style="width: 600px; margin: 300px auto; padding: 10px; text-align: center;"> \
  1993. <textarea cols="80" rows="12" disabled="disabled" style="padding: 10px;">' + GM_getValue("DF_msg_sent_content_" + username, "") + '</textarea><br> \
  1994. <input type="button" onclick="var PMBox = document.getElementById(\'PMBox\'); PMBox.style.visibility = \'hidden\';" value="Close" style="margin-top: 5px; width: 150px; height: 35px; cursor: pointer;"> \
  1995. </div>';
  1996. document.body.appendChild(PMBox);
  1997. }
  1998. else
  1999. {
  2000. lastMsgRow.insertCell(1).innerHTML = 'Last Msg: ' + AttackPHP_GetLastMsgSent(username);
  2001. }
  2002.  
  2003. lastMsgRow.cells[0].width = "50%";
  2004. }
  2005.  
  2006. // Does the script remembers your sab options? If not, last sab will be taken as the option
  2007. var sabRemember = false;
  2008.  
  2009. // Show additional information about the target
  2010. GM_xmlhttpRequest(
  2011. {
  2012. method: "GET",
  2013. url: DF_server + "backbone.php?code=aat2&whoami=" + DF_username + "&password=" + DF_password + "&whoamid=" + DF_statid + "&username=" + username,
  2014. onload: function(r)
  2015. {
  2016. if(r.status == 200)
  2017. {
  2018.  
  2019. document.getElementById('DB_sa').innerHTML = GetTextIn(r.responseText, "[SA]", "[/SA]");
  2020. document.getElementById('DB_da').innerHTML = GetTextIn(r.responseText, "[DA]", "[/DA]");
  2021. document.getElementById('DB_spy').innerHTML = GetTextIn(r.responseText, "[SPY]", "[/SPY]");
  2022. document.getElementById('DB_sentry').innerHTML = GetTextIn(r.responseText, "[SENTRY]", "[/SENTRY]");
  2023.  
  2024. document.getElementById('DB_saTime').innerHTML = GetTextIn(r.responseText, "[tSA]", "[/tSA]");
  2025. document.getElementById('DB_daTime').innerHTML = GetTextIn(r.responseText, "[tDA]", "[/tDA]");
  2026. document.getElementById('DB_spyTime').innerHTML = GetTextIn(r.responseText, "[tSPY]", "[/tSPY]");
  2027. document.getElementById('DB_sentryTime').innerHTML = GetTextIn(r.responseText, "[tSENTRY]", "[/tSENTRY]");
  2028.  
  2029. document.getElementById('DB_gold').innerHTML = GetTextIn(r.responseText, "[GOLD]", "[/GOLD]");
  2030. document.getElementById('DB_goldTime').innerHTML = GetTextIn(r.responseText, "[tGOLD]", "[/tGOLD]");
  2031.  
  2032. var lastSabber = GetTextIn(r.responseText, "[uSAB]", "[/uSAB]");
  2033. var lastWep = GetTextIn(r.responseText, "[bSAB]", "[/bSAB]");
  2034.  
  2035. lastSabRow.cells[0].innerHTML += "&nbsp;&nbsp;" + GetTextIn(r.responseText, "[tSAB]", "[/tSAB]");
  2036. lastSabRow.cells[1].innerHTML = (lastWep == "" ? "Never" : lastWep + "&nbsp;&nbsp;&nbsp;by " + lastSabber);
  2037.  
  2038. document.getElementById('DB_bpm').innerHTML = GetTextIn(r.responseText, "[BPM]", "[/BPM]");
  2039. document.getElementById('DB_ch').innerHTML = GetTextIn(r.responseText, "[CH]", "[/CH]");
  2040. document.getElementById('DB_is').innerHTML = GetTextIn(r.responseText, "[IS]", "[/IS]");
  2041. document.getElementById('DB_ds').innerHTML = GetTextIn(r.responseText, "[DS]", "[/DS]");
  2042. document.getElementById('DB_nun').innerHTML = GetTextIn(r.responseText, "[NUN]", "[/NUN]");
  2043. document.getElementById('DB_lt').innerHTML = GetTextIn(r.responseText, "[LT]", "[/LT]");
  2044. document.getElementById('DB_sk').innerHTML = GetTextIn(r.responseText, "[SK]", "[/SK]");
  2045. document.getElementById('DB_gd').innerHTML = GetTextIn(r.responseText, "[GD]", "[/GD]");
  2046. document.getElementById('DB_gh').innerHTML = GetTextIn(r.responseText, "[GH]", "[/GH]");
  2047. document.getElementById('DB_tw').innerHTML = GetTextIn(r.responseText, "[TW]", "[/TW]");
  2048. document.getElementById('DB_ck').innerHTML = GetTextIn(r.responseText, "[CK]", "[/CK]");
  2049.  
  2050. document.getElementById('DB_bpmTime').innerHTML = GetTextIn(r.responseText, "[tBPM]", "[/tBPM]");
  2051. document.getElementById('DB_chTime').innerHTML = GetTextIn(r.responseText, "[tCH]", "[/tCH]");
  2052. document.getElementById('DB_isTime').innerHTML = GetTextIn(r.responseText, "[tIS]", "[/tIS]");
  2053. document.getElementById('DB_dsTime').innerHTML = GetTextIn(r.responseText, "[tDS]", "[/tDS]");
  2054. document.getElementById('DB_nunTime').innerHTML = GetTextIn(r.responseText, "[tNUN]", "[/tNUN]");
  2055. document.getElementById('DB_ltTime').innerHTML = GetTextIn(r.responseText, "[tLT]", "[/tLT]");
  2056. document.getElementById('DB_skTime').innerHTML = GetTextIn(r.responseText, "[tSK]", "[/tSK]");
  2057. document.getElementById('DB_gdTime').innerHTML = GetTextIn(r.responseText, "[tGD]", "[/tGD]");
  2058. document.getElementById('DB_ghTime').innerHTML = GetTextIn(r.responseText, "[tGH]", "[/tGH]");
  2059. document.getElementById('DB_twTime').innerHTML = GetTextIn(r.responseText, "[tTW]", "[/tTW]");
  2060. document.getElementById('DB_ckTime').innerHTML = GetTextIn(r.responseText, "[tCK]", "[/tCK]");
  2061.  
  2062. document.getElementById('DB_bpmAat').innerHTML = GetTextIn(r.responseText, "[bBPM]", "[/bBPM]");
  2063. document.getElementById('DB_chAat').innerHTML = GetTextIn(r.responseText, "[bCH]", "[/bCH]");
  2064. document.getElementById('DB_isAat').innerHTML = GetTextIn(r.responseText, "[bIS]", "[/bIS]");
  2065. document.getElementById('DB_dsAat').innerHTML = GetTextIn(r.responseText, "[bDS]", "[/bDS]");
  2066. document.getElementById('DB_nunAat').innerHTML = GetTextIn(r.responseText, "[bNUN]", "[/bNUN]");
  2067. document.getElementById('DB_ltAat').innerHTML = GetTextIn(r.responseText, "[bLT]", "[/bLT]");
  2068. document.getElementById('DB_skAat').innerHTML = GetTextIn(r.responseText, "[bSK]", "[/bSK]");
  2069. document.getElementById('DB_gdAat').innerHTML = GetTextIn(r.responseText, "[bGD]", "[/bGD]");
  2070. document.getElementById('DB_ghAat').innerHTML = GetTextIn(r.responseText, "[bGH]", "[/bGH]");
  2071. document.getElementById('DB_twAat').innerHTML = GetTextIn(r.responseText, "[bTW]", "[/bTW]");
  2072. document.getElementById('DB_ckAat').innerHTML = GetTextIn(r.responseText, "[bCK]", "[/bCK]");
  2073.  
  2074. // Update button meanings in the inventory table
  2075. var aatButtons = document.getElementsByName("aatButton");
  2076.  
  2077. for(i = 0; i < aatButtons.length; i++)
  2078. {
  2079. aatButtons[i].addEventListener('click', function()
  2080. {
  2081. document.getElementsByTagName('select')[0].value = GetText("label=\"" + this.getAttribute("weapon").trim() + "\"", "value=\"", "\"");
  2082. document.getElementsByName('numsab')[0].value = parseInt(this.innerHTML.replace(/,/g, ""));
  2083.  
  2084. }, false);
  2085.  
  2086. if(i == 0) // skip the last sabber button
  2087. continue;
  2088.  
  2089. aatButtons[i].style.width = "80%";
  2090. }
  2091.  
  2092.  
  2093. // If the script cannot remember the sab options agains this opponent, take the last sab
  2094. if(!sabRemember)
  2095. {
  2096. if(aatButtons.length == 7) // if there is a last sab
  2097. {
  2098. aatButtons[0].click();
  2099. }
  2100. else // if there is no last sab, take LT/BROKENSTICK aat
  2101. {
  2102. //document.getElementsByTagName('select')[0].value = 69;
  2103. //document.getElementsByName('numsab')[0].value = 1;
  2104. aatButtons[5].click();
  2105. }
  2106. }
  2107.  
  2108.  
  2109. // Remove Weapons buttons
  2110. var removeButtons = document.getElementsByName("removeWeapon");
  2111.  
  2112. for(i = 0; i < removeButtons.length; i++)
  2113. {
  2114. removeButtons[i].addEventListener('click', function()
  2115. {
  2116. GM_xmlhttpRequest(
  2117. {
  2118. method: "POST",
  2119. url: DF_server + "backbone.php",
  2120. headers: { 'Content-type' : 'application/x-www-form-urlencoded' },
  2121. data: encodeURI("code=removeWeapon&whoami=" + DF_username + "&password=" + DF_password + "&whoamid=" + DF_statid + "&target=" + username + "&weapon=" + this.getAttribute("weapon")),
  2122. onload: function(r)
  2123. {
  2124.  
  2125. if(r.status != 200) return;
  2126. location.reload(true);
  2127. }
  2128. });
  2129. }, false);
  2130. }
  2131. }
  2132. }
  2133. });
  2134.  
  2135. // Remember sabotage settings for this target
  2136. document.getElementsByTagName('select')[0].value = GM_getValue("DF_sab_wep_" + username, 69);
  2137. document.getElementsByName('numsab')[0].value = GM_getValue("DF_sab_cnt_" + username, 1);
  2138. document.getElementsByName('numspies')[0].value = GM_getValue("DF_sab_spies_" + username, 1);
  2139. document.getElementsByTagName('select')[1].value = GM_getValue("DF_sab_turns_" + username, 5);
  2140.  
  2141. sabRemember = (GM_getValue("DF_sab_wep_" + username, -1) != -1);
  2142.  
  2143. // Lower aat if cannot get through
  2144. if(document.body.innerHTML.indexOf("you will never be able to get away") > 0)
  2145. {
  2146. if(document.getElementsByName('numsab')[0].value > 0)
  2147. {
  2148. document.getElementsByName('numsab')[0].value -= 1;
  2149. }
  2150. }
  2151.  
  2152. // Listen the sab form
  2153. document.getElementsByTagName('form')[2].addEventListener('submit', function() { AttackPHP_OnSubmitSab(username); }, false);
  2154. }
  2155.  
  2156. function BattlefieldPHP()
  2157. {
  2158. if(GM_getValue("DF_eligable", 0) == 0)
  2159. {
  2160. return;
  2161. }
  2162.  
  2163. // Disable ajax navigation on koc
  2164. GetContentTD().innerHTML = GetContentTD().innerHTML;
  2165.  
  2166. // Find the bf table
  2167. var tables = document.getElementsByClassName("table_lines battlefield");
  2168. if(tables.length == 0) return;
  2169.  
  2170. bfTable = tables[0];
  2171.  
  2172. // Add next and back buttons at top
  2173. if(bfTable.rows.length > 11)
  2174. {
  2175. bfTable.insertRow(1).innerHTML = bfTable.rows[bfTable.rows.length - 1].innerHTML;
  2176. bfTable.rows[1].style.backgroundColor = "#222222";
  2177. }
  2178. bfTable.rows[bfTable.rows.length - 1].style.backgroundColor = "#222222";
  2179.  
  2180. // Dont let the alliance column dominate
  2181. bfTable.rows[0].cells[1].width = "15%";
  2182.  
  2183. // Log bf gold
  2184. var logList = "";
  2185.  
  2186. for(var i = 0; i < bfTable.rows.length; i++)
  2187. {
  2188. if(bfTable.rows[i].cells.length != 7) continue;
  2189.  
  2190. var usernameInner = bfTable.rows[i].cells[2].innerHTML;
  2191. var username = GetTextIn(usernameInner, ">", "<");
  2192. var statid = GetTextIn(usernameInner, "id=", "\"");
  2193.  
  2194. var tff = bfTable.rows[i].cells[3].innerHTML.replace(/,/g, "");
  2195. var race = bfTable.rows[i].cells[4].innerHTML.trim();
  2196. var treasury = bfTable.rows[i].cells[5].innerHTML.replace(/,/g, "").replace(" Gold", "");
  2197. var rank = bfTable.rows[i].cells[6].innerHTML.replace(/,/g, "");
  2198.  
  2199. logList += "#username=" + username + "*gold=" + treasury + "*tff=" + tff + "*userid=" + statid + "*rank=" + rank + "*race=" + race;
  2200.  
  2201. // Also make username links open in new tab
  2202. bfTable.rows[i].cells[2].innerHTML = bfTable.rows[i].cells[2].innerHTML.replace("href=", "target=_blank href=");
  2203. }
  2204.  
  2205. var statDiv = document.createElement('div');
  2206. statDiv.setAttribute('id', "statDiv");
  2207. statDiv.setAttribute('style', "text-align:center; position:fixed; right:10px; bottom:10px; width:15ex; border:1px solid gray; background-color:black; color:white; font-size:10pt;");
  2208. statDiv.innerHTML = "Loading...";
  2209. document.body.appendChild(statDiv);
  2210.  
  2211. GM_xmlhttpRequest(
  2212. {
  2213. method: "POST",
  2214. url: DF_server + "backbone.php",
  2215. headers: { 'Content-type' : 'application/x-www-form-urlencoded' },
  2216. data: encodeURI("code=logbattlefield&whoami=" + DF_username + "&password=" + DF_password + "&whoamid=" + DF_statid + "&fill=" + GM_getValue("DF_fillBattlefield", 1) + "&list=" + logList),
  2217. onload: function(r)
  2218. {
  2219.  
  2220. if(r.status != 200) return;
  2221.  
  2222. if(GM_getValue("DF_fillBattlefield", 1) != 1) return;
  2223.  
  2224. document.getElementById('statDiv').innerHTML = "Loaded!";
  2225.  
  2226. for(var i = 0; i < bfTable.rows.length; i++)
  2227. {
  2228. if(bfTable.rows[i].cells.length != 7) continue;
  2229.  
  2230. var username = GetTextIn(bfTable.rows[i].cells[2].innerHTML, ">", "<");
  2231. var data = GetTextIn(r.responseText, "[" + username + "]", "[/" + username + "]");
  2232.  
  2233. if(data == "") continue;
  2234.  
  2235. if(bfTable.rows[i].cells[5].innerHTML == "??? Gold")
  2236. {
  2237. bfTable.rows[i].cells[5].innerHTML = GetTextIn(data, "[aGOLD]", "[/aGOLD]") + " &nbsp <span style='color:yellow'>" + GetTextIn(data, "[GOLD]", "[/GOLD]") + "</span> Gold";
  2238. }
  2239.  
  2240. var sa = GetTextIn(data, "[SA]", "[/SA]");
  2241. var da = GetTextIn(data, "[DA]", "[/DA]");
  2242. var spy = GetTextIn(data, "[SPY]", "[/SPY]");
  2243. var sentry = GetTextIn(data, "[SENTRY]", "[/SENTRY]");
  2244.  
  2245. var saTime = GetTextIn(data, "[aSA]", "[/aSA]");
  2246. var daTime = GetTextIn(data, "[aDA]", "[/aDA]");
  2247. var spyTime = GetTextIn(data, "[aSPY]", "[/aSPY]");
  2248. var sentryTime = GetTextIn(data, "[aSENTRY]", "[/aSENTRY]");
  2249.  
  2250. var player = [username, sa, saTime, da, daTime, spy, spyTime, sentry, sentryTime];
  2251. bfPlayers[i] = player;
  2252.  
  2253. bfTable.rows[i].addEventListener('mouseover', BattlefieldPHP_OnShowStat, true);
  2254. bfTable.rows[i].addEventListener('mouseout', function(){ document.getElementById('statDiv').style.display = 'none'; }, true);
  2255. }
  2256. }
  2257. });
  2258.  
  2259. // Add an option to fill the battlefield
  2260. bfTable.rows[0].cells[0].innerHTML = "<input type=checkbox id=FillBattlefield " + (GM_getValue("DF_fillBattlefield", 1) == 1 ? "checked" : "") + "><label for=FillBattlefield>Fill BF</label>";
  2261. document.getElementById('FillBattlefield').addEventListener('click', function(){ GM_setValue("DF_fillBattlefield", this.checked ? 1 : 0); window.location = window.location; }, false);
  2262.  
  2263. if(GM_getValue("DF_fillBattlefield", 1) != 1)
  2264. {
  2265. statDiv.innerHTML = "Logged!";
  2266. }
  2267. }
  2268.  
  2269. function BattlefieldPHP_OnShowStat()
  2270. {
  2271. var username = GetTextIn(this.cells[2].innerHTML, ">", "<");
  2272.  
  2273. var idx = -1;
  2274.  
  2275. for(var i = 0; i < bfPlayers.length; i++)
  2276. {
  2277. if(bfPlayers[i] && bfPlayers[i][0] == username)
  2278. {
  2279. idx = i;
  2280. break;
  2281. }
  2282. }
  2283.  
  2284. if(idx < 0) return;
  2285.  
  2286. var sa = bfPlayers[idx][1];
  2287. var da = bfPlayers[idx][3];
  2288. var spy = bfPlayers[idx][5];
  2289. var sentry = bfPlayers[idx][7];
  2290.  
  2291. var saTime = bfPlayers[idx][2];
  2292. var daTime = bfPlayers[idx][4];
  2293. var spyTime = bfPlayers[idx][6];
  2294. var sentryTime = bfPlayers[idx][8];
  2295.  
  2296. var statDiv = document.getElementById('statDiv');
  2297.  
  2298. statDiv.innerHTML = "<table width=100% class=table_lines cellspacing=0 cellpadding=6>"
  2299. + "<tr><th colspan=3>" + username + "'s Stats</th></tr>"
  2300. + "<tr><td><b>Attack</b></td><td align=right id=DB_sa>" + sa + "</td><td align=right id=DB_saTime>" + saTime + "</td></tr>"
  2301. + "<tr><td><b>Defense</b></td><td align=right id=DB_da>" + da + "</td><td align=right id=DB_daTime>" + daTime + "</td></tr>"
  2302. + "<tr><td><b>Spy</b></td><td align=right id=DB_spy>" + spy + "</td><td align=right id=DB_spyTime>" + spyTime + "</td></tr>"
  2303. + "<tr><td><b>Sentry</b></td><td align=right id=DB_sentry>" + sentry + "</td><td align=right id=DB_sentryTime>" + sentryTime + "</td></tr>"
  2304. + "</table>";
  2305.  
  2306. statDiv.style.width = "60ex";
  2307. statDiv.style.display = '';
  2308. }
  2309.  
  2310. function DetailPHP()
  2311. {
  2312. if(GM_getValue("DF_eligable", 0) == 0)
  2313. {
  2314. return;
  2315. }
  2316.  
  2317. var listenKeyboard = GM_getValue("DF_OptionKS", 1);
  2318.  
  2319. if(url.indexOf("suspense=1") >= 0)
  2320. {
  2321. // Remove suspense
  2322. var th = GetTag('th', "Battle Report");
  2323. var content = th.parentNode.parentNode.parentNode.parentNode.parentNode;
  2324. var scriptSource = GetTextIn(content.innerHTML, "<script", "</script>");
  2325.  
  2326.  
  2327. if(scriptSource != "")
  2328. {
  2329. var content2 = content.innerHTML.replace(scriptSource, ">");
  2330.  
  2331. content2 = content2.replace("table_lines battle", "table_lines");
  2332. content2 = content2.replace(/display: none/g, "");
  2333.  
  2334. content.innerHTML = content2;
  2335. }
  2336. }
  2337.  
  2338. // Scroll down to the useful part
  2339. var but = GetElement('input', "Attack / Spy Again");
  2340. but.scrollIntoView();
  2341.  
  2342. // Log the attack
  2343. var attackType = GetText("your soldiers are trained ", " specialists");
  2344. if(attackType != "attack")
  2345. {
  2346. // Log only attacks from our players ;)
  2347. return;
  2348. }
  2349.  
  2350. var reportId = url.indexOf("suspense") >= 0 ? GetTextIn(url, "_id=", "&suspense") : url.substring(49, url.length);
  2351. var treasury = 0;
  2352. var opponent = GetText("casualties!",">", "'s forces").trim();
  2353. opponent = opponent.split("\n")[1];
  2354.  
  2355. var result = document.body.innerHTML.indexOf("You <font ") > 0 ? "Successful" : "Defended";
  2356.  
  2357. if(document.body.innerHTML.indexOf("You stole") >= 0)
  2358. {
  2359. treasury = parseInt( GetText("You stole", ">", "<").replace(/,/g, "") );
  2360.  
  2361. // Add a shortcut to armory
  2362. but.parentNode.innerHTML += "<a href='http://www.kingsofchaos.com/armory.php' style='border: 1px solid #888888; background: black; font-size: 10pt; color: white; padding: 1px 10px;'> Armory" + (listenKeyboard == 0 ? "" : " (b)") + "</a>";
  2363. but = GetElement('input', "Attack / Spy Again");
  2364. }
  2365.  
  2366. var untrained = 0;
  2367.  
  2368. if(document.body.innerHTML.indexOf("untrained soldiers with weapons and ") >= 0)
  2369. {
  2370. untrained += parseInt(GetText("The enemy has <b>","</b> untrained soldiers").replace(/,/g,""));
  2371. untrained += parseInt(GetText("untrained soldiers with weapons and <b>","</b> with no weapons").replace(/,/g,""));
  2372. }
  2373.  
  2374.  
  2375. if(document.body.innerHTML.indexOf(">None</font> of the enemy's ") >= 0)
  2376. {
  2377. if(GetText("None</font> of the enemy's "," untrained soldiers have weapons"))
  2378. {
  2379. untrained += parseInt(GetText("None</font> of the enemy's "," untrained soldiers have weapons").replace(/,/,""));
  2380. }
  2381. }
  2382.  
  2383. var elost = 0;
  2384. if(document.body.innerHTML.indexOf("The enemy sustains ") >= 0)
  2385. {
  2386. elost = parseInt(String(FindText(GetText('The enemy sustains','/fon'),">","<")).replace(/,/g, ''));
  2387. }
  2388.  
  2389. // Add a place golder for the result of the logging
  2390. but.parentNode.innerHTML = but.parentNode.innerHTML.replace("Attack / Spy Again", "Attack / Spy Again" + (listenKeyboard == 0 ? "" : " (kp)")) + "<span id=logAttack style=\"margin-left: 20px;\">Logging your attack...</span>";
  2391.  
  2392.  
  2393. if ( Get_Cookie("attackType") == "raid" )
  2394. {
  2395. var aType = "raid";
  2396. }else if(treasury > 1)
  2397. {
  2398. var aType = "succesful";
  2399. }else{
  2400. var aType = "defended";
  2401. }
  2402.  
  2403.  
  2404. document.cookie = "attackType=notRaid;";
  2405.  
  2406. GM_xmlhttpRequest(
  2407. {
  2408. method: "GET",
  2409. url: DF_server + "backbone.php?code=logattacks&whoami=" + DF_username + "&password=" + DF_password + "&whoamid=" + DF_statid + "&target=" + opponent + "&result=" + result + "&gold=" + treasury + "&untrained=" + untrained + "&rid=" + reportId + "&type=" + aType + "&elost=" + elost,
  2410. onload: function(r)
  2411. {
  2412. if(r.status == 200)
  2413. {
  2414. document.getElementById('logAttack').innerHTML = r.responseText;
  2415. }
  2416. }
  2417. });
  2418. }
  2419.  
  2420. function WritemailPHP()
  2421. {
  2422. var username = GetTextIn(document.body.innerHTML, "</b>", "</th").trim();
  2423.  
  2424. document.getElementsByTagName('textarea')[0].value = GM_getValue("DF_msg_sig", "");
  2425.  
  2426. // If send button is clicked, save time
  2427. document.addEventListener('click', function(event) {
  2428. if(event.target.value)
  2429. {
  2430. var value = String(event.target.value);
  2431. if(value.indexOf("Send") == 0)
  2432. {
  2433. GM_setValue("DF_msg_sent_time_" + username, getCurrentTime());
  2434. GM_setValue("DF_msg_sent_content_" + username, document.getElementsByTagName('textarea')[0].value);
  2435. }
  2436. }
  2437.  
  2438. }, true);
  2439. }
  2440.  
  2441. function AttackLogPHP()
  2442. {
  2443. // Disable ajax navigation on koc
  2444. GetContentTD().innerHTML = GetContentTD().innerHTML;
  2445. }
  2446.  
  2447.  
  2448. function InboxPHP()
  2449. {
  2450. // Create Set Signature Button
  2451. var setSignature = GetElement('input', "Delete Entire Inbox").parentNode.parentNode;
  2452. setSignature.innerHTML = '<button onclick="document.getElementById(\'signatureBox\').style.visibility = \'visible\'; return false;" style="float: right; margin-left: 15px;">Set Signature</button>' + setSignature.innerHTML;
  2453.  
  2454. // Box for Signature Editing
  2455. var signatureBox = document.createElement('div');
  2456. signatureBox.setAttribute('id', 'signatureBox');
  2457. signatureBox.style.visibility = 'hidden';
  2458. signatureBox.style.position = 'absolute';
  2459. signatureBox.style.left = '0';
  2460. signatureBox.style.top = '0';
  2461. signatureBox.style.width = '100%';
  2462. signatureBox.style.height = window.outerHeight;
  2463. signatureBox.style.textAlign = 'center';
  2464. signatureBox.style.zIndex = '1000';
  2465. signatureBox.style.backgroundColor = ' rgba(0,0,0,.75)';
  2466. signatureBox.innerHTML = '<div style="width: 600px; margin: 300px auto; padding: 10px; text-align: center;"> \
  2467. <h1>EDIT SIGNATURE</h1> \
  2468. <textarea id="signature" cols=60 rows=8>' + GM_getValue("DF_msg_sig", "") + '</textarea><br> \
  2469. <input type="button" onclick="var signatureBox = document.getElementById(\'signatureBox\'); signatureBox.style.visibility = \'hidden\';" value="Save Signature" style="margin-top: 5px; width: 150px; height: 35px;"> \
  2470. </div>';
  2471. document.body.appendChild(signatureBox);
  2472.  
  2473. // Save signature when clicked on Save button
  2474. document.addEventListener('click', function(event) {
  2475. if(event.target.value)
  2476. {
  2477. var value = String(event.target.value);
  2478. if(value.indexOf("Save Signature") == 0)
  2479. {
  2480. GM_setValue("DF_msg_sig", document.getElementById('signature').value);
  2481. }
  2482. }
  2483.  
  2484. }, true);
  2485. }
  2486.  
  2487. function RecruitPHP()
  2488. {
  2489. var kocid = GetText("<a href=\"stats.php?id=", '"');
  2490. var recruitid= document.URL.substring( document.URL.indexOf("=") +1 );
  2491. //alert(kocid + " " + recruitid);
  2492.  
  2493. GM_xmlhttpRequest(
  2494. {
  2495. method: "POST",
  2496. url: DF_server + "backbone.php",
  2497. headers: { 'Content-type' : 'application/x-www-form-urlencoded' },
  2498. data: encodeURI("code=addrecruitid&whoami=" + DF_username + "&password=" + DF_password + "&whoamid=" + DF_statid + "&kocid=" + kocid + "&recruitid=" + recruitid),
  2499. onload: function(r)
  2500. {
  2501. if(r.status != 200) return;
  2502. }
  2503. });
  2504. }
  2505.  
  2506. /*****************************************************************************/
  2507. /********************************* FUNCTIONS *********************************/
  2508. /*****************************************************************************/
  2509.  
  2510. function AddCommas(val)
  2511. {
  2512. var val2 = "";
  2513.  
  2514. for(var i = val.length - 1, j = 1; i >= 0; i--, j++)
  2515. {
  2516. val2 += val[i];
  2517.  
  2518. if(j % 3 == 0 && i)
  2519. {
  2520. val2 += ",";
  2521. }
  2522. }
  2523.  
  2524. var val3 = "";
  2525.  
  2526. for(var i = val2.length - 1; i >= 0; i--)
  2527. {
  2528. val3 += val2[i];
  2529. }
  2530.  
  2531. return val3;
  2532. }
  2533.  
  2534. //first n-1 args are 'begin', last one is end, should send at least 2 args
  2535. function GetText()
  2536. {
  2537. var doc = document.body.innerHTML;
  2538.  
  2539. var pos = 0;
  2540.  
  2541. for(z = 0; z < (arguments.length - 1); z++)
  2542. {
  2543. pos = doc.indexOf(arguments[z], pos);
  2544. if(pos < 0) return "";
  2545.  
  2546. pos += arguments[z].length;
  2547. }
  2548.  
  2549. var pos2 = doc.indexOf(arguments[arguments.length - 1], pos);
  2550. if(pos2 < 0) return "";
  2551.  
  2552. return doc.substring(pos, pos2);
  2553. }
  2554.  
  2555. //the very first argumant is the text to search in, the rest is the same as GeText
  2556. function GetTextIn()
  2557. {
  2558. var pos = 0;
  2559.  
  2560. for(var i = 1; i < (arguments.length - 1); i++)
  2561. {
  2562. pos = arguments[0].indexOf(arguments[i], pos);
  2563. if(pos < 0) return "";
  2564.  
  2565. pos += arguments[i].length;
  2566. }
  2567.  
  2568. var pos2 = arguments[0].indexOf(arguments[arguments.length - 1], pos);
  2569. if(pos2 < 0) return "";
  2570.  
  2571. return arguments[0].substring(pos, pos2);
  2572. }
  2573.  
  2574. function GetTag(tag, inner)
  2575. {
  2576. var tagList = document.getElementsByTagName(tag);
  2577.  
  2578. for(z = 0; z < tagList.length; z++)
  2579. {
  2580. if(tagList[z].innerHTML.indexOf(inner) == 0)
  2581. {
  2582. return tagList[z];
  2583. }
  2584. }
  2585.  
  2586. return 0;
  2587. }
  2588.  
  2589. function GetElement(elem, val)
  2590. {
  2591. var elemList = document.getElementsByTagName(elem);
  2592.  
  2593. for(var i = 0; i < elemList.length; i++)
  2594. {
  2595. if(elemList[i].value.toString().indexOf(val) == 0)
  2596. {
  2597. return elemList[i];
  2598. }
  2599. }
  2600.  
  2601. return 0;
  2602. }
  2603.  
  2604. function GetTable(thInner)
  2605. {
  2606. var th = GetTag('th', thInner);
  2607. if(!th) return 0;
  2608.  
  2609. return th.parentNode.parentNode;
  2610. }
  2611.  
  2612. // returns 0-based index
  2613. function GetTableRow(table, cellId, inner)
  2614. {
  2615. for(var i = 0; i < table.rows.length; i++)
  2616. {
  2617. if(table.rows[i].cells[cellId].innerHTML.indexOf(inner) >= 0)
  2618. {
  2619. return i;
  2620. }
  2621. }
  2622.  
  2623. return -1;
  2624. }
  2625.  
  2626. function GetContentTD()
  2627. {
  2628. var tables = document.getElementsByClassName("content");
  2629. if(tables.length == 0) return 0;
  2630.  
  2631. return tables[0];
  2632. }
  2633.  
  2634. // Convert ms to ... ago
  2635. function PrintableTime(elapsedMs)
  2636. {
  2637. var secs = elapsedMs / 1000;
  2638.  
  2639. var months = parseInt( Math.floor(secs / 2592000) );
  2640. secs -= months * 2592000;
  2641.  
  2642. var days = parseInt( Math.floor(secs / 86400) );
  2643. secs -= days * 86400;
  2644.  
  2645. var hours = parseInt( Math.floor(secs / 3600) );
  2646. secs -= hours * 3600;
  2647.  
  2648. var minutes = parseInt( Math.floor(secs / 60) );
  2649. secs -= minutes * 3600;
  2650.  
  2651. secs = parseInt( Math.floor(secs) );
  2652.  
  2653. var str = "";
  2654.  
  2655. if(months > 0) str += (months + " month" + (months > 1 ? "s " : " "));
  2656. if(days > 0) str += (days + " day" + (days > 1 ? "s " : " "));
  2657. if(hours > 0) str += (hours + " hour" + (hours > 1 ? "s " : " "));
  2658. if(minutes > 0) str += (minutes + " minute" + (minutes > 1 ? "s " : " "));
  2659. if(secs > 0) str += (secs + " second" + (secs > 1 ? "s " : " "));
  2660.  
  2661. return str.trim();
  2662. }
  2663.  
  2664. function GetGold()
  2665. {
  2666. var goldText = GetText("Gold:", ">", "<");
  2667. if(goldText == "") return 0;
  2668.  
  2669. return parseInt( goldText.trim().replace(/,/g, "").replace('M', '000000') );
  2670. }
  2671.  
  2672. function GetSoldier(type)
  2673. {
  2674. var soldierText = GetText(type, "right\">", "<");
  2675. if(soldierText == "") return 0;
  2676.  
  2677. return parseInt( soldierText.replace(/,/g, "") );
  2678. }
  2679.  
  2680. function GetSoldiers()
  2681. {
  2682. var tas = GetSoldier("Trained Attack Soldiers");
  2683. var tam = GetSoldier("Trained Attack Mercenaries");
  2684. var tds = GetSoldier("Trained Defense Soldiers");
  2685. var tdm = GetSoldier("Trained Defense Mercenaries");
  2686. var us = GetSoldier("Untrained Soldiers");
  2687. var um = GetSoldier("Untrained Mercenaries");
  2688. var spy = GetSoldier("Spies");
  2689. var sentry = GetSoldier("Sentries");
  2690. var tff = GetSoldier("Total Fighting Force");
  2691.  
  2692. return {'tas' : tas, 'tam' : tam, 'tds' : tds, 'tdm' : tdm, 'us' : us, 'um' : um, 'spy' : spy, 'sentry' : sentry, 'tff' : tff};
  2693. }
  2694.  
  2695. function GetAvailableMerc(type)
  2696. {
  2697. var mercText = GetText('>' + type + '<', "right\">", "right\">", "<");
  2698. if(mercText == "None" || mercText == "") return 0;
  2699.  
  2700. return parseInt( mercText.replace(/,/g, "") );
  2701. }
  2702.  
  2703. function GetAvailableMercs()
  2704. {
  2705. var am = GetAvailableMerc("Attack Specialist");
  2706. var dm = GetAvailableMerc("Defense Specialist");
  2707. var um = GetAvailableMerc("Untrained");
  2708.  
  2709. return {'am' : am, 'dm' : dm, 'um' : um};
  2710. }
  2711.  
  2712. function AddSoldierButton(soldierName, buttonId, callback)
  2713. {
  2714. var td = GetTag('td', soldierName);
  2715.  
  2716. if(td)
  2717. {
  2718. td.parentNode.innerHTML += "<td><button id=" + buttonId + " onClick=\"return false;\">0</button></td>";
  2719.  
  2720. document.getElementById(buttonId).addEventListener('click', callback, false);
  2721. }
  2722. }
  2723.  
  2724. function ExpandCollapseTable(header, collapse)
  2725. {
  2726. var th = GetTag('th', header);
  2727. if(!th) return;
  2728.  
  2729. th.innerHTML += "<span id=toggle_" + header.replace(/ /g, "_") + " style=\"float:right\"><tt>-</tt></span>";
  2730.  
  2731. var table = th.parentNode.parentNode;
  2732.  
  2733. table.rows[0].addEventListener('click', function(){ OnExpColTable(header); }, false);
  2734. table.rows[0].style.cursor = "pointer";
  2735.  
  2736. // Set the initial state
  2737. if(collapse == undefined)
  2738. {
  2739. collapse = GM_getValue("DF_expcol_" + header.replace(/ /g, "_"), 1) == 0; // 1: expanded, 0: collapsed
  2740. }
  2741.  
  2742. if(collapse)
  2743. {
  2744. OnExpColTable(header);
  2745. }
  2746. }
  2747.  
  2748. function OnExpColTable(header)
  2749. {
  2750. var th = GetTag('th', header);
  2751. if(!th) return;
  2752.  
  2753. var table = th.parentNode.parentNode;
  2754.  
  2755. if(table.rows.length < 2) return;
  2756.  
  2757. var disp = (table.rows[1].style.display == "none" ? "" : "none");
  2758.  
  2759. for(i = 1; i < table.rows.length; i++)
  2760. {
  2761. table.rows[i].style.display = disp;
  2762. }
  2763.  
  2764. document.getElementById('toggle_' + header.replace(/ /g, "_")).innerHTML = "<tt>" + (disp == "none" ? "+" : "-") + "</tt>";
  2765.  
  2766. GM_setValue("DF_expcol_" + header.replace(/ /g, "_"), disp == "none" ? 0 : 1);
  2767. }
  2768.  
  2769. function checkVersion()
  2770. {
  2771. lastCheck = GM_getValue("DF_LastUpdateCheck_time", "");
  2772. if(lastCheck == "")
  2773. {
  2774. GM_xmlhttpRequest(
  2775. {
  2776. method: "GET",
  2777. url: DF_server + "version.php?ver=" + DF_version,
  2778. onload: function(r)
  2779. {
  2780. if(r.status != 200) return;
  2781. GM_setValue("DF_LastUpdateCheck_time", getCurrentTime());
  2782. }
  2783. });
  2784. GM_setValue("DF_LastUpdateCheck_time", getCurrentTime());
  2785. }
  2786. else
  2787. {
  2788. if(getCurrentTime() - lastCheck > 600)
  2789. {
  2790. GM_xmlhttpRequest(
  2791. {
  2792. method: "GET",
  2793. url: DF_server + "version.php?ver=" + DF_version,
  2794. onload: function(r)
  2795. {
  2796. if(r.status != 200) return;
  2797. var ver = GetTextIn(r.responseText, "[VER]", "[/VER]");
  2798. var dlink = GetTextIn(r.responseText, "[LINK]", "[/LINK]");
  2799. var changelog = GetTextIn(r.responseText, "[CHANGELOG]", "[/CHANGELOG]");
  2800. if(DF_version != ver) alert("You're using an old version of AaA's DF!\n----Changelog----\n " + changelog), GM_openInTab(dlink);
  2801. GM_setValue("DF_LastUpdateCheck_time", getCurrentTime());
  2802. }
  2803. });
  2804. GM_setValue("DF_LastUpdateCheck_time", getCurrentTime());
  2805. }
  2806. }
  2807. }
  2808.  
  2809. function getCurrentTime()
  2810. {
  2811. return Math.round(new Date / 1E3);
  2812. }
  2813.  
  2814. function AddMenuItems()
  2815. {
  2816. var table = GetTag('td', "<img src=\"/images/menubar/age").parentNode.parentNode;
  2817.  
  2818. table.insertRow(3).insertCell(0).innerHTML = "<a href=\"http://www.kingsofchaos.com/stats.php?id=targetlist\"><img alt=\"Target List\" src=\"" + DF_server + "images/menubar_targets.gif\"></a>";
  2819. table.insertRow(4).insertCell(0).innerHTML = "<a href=\"http://www.kingsofchaos.com/stats.php?id=farmlist\"><img alt=\"Farm List\" src=\"" + DF_server + "images/menubar_farmlist.gif\"></a>";
  2820. table.insertRow(13).insertCell(0).innerHTML = "<a href=\"http://www.kingsofchaos.com/stats.php?id=links\"><img alt=\"Third Party Links\" src=\"" + DF_server + "images/links.gif\"></a>";
  2821.  
  2822. // check if there was a war last time
  2823. var warStatus = GM_getValue("GO_war_status", 0);
  2824. var warLink = GM_getValue("GO_war_link", "");
  2825.  
  2826. if(warStatus > 0)
  2827. {
  2828. // Add new menu item for the war
  2829. table.insertRow(3).insertCell(0).innerHTML = "<a target=_blank href=\"" + warLink + "\"><img alt=\"War missions!\" src=\"" + DF_server + "images/missions.gif\"></a>";
  2830. }
  2831.  
  2832. GM_xmlhttpRequest(
  2833. {
  2834. method: "GET",
  2835. url: DF_server + "backbone.php?code=war",
  2836. onload: function(r)
  2837. {
  2838. if(r.status != 200) return;
  2839.  
  2840.  
  2841. if(r.responseText.indexOf("hide") < 0)
  2842. {
  2843. warLink = r.responseText.replace("[NAME]", DF_username);
  2844.  
  2845. if(warStatus > 0) // if there was war, just update
  2846. {
  2847. table.rows[3].cells[0].innerHTML = "<a target=_blank href=\"" + warLink + "\"><img alt=\"War missions!\" src=\"http://www.againstallauthority.nl/script/images/missions.gif\"></a>";
  2848. }
  2849. else
  2850. {
  2851. // Add new menu item for the war
  2852. table.insertRow(3).insertCell(0).innerHTML = "<a target=_blank href=\"" + warLink + "\"><img alt=\"War missions!\" src=\"http://www.againstallauthority.nlscript/images/missions.gif\"></a>";
  2853.  
  2854. // Switch on war status
  2855. GM_setValue("GO_war_status", 1);
  2856. }
  2857.  
  2858. GM_setValue("GO_war_link", warLink);
  2859. }
  2860. else
  2861. {
  2862. // Switch off war status
  2863. GM_setValue("GO_war_status", 0);
  2864. GM_setValue("GO_war_link", "");
  2865. }
  2866.  
  2867. }
  2868. });
  2869.  
  2870. }
  2871.  
  2872. function AddBfSearch()
  2873. {
  2874. var links = document.getElementsByTagName('a');
  2875.  
  2876. var firefoxLink = 0;
  2877.  
  2878. for(var i = 0; i < links.length; i++)
  2879. {
  2880. if(links[i].href.indexOf("spreadfirefox") >= 0)
  2881. {
  2882. firefoxLink = links[i];
  2883. break;
  2884. }
  2885. }
  2886.  
  2887. if(firefoxLink)
  2888. {
  2889.  
  2890. firefoxLink.parentNode.innerHTML = "<table border=\"0\" cellpadding=\"6\" cellspacing=\"0\" width=\"100%\"><tr><th>Battlefield</th></tr><tr><td align=\"center\"><input type=text id=bfSearchName style='width:120px;' /></td></tr><tr><td align=\"center\"><button id=bfSearchButton onClick=\"window.location='http://www.kingsofchaos.com/battlefield.php?search=' + document.getElementById('bfSearchName').value.trim();\">Search</button></td></tr><tr><td><div id=resultsDiv style='position:absolute; margin-top: -80px; margin-left: 90px;'><ul id=results style='list-style-type:none;'></ul></div></td></tr>";
  2891.  
  2892. var inputElem = document.getElementById("bfSearchName");
  2893. inputElem.addEventListener('keyup', findUsername, true);
  2894. }
  2895.  
  2896. }
  2897.  
  2898. function findUsername(e)
  2899. {
  2900. if(e.keyCode == 27 || document.getElementById("bfSearchName").value == "")
  2901. {
  2902. document.getElementById("results").innerHTML = "";
  2903. }
  2904. else
  2905. {
  2906. GM_xmlhttpRequest(
  2907. {
  2908. method: "GET",
  2909. url: DF_server + "backbone.php?code=findUsername&username=" + document.getElementById("bfSearchName").value,
  2910. onload: function(r)
  2911. {
  2912. if(r.status == 200)
  2913. {
  2914. document.getElementById('results').innerHTML = r.responseText;
  2915.  
  2916. }
  2917. }
  2918. });
  2919. }
  2920. }
  2921.  
  2922. function CheckExpForNextTech()
  2923. {
  2924. var targetExp = GM_getValue("DF_nextTechExp", -1);
  2925. if(targetExp < 0)
  2926. {
  2927. return;
  2928. }
  2929.  
  2930. var curExp = parseInt( GetText("Experience:", "color", ">", "<").trim().replace(/,/g, ""), 10 );
  2931. if(isNaN(curExp))
  2932. {
  2933. return;
  2934. }
  2935.  
  2936. if(curExp >= targetExp)
  2937. {
  2938. var t = GetTag('td', "Experience:");
  2939. if(t)
  2940. {
  2941. t.style.color = "#CC0000";
  2942. }
  2943. }
  2944. }
  2945.  
  2946. function DetectRunningInstance()
  2947. {
  2948. if(document.getElementById('InstanceDF'))
  2949. {
  2950. return true;
  2951. }
  2952.  
  2953. var instanceDiv = document.createElement('div');
  2954. instanceDiv.style.display = 'none';
  2955. instanceDiv.setAttribute('id', "InstanceDF");
  2956. document.body.appendChild(instanceDiv);
  2957.  
  2958. return false;
  2959. }
  2960.  
  2961. /*************************** base.php Functions ******************************/
  2962.  
  2963. function BasePHP_OnRegisterDF(username, statid, uniqid, password, email)
  2964. {
  2965. // ask for password
  2966. var ret = password;
  2967. while(true)
  2968. {
  2969. ret = prompt("Hello " + username + "!\nEnter your DF password:", password);
  2970. if(ret == null)
  2971. {
  2972. return;
  2973. }
  2974.  
  2975. if(ret.length > 0)
  2976. {
  2977. break;
  2978. }
  2979. };
  2980.  
  2981. password = ret;
  2982. GM_setValue("DF_password", password);
  2983. GM_setValue("password", password);
  2984.  
  2985. GM_xmlhttpRequest(
  2986. {
  2987. method: "GET",
  2988. url: DF_server + "register.php?username=" + username + "&password=" + password + "&userid=" + statid + "&recruitid=" + uniqid
  2989. });
  2990.  
  2991. alert("Your registration details have been sent to the AaA server.\n"
  2992. + "Please wait until an AaA administrator activates your DF account.\n");
  2993.  
  2994. window.location = "http://www.kingsofchaos.com/base.php";
  2995. }
  2996.  
  2997. function BasePHP_OnputDFPassword(username, password)
  2998. {
  2999. // ask for password
  3000. var ret = password;
  3001. while(true)
  3002. {
  3003. ret = prompt("Hello " + username + "!\nEnter your DF password:", password);
  3004. if(ret == null)
  3005. {
  3006. return;
  3007. }
  3008.  
  3009. if(ret.length > 0)
  3010. {
  3011. break;
  3012. }
  3013. };
  3014.  
  3015. password = ret;
  3016. GM_setValue("DF_password", password);
  3017. GM_setValue("password", password);
  3018.  
  3019. window.location = "http://www.kingsofchaos.com/base.php";
  3020. }
  3021.  
  3022. function BasePHP_OnToggleDFOptions()
  3023. {
  3024. if(document.getElementById('ddfOptionsContainer').style.display == '')
  3025. {
  3026. document.getElementById('ddfOptionsContainer').style.display = 'none';
  3027. document.getElementById('ddfOptions').style.display = 'none';
  3028. }
  3029. else
  3030. {
  3031. document.getElementById('ddfOptionsContainer').style.display = '';
  3032. document.getElementById('ddfOptions').style.display = '';
  3033. }
  3034. }
  3035.  
  3036. function BasePHP_OnSaveDFOptions()
  3037. {
  3038. GM_setValue("DF_OptionArmoryDetail", document.getElementById('dfOptionArmoryDetail').checked == true ? 1 : 0);
  3039. GM_setValue("DF_OptionScrollIntoContent", document.getElementById('dfOptionScrollIntoContent').checked == true ? 1 : 0);
  3040. GM_setValue("DF_OptionEconomicDevelopment", document.getElementById('dfOptionEconomicDevelopment').checked == true ? 1 : 0);
  3041. GM_setValue("DF_OptionSpecialEffects", document.getElementById('dfOptionSpecialEffects').checked == true ? 1 : 0);
  3042. GM_setValue("DF_OptionShowLastMsgSent", document.getElementById('dfOptionShowLastMsgSent').checked == true ? 1 : 0);
  3043.  
  3044.  
  3045. GM_setValue("DF_password", document.getElementById("dfOptionPassword").value);
  3046.  
  3047. // hide the options
  3048. BasePHP_OnToggleDFOptions();
  3049.  
  3050. window.location = "base.php";
  3051. }
  3052.  
  3053.  
  3054. /*************************** armory.php Functions *****************************/
  3055. function ArmoryPHP_OnClearLostLog()
  3056. {
  3057. var cf = confirm("Are you sure you want to clear the log?");
  3058. if(!cf) return;
  3059.  
  3060. for(var i = 0; i < 10; i++)
  3061. {
  3062. GM_setValue("DF_lost_wep_log_" + i, "::");
  3063. }
  3064.  
  3065. window.location = "armory.php";
  3066. }
  3067.  
  3068. function ArmoryPHP_ReduceBloodEffect()
  3069. {
  3070. var bloodDiv = document.getElementById('bloodDiv');
  3071.  
  3072. bloodDiv.style.opacity -= 0.1;
  3073.  
  3074. if(bloodDiv.style.opacity > 0)
  3075. {
  3076. setTimeout(ArmoryPHP_ReduceBloodEffect, 100);
  3077. }
  3078. else
  3079. {
  3080. bloodDiv.style.display = 'none';
  3081. }
  3082. }
  3083.  
  3084. function ArmoryPHP_UpdateWeaponButtons()
  3085. {
  3086. var totalGoldNeed = 0;
  3087.  
  3088. var buyTable = GetTable("Buy Weapons");
  3089.  
  3090. for(var i = 2; i < buyTable.rows.length; i++)
  3091. {
  3092. if(buyTable.rows[i].cells.length < 5) continue;
  3093.  
  3094. var buybutId = GetTextIn(buyTable.rows[i].cells[3].innerHTML, "name=\"", "\"");
  3095.  
  3096. var wepCost = parseInt( buyTable.rows[i].cells[2].innerHTML.replace(/,/g, "") );
  3097.  
  3098. var wepCount = parseInt( document.getElementsByName(buybutId)[0].value, 10 );
  3099.  
  3100. if(isNaN(wepCount) || wepCount < 0)
  3101. {
  3102. wepCount = 0;
  3103. document.getElementsByName(buybutId)[0].value = 0;
  3104. }
  3105.  
  3106. totalGoldNeed += (wepCost * wepCount);
  3107. }
  3108.  
  3109. if(totalGoldNeed > gold)
  3110. {
  3111. if(this.name.length > 0)
  3112. {
  3113. this.value = 0;
  3114.  
  3115. ArmoryPHP_UpdateWeaponButtons();
  3116.  
  3117. return;
  3118. }
  3119. }
  3120.  
  3121. // Update the buttons with the left amount and compose the buying note
  3122. var leftGold = gold - totalGoldNeed;
  3123. var buyingNote = [];
  3124.  
  3125. for(var i = 2; i < buyTable.rows.length; i++)
  3126. {
  3127. if(buyTable.rows[i].cells.length < 5) continue;
  3128.  
  3129. var buybutId = GetTextIn(buyTable.rows[i].cells[3].innerHTML, "name=\"", "\"");
  3130.  
  3131. var wepCost = parseInt( buyTable.rows[i].cells[2].innerHTML.replace(/,/g, "") );
  3132.  
  3133. var wepCount = parseInt( document.getElementsByName(buybutId)[0].value, 10 );
  3134.  
  3135. document.getElementById(buybutId).innerHTML = wepCount + Math.floor( leftGold / wepCost );
  3136.  
  3137. // buying note
  3138. var wepName = buyTable.rows[i].cells[0].innerHTML;
  3139.  
  3140. if(weaponList.indexOf(wepName) >= 0 && wepCount > 0)
  3141. {
  3142. buyingNote.push(wepCount + " " + wepName + (wepCount > 1 ? "s" : ""));
  3143. }
  3144. }
  3145.  
  3146. // Update the buying note
  3147. document.getElementById('BuyingNote').innerHTML = (buyingNote.length == 0 ? "Nothing" : buyingNote.join("<br />"));
  3148. }
  3149.  
  3150. function ArmoryPHP_OnClearBuyButtons()
  3151. {
  3152. var buyTable = GetTable("Buy Weapons");
  3153.  
  3154. for(var i = 2; i < buyTable.rows.length; i++)
  3155. {
  3156. if(buyTable.rows[i].cells.length < 5) continue;
  3157.  
  3158. var buybutId = GetTextIn(buyTable.rows[i].cells[3].innerHTML, "name=\"", "\"");
  3159.  
  3160. document.getElementsByName(buybutId)[0].value = 0;
  3161. }
  3162.  
  3163. ArmoryPHP_UpdateWeaponButtons();
  3164. }
  3165.  
  3166. function ArmoryPHP_OnSellButton()
  3167. {
  3168. var wepId = GetTextIn(this.parentNode.parentNode.innerHTML, "scrapsell[", "]");
  3169.  
  3170. var wepBuyBut = document.getElementById("buy_weapon[" + wepId + "]");
  3171. if(!wepBuyBut) return;
  3172.  
  3173. var wepName = wepBuyBut.parentNode.parentNode.cells[0].innerHTML;
  3174. if(weaponList.indexOf(wepName) < 0) return;
  3175.  
  3176. var wepSellCount = parseInt( document.getElementsByName('scrapsell[' + wepId + ']')[0].value, 10 );
  3177. if(wepSellCount < 0) return;
  3178.  
  3179. GM_setValue("DF_armory_" + wepName.replace(/ /g, "_") + "_sold", wepSellCount);
  3180. }
  3181.  
  3182.  
  3183. /*************************** attack.php Functions *****************************/
  3184.  
  3185. function AttackPHP_OnSubmitSab(targetname)
  3186. {
  3187. // Remember sabotage settings for this target
  3188. GM_setValue("DF_sab_wep_" + targetname, document.getElementsByTagName('select')[0].value);
  3189. GM_setValue("DF_sab_cnt_" + targetname, document.getElementsByName('numsab')[0].value);
  3190. GM_setValue("DF_sab_spies_" + targetname, document.getElementsByName('numspies')[0].value);
  3191. GM_setValue("DF_sab_turns_" + targetname, document.getElementsByTagName('select')[1].value);
  3192. }
  3193.  
  3194. function AttackPHP_SetReconCnt(username)
  3195. {
  3196. if(GM_getValue("DF_recon_cnt_" + username, 15) > 0)
  3197. {
  3198. GM_setValue("DF_recon_cnt_" + username, GM_getValue("DF_recon_cnt_" + username, 15) - 1);
  3199. GM_setValue("DF_recon_dates_" + username, GM_getValue("DF_recon_dates_"+ username, "") + getCurrentTime() + ",");
  3200. }
  3201. }
  3202.  
  3203. function AttackPHP_GetLastMsgSent(username)
  3204. {
  3205. if(GM_getValue("DF_msg_sent_time_" + username, "Never") == "Never")
  3206. {
  3207. return "<span style=color:gray>" + "Never" + "</span>";
  3208. }
  3209. else
  3210. {
  3211. var timeAgo = ConvertTimeSimple(GM_getValue("DF_msg_sent_time_" + username)) + " ago";
  3212. if(timeAgo.indexOf("second") >= 0) return "<span style=color:red>" + timeAgo + "</span>";
  3213. else if(timeAgo.indexOf("minute") >= 0)
  3214. {
  3215. var timeAgoSplit = timeAgo.split(" ");
  3216. if(timeAgoSplit[0] <= 15) return "<span style=color:yellow>" + timeAgo + "</span>";
  3217. else return "<span style=color:green>" + timeAgo + "</span>";
  3218. }
  3219. else if(timeAgo.indexOf("hour") >= 0) return "<span style=color:green>" + timeAgo + "</span>";
  3220. else return "<span style=color:gray>" + timeAgo + "</span>";
  3221. }
  3222. }
  3223.  
  3224. function InteldetailPHP_CalcReconsLeft(username)
  3225. {
  3226. var reconDatesStr = GM_getValue("DF_recon_dates_"+ username, "");
  3227. var reconDates = reconDatesStr.split(",");
  3228. var newReconDatesStr = "";
  3229.  
  3230. if(reconDates.length >= 1 && reconDates[0] != "")
  3231. {
  3232. if(getCurrentTime() - reconDates[0] > 86400) // 24 hours = 60 * 60 * 24 = 86400
  3233. {
  3234. GM_setValue("DF_recon_cnt_" + username, GM_getValue("DF_recon_cnt_" + username, 15) + 1);
  3235. reconDates.splice(0, 1);
  3236.  
  3237. for(var i = 0; i < reconDates.length; i++)
  3238. {
  3239. if(reconDates[i] != "")
  3240. {
  3241. newReconDatesStr += reconDates[i] + ",";
  3242. }
  3243. }
  3244.  
  3245. if(newReconDatesStr == "")
  3246. {
  3247. GM_deleteValue("DF_recon_dates_" + username);
  3248. GM_deleteValue("DF_recon_cnt_" + username);
  3249. }
  3250. else
  3251. {
  3252. GM_setValue("DF_recon_dates_" + username, newReconDatesStr);
  3253. InteldetailPHP_CalcReconsLeft(username);
  3254. }
  3255. }
  3256. }
  3257. }
  3258.  
  3259. /*************************** train.php Functions *****************************/
  3260.  
  3261. function TrainPHP_OnAssignSoldier()
  3262. {
  3263. switch(this.id)
  3264. {
  3265. case 'assign_attack':
  3266. document.getElementsByName('train[attacker]')[0].value = document.getElementById(this.id).innerHTML;
  3267. break;
  3268.  
  3269. case 'assign_defense':
  3270. document.getElementsByName('train[defender]')[0].value = document.getElementById(this.id).innerHTML;
  3271. break;
  3272.  
  3273. case 'assign_spy':
  3274. document.getElementsByName('train[spy]')[0].value = document.getElementById(this.id).innerHTML;
  3275. break;
  3276.  
  3277. case 'assign_sentry':
  3278. document.getElementsByName('train[sentry]')[0].value = document.getElementById(this.id).innerHTML;
  3279. break;
  3280. }
  3281.  
  3282. TrainPHP_UpdateTrainingButtons();
  3283. }
  3284.  
  3285. function TrainPHP_UpdateTrainingButtons()
  3286. {
  3287. var tattack = 1 * document.getElementsByName('train[attacker]')[0].value;
  3288. var tdefense = 1 * document.getElementsByName('train[defender]')[0].value;
  3289. var tspy = 1 * document.getElementsByName('train[spy]')[0].value;
  3290. var tsentry = 1 * document.getElementsByName('train[sentry]')[0].value;
  3291.  
  3292. if(tattack < 0 || isNaN(tattack)) tattack = 0;
  3293. if(tdefense < 0 || isNaN(tdefense)) tdefense = 0;
  3294. if(tspy < 0 || isNaN(tspy)) tspy = 0;
  3295. if(tsentry < 0 || isNaN(tsentry)) tsentry = 0;
  3296.  
  3297. var remainingSoldiers = soldiers.us - (tattack + tdefense + tspy + tsentry);
  3298.  
  3299. if(remainingSoldiers < 0)
  3300. {
  3301. tattack = tdefense = tspy = tsentry = 0;
  3302. remainingSoldiers = soldiers.us;
  3303. }
  3304.  
  3305. var remainingGold = gold - (tattack + tdefense) * 2000 - (tspy + tsentry) * 3500;
  3306. if(remainingGold <= 0) remainingGold = 0;
  3307.  
  3308. var remain2 = Math.min( Math.floor(remainingGold / 2000), remainingSoldiers );
  3309. var remain3 = Math.min( Math.floor(remainingGold / 3500), remainingSoldiers );
  3310.  
  3311. document.getElementById('assign_attack').innerHTML = remain2 ? tattack + remain2 : 0;
  3312. document.getElementById('assign_defense').innerHTML = remain2 ? tdefense + remain2 : 0;
  3313. document.getElementById('assign_spy').innerHTML = remain3 ? tspy + remain3 : 0;
  3314. document.getElementById('assign_sentry').innerHTML = remain3 ? tsentry + remain3 : 0;
  3315.  
  3316. document.getElementsByName('train[attacker]')[0].value = tattack;
  3317. document.getElementsByName('train[defender]')[0].value = tdefense;
  3318. document.getElementsByName('train[spy]')[0].value = tspy;
  3319.  
  3320. document.getElementsByName('train[sentry]')[0].value = tsentry;
  3321. }
  3322.  
  3323. function TrainPHP_ClearTraining()
  3324. {
  3325. document.getElementsByName('train[attacker]')[0].value = 0;
  3326. document.getElementsByName('train[defender]')[0].value = 0;
  3327. document.getElementsByName('train[spy]')[0].value = 0;
  3328. document.getElementsByName('train[sentry]')[0].value = 0;
  3329. document.getElementsByName('train[unattacker]')[0].value = 0;
  3330. document.getElementsByName('train[undefender]')[0].value = 0;
  3331.  
  3332. TrainPHP_UpdateTrainingButtons();
  3333. }
  3334.  
  3335. function TrainPHP_OnToggleTechs()
  3336. {
  3337. var stateSpan = document.getElementById('toggle_techs');
  3338. var state = stateSpan.innerHTML.indexOf("+") >= 0;
  3339. var table = GetTag('th', "Technological Development").parentNode.parentNode;
  3340.  
  3341. for(i = 3; i < table.rows.length; i++)
  3342. {
  3343. table.rows[i].style.display = state ? '' : 'none';
  3344. }
  3345.  
  3346. stateSpan.innerHTML = stateSpan.innerHTML.replace(state ? '+' : '-', state ? '-' : '+');
  3347. }
  3348.  
  3349.  
  3350. /*************************** mercs.php Functions *****************************/
  3351.  
  3352. function MercsPHP_OnAssignMerc()
  3353. {
  3354. switch(this.id)
  3355. {
  3356. case 'assign_attack':
  3357. document.getElementsByName('mercs[attack]')[0].value = document.getElementById(this.id).innerHTML;
  3358. break;
  3359.  
  3360. case 'assign_defense':
  3361. document.getElementsByName('mercs[defend]')[0].value = document.getElementById(this.id).innerHTML;
  3362. break;
  3363.  
  3364. case 'assign_untrained':
  3365. document.getElementsByName('mercs[general]')[0].value = document.getElementById(this.id).innerHTML;
  3366. break;
  3367. }
  3368.  
  3369. MercsPHP_UpdateMercButtons();
  3370. }
  3371.  
  3372. function MercsPHP_UpdateMercButtons()
  3373. {
  3374. var mattack = 1 * document.getElementsByName('mercs[attack]')[0].value;
  3375. var mdefense = 1 * document.getElementsByName('mercs[defend]')[0].value;
  3376. var muntrained = 1 * document.getElementsByName('mercs[general]')[0].value;
  3377.  
  3378. if(mattack < 0 || isNaN(mattack)) mattack = 0;
  3379. if(mdefense < 0 || isNaN(mdefense)) mdefense = 0;
  3380. if(muntrained < 0 || isNaN(muntrained)) muntrained = 0;
  3381.  
  3382. var mercLimit = Math.floor((soldiers.tas + soldiers.tds + soldiers.us) / 3) - (soldiers.tam + soldiers.tdm + soldiers.um);
  3383.  
  3384. // display how much merc is at hand
  3385. var t = GetTag('h3', "Mercenaries");
  3386. if(t)
  3387. {
  3388. if(mercLimit <= 0)
  3389. {
  3390. //you cannot but any more mercs
  3391. if(t.innerHTML.indexOf("You have ") < 0)
  3392. {
  3393. t.innerHTML += "<font color=red style=\"float: right; margin-right: 4ex;\">Warning: You have at least 25% mercs!</font>";
  3394. }
  3395. }
  3396. else
  3397. {
  3398. if(t.innerHTML.indexOf("You have ") < 0)
  3399. {
  3400. var perc = 100 * (soldiers.tam + soldiers.tdm + soldiers.um) / soldiers.tff;
  3401. t.innerHTML += "<font color=white style=\"float: right; margin-right: 4ex;\">You have " + perc.toFixed(2) + "% mercs</font>";
  3402. }
  3403. }
  3404. }
  3405.  
  3406. mercLimit -= (mattack + mdefense + muntrained);
  3407.  
  3408. if(mercLimit < 0)
  3409. {
  3410. mattack = mdefense = muntrained = 0;
  3411. mercLimit = Math.floor((soldiers.tas + soldiers.tds + soldiers.us) / 3) - (soldiers.tam + soldiers.tdm + soldiers.um);
  3412.  
  3413. if(mercLimit <= 0)
  3414. {
  3415. mercLimit = 0;
  3416. }
  3417. }
  3418.  
  3419. var remainingGold = gold - (mattack + mdefense) * 4500 - muntrained * 3500;
  3420. if(remainingGold <= 0) remainingGold = 0;
  3421.  
  3422. var maxAttack = Math.min( Math.min( Math.floor(remainingGold / 4500), mercLimit ), mercs.am);
  3423. var maxDefense = Math.min( Math.min( Math.floor(remainingGold / 4500), mercLimit ), mercs.dm);
  3424. var maxUntrained = Math.min( Math.min( Math.floor(remainingGold / 3500), mercLimit ), mercs.um);
  3425.  
  3426. document.getElementById('assign_attack').innerHTML = maxAttack ? mattack + maxAttack : 0;
  3427. document.getElementById('assign_defense').innerHTML = maxDefense ? mdefense + maxDefense : 0;
  3428. document.getElementById('assign_untrained').innerHTML = maxUntrained ? muntrained + maxUntrained : 0;
  3429.  
  3430. document.getElementsByName('mercs[attack]')[0].value = mattack;
  3431. document.getElementsByName('mercs[defend]')[0].value = mdefense;
  3432. document.getElementsByName('mercs[general]')[0].value = muntrained;
  3433. }
  3434.  
  3435. function MercsPHP_ClearMercs()
  3436. {
  3437. document.getElementsByName('mercs[attack]')[0].value = 0;
  3438. document.getElementsByName('mercs[defend]')[0].value = 0;
  3439. document.getElementsByName('mercs[general]')[0].value = 0;
  3440.  
  3441. MercsPHP_UpdateMercButtons();
  3442. }
  3443.  
  3444.  
  3445. /*************************** Custom page *****************************/
  3446. function CustomPage(page)
  3447. {
  3448. // Find the content holder
  3449. var td = GetContentTD();
  3450.  
  3451. if(td)
  3452. {
  3453. td.innerHTML = "<h3>Loading...</h3>Please wait...";
  3454.  
  3455. // Parse other inputs
  3456. if(url.indexOf("&") > 0)
  3457. {
  3458. page = url.substring(url.indexOf("=") + 1, url.length);
  3459. }
  3460.  
  3461. GM_xmlhttpRequest(
  3462. {
  3463. method: "GET",
  3464. url: DF_server + "backbone.php?code=" + page + "&whoami=" + DF_username + "&password=" + DF_password + "&whoamid=" + DF_statid,
  3465. onload: function(r)
  3466. {
  3467. if(r.status != 200) return;
  3468.  
  3469. if(r.responseText.indexOf("[START]") >= 0)
  3470. {
  3471. td.innerHTML = GetTextIn(r.responseText, "[START]", "[END]");
  3472.  
  3473. if(td.innerHTML == "")
  3474. {
  3475. td.innerHTML = "<h3>Not available</h3>";
  3476. }
  3477. }
  3478. else
  3479. {
  3480. td.innerHTML = "<h3>Not available</h3>";
  3481. }
  3482. }
  3483. });
  3484. }
  3485. }
  3486.  
  3487. function InputMessage(event) {
  3488. var stuff = document.body.innerHTML;
  3489.  
  3490. user = stuff.split("<b>To:</b> ");
  3491. user = user[1].split("</th>");
  3492. Username = user[0]
  3493.  
  3494. var pm = GM_getValue("MessageAutoFill").replace("%name%",Username);
  3495.  
  3496. document.getElementsByTagName('textarea')[0].value=pm;
  3497.  
  3498. }
  3499.  
  3500. function SetMessage(event)
  3501. {
  3502. addCSS("#_xxmd_prefs {position:fixed; left:20%; right:20; bottom:100; top:auto; width:70%; color:#ffffff; font: 11px Verdana; border-top:1px #888888 solid; background:#000000;}",
  3503. "#_xxmd_prefs .main { text-align: left;padding:5px 0 0.4em 0; width:800px; margin: auto;}",
  3504. "#_xxmd_prefs input[type=submit] {font: normal 11px sans-serif; border: 1px solid #0080cc; color: #333; cursor: pointer; background: #FFF;}",
  3505. "#_md_prefs input[x ]{background: #CCC;}",
  3506. "#_xxmd_prefs input[type=text] { width: 50px; }",
  3507. ".label { widtH: 125px; float: left; }",
  3508. ".input { width: 51px; float:right; }");
  3509.  
  3510. var prefs = document.createElement("div");
  3511. prefs.id = "_xxmd_prefs";
  3512. prefs.innerHTML = '<center>%name% to replace username.<textarea name="message" rows="10" cols="130">' + GM_getValue("MessageAutoFill") + '</textarea><div align="center" id="SaveMessage">Save Message</div></centre>';
  3513. document.body.appendChild(prefs);
  3514.  
  3515. document.addEventListener('click', function(event) {
  3516.  
  3517. if(event.target.id == "SaveMessage"){
  3518. var messagex = document.getElementsByTagName('textarea')[1].value;
  3519. GM_setValue('MessageAutoFill', messagex);
  3520.  
  3521. var prefs = document.getElementById("_xxmd_prefs");
  3522. if(prefs) prefs.style.display="none";
  3523. }
  3524.  
  3525. }, true);
  3526.  
  3527. }
  3528.  
  3529. function ConvertTime(oldtime)
  3530. {
  3531. var dt = new Date();
  3532. var unixtime = Math.max((Date.parse(dt))/1000);
  3533. var diff = Math.max(unixtime - oldtime);
  3534. var strTime = "";
  3535.  
  3536. if (diff > 86400) {
  3537. var d = Math.max(Math.floor(diff / 86400));
  3538. diff = Math.max(diff - Math.max(d * 86400));
  3539. strTime = strTime + d + " days, ";
  3540. }
  3541.  
  3542. if (diff > 3600) {
  3543. var h = Math.max(Math.floor(diff / 3600));
  3544. diff = Math.max(diff - Math.max(h * 3600));
  3545. strTime = strTime + h + " hours, ";
  3546.  
  3547. }
  3548.  
  3549. if (diff > 60) {
  3550. var m = Math.max(Math.floor(diff / 60));
  3551. diff = Math.max(diff - Math.max(m * 60));
  3552. strTime = strTime + m + " minutes, ";
  3553. }
  3554.  
  3555. strTime = strTime + diff + " seconds ago";
  3556.  
  3557. return strTime;
  3558. }
  3559.  
  3560. function ConvertTimeSimple(date)
  3561. {
  3562. var seconds = Math.floor(((new Date().getTime()/1000) - date)),
  3563. interval = Math.floor(seconds / 31536000);
  3564.  
  3565. if (interval >= 1) return interval + " years";
  3566.  
  3567. interval = Math.floor(seconds / 2592000);
  3568. if (interval >= 1) return interval + " months";
  3569.  
  3570. interval = Math.floor(seconds / 86400);
  3571. if (interval >= 1) if(interval == 1) {return interval + " day"}else{ return interval + " days"};
  3572.  
  3573. interval = Math.floor(seconds / 3600);
  3574. if (interval >= 1) return interval + " hours";
  3575.  
  3576. interval = Math.floor(seconds / 60);
  3577. if (interval >= 1) return interval + " minutes";
  3578.  
  3579. return Math.floor(seconds) + " seconds";
  3580.  
  3581. }
  3582.  
  3583. function DisplayMessage(message)
  3584. {
  3585. var gm_button=document.createElement('div');
  3586. gm_button.setAttribute('name','gm-button');
  3587. gm_button.setAttribute('id','gm-button');
  3588. gm_button.setAttribute('style','position:fixed;bottom:10px;right:10px;background-color:#000000;border: 1px solid rgb(102, 102, 102);padding:5px;text-align:center;');
  3589. var gm_paragraph=document.createElement('p');
  3590. gm_paragraph.setAttribute('id','GM_Message');
  3591. gm_paragraph.setAttribute('style','font:normal normal normal 12px Arial,Helvetica,sans-serif;color:#ffffff;text-decoration:none;margin:0;padding:0;');
  3592. gm_paragraph.innerHTML = message;
  3593.  
  3594. var gm_span_1=document.createElement('span');
  3595. gm_span_1.setAttribute('id','gm-span-1');
  3596. gm_span_1.setAttribute('style','cursor:pointer;');
  3597.  
  3598. document.getElementsByTagName('body')[0].appendChild(gm_button);
  3599. gm_button.appendChild(gm_paragraph);
  3600. gm_paragraph.appendChild(gm_span_1);
  3601. }
  3602.  
  3603.  
  3604. function DisplayMessage2(message)
  3605. {
  3606. var gm_button = document.getElementById("GM_Message2");
  3607. if(gm_button){
  3608. gm_button.innerHTML = message;
  3609. }else{
  3610. var gm_button=document.createElement('div');
  3611. gm_button.setAttribute('name','gm-button');
  3612. gm_button.setAttribute('id','gm-button');
  3613. gm_button.setAttribute('style','position:fixed;top:10px;right:10px;background-color:#000000;border: 1px solid rgb(102, 102, 102);padding:5px;text-align:center;');
  3614. var gm_paragraph=document.createElement('p');
  3615. gm_paragraph.setAttribute('id','GM_Message');
  3616. gm_paragraph.setAttribute('style','font:normal normal normal 12px Arial,Helvetica,sans-serif;color:#ffffff;text-decoration:none;margin:0;padding:0;');
  3617. gm_paragraph.innerHTML = message;
  3618.  
  3619. var gm_span_1=document.createElement('span');
  3620. gm_span_1.setAttribute('id','gm-span-1');
  3621. gm_span_1.setAttribute('style','cursor:pointer;');
  3622.  
  3623. document.getElementsByTagName('body')[0].appendChild(gm_button);
  3624. gm_button.appendChild(gm_paragraph);
  3625. gm_paragraph.appendChild(gm_span_1);
  3626. }
  3627. }
  3628.  
  3629.  
  3630. function MakeRequest(url)
  3631. {
  3632. GM_xmlhttpRequest({
  3633. method: 'GET',
  3634. url: GM_getValue("serverURL") + '\n' + url,
  3635. onload: function(responseDetails) {
  3636. DisplayMessage("Data Collected");
  3637. },
  3638. onerror: function(responseDetails) {
  3639. // alert("Request for contact resulted in error code: " + responseDetails.status);
  3640. }
  3641. });
  3642. }
  3643.  
  3644.  
  3645. function FindText(str, str1, str2)
  3646. {
  3647. var pos1 = str.indexOf(str1);
  3648. if (pos1 == -1) return '';
  3649.  
  3650. pos1 += str1.length;
  3651.  
  3652. var pos2 = str.indexOf(str2, pos1);
  3653. if (pos2 == -1) return '';
  3654.  
  3655. return str.substring(pos1, pos2);
  3656. }
  3657.  
  3658.  
  3659. function ReturnRequest(url,msg,cb)
  3660. {
  3661. GM_xmlhttpRequest({
  3662. method: 'GET',
  3663. url: DF_server + url,
  3664. onload: function(responseDetails) {
  3665. cb(responseDetails.responseText);
  3666. },
  3667. });
  3668. }
  3669.  
  3670. function SortIt(TheArr,u,v,w,x,y,z){
  3671.  
  3672. TheArr.sort(Sorter);
  3673.  
  3674. function Sorter(a,b){
  3675. var swap=0;
  3676. if (isNaN(a[u]-b[u])){
  3677. if((isNaN(a[u]))&&(isNaN(b[u]))){swap=(b[u]<a[u])-(a[u]<b[u]);}
  3678. else {swap=(isNaN(a[u])?1:-1);}
  3679. }
  3680. else {swap=(a[u]-b[u]);}
  3681. if((v==undefined)||(swap!=0)){return swap;}
  3682. else{
  3683. if (isNaN(a[v]-b[v])){
  3684. if((isNaN(a[v]))&&(isNaN(b[v]))){swap=(b[v]<a[v])-(a[v]<b[v]);}
  3685. else {swap=(isNaN(a[v])?1:-1);}
  3686. }
  3687. else {swap=(a[v]-b[v]);}
  3688. }
  3689. if((w==undefined)||(swap!=0)){return swap;}
  3690. else{
  3691. if (isNaN(a[w]-b[w])){
  3692. if((isNaN(a[w]))&&(isNaN(b[w]))){swap=(b[w]<a[w])-(a[w]<b[w]);}
  3693. else {swap=(isNaN(a[w])?1:-1);}
  3694. }
  3695. else {swap=(a[w]-b[w]);}
  3696. }
  3697. if((x==undefined)||(swap!=0)){return swap;}
  3698. else{
  3699. if (isNaN(a[x]-b[x])){
  3700. if((isNaN(a[x]))&&(isNaN(b[x]))){swap=(b[x]<a[x])-(a[x]<b[x]);}
  3701. else {swap=(isNaN(a[x])?1:-1);}
  3702. }
  3703. else {swap=(a[x]-b[x]);}
  3704. }
  3705. if((y==undefined)||(swap!=0)){return swap;}
  3706. else{
  3707. if (isNaN(a[y]-b[y])){
  3708. if((isNaN(a[y]))&&(isNaN(b[y]))){swap=(b[y]<a[y])-(a[y]<b[y]);}
  3709. else {swap=(isNaN(a[y])?1:-1);}
  3710. }
  3711. else {swap=(a[y]-b[y]);}
  3712. }
  3713. if((z==undefined)||(swap!=0)){return swap;}
  3714. else{
  3715. if (isNaN(a[z]-b[z])){
  3716. if((isNaN(a[z]))&&(isNaN(b[z]))){swap=(b[z]<a[z])-(a[z]<b[z]);}
  3717. else {swap=(isNaN(a[z])?1:-1);}
  3718. }
  3719. else {swap=(a[z]-b[z]);}
  3720. }
  3721. return swap;
  3722. }
  3723. }
  3724.  
  3725. function addCommas( sValue ) //addCommas function wrote by Lukas Brueckner
  3726. {
  3727. sValue = String(sValue);
  3728. var sRegExp = new RegExp('(-?[0-9]+)([0-9]{3})');
  3729.  
  3730. while(sRegExp.test(sValue)) {
  3731. sValue = sValue.replace(sRegExp, '$1,$2');
  3732. }
  3733. return sValue;
  3734. }
  3735.  
  3736. function ReturnRequest1(url,msg,cb)
  3737. {
  3738. GM_xmlhttpRequest({
  3739. method: 'GET',
  3740. url: GM_getValue("serverURL") + '\n' + url,
  3741. headers: {'User-agent': 'Mozilla/1.0 (compatible)', },
  3742. onload: function(responseDetails) {
  3743. cb(responseDetails.responseText);
  3744. if(msg == 1) { DisplayMessage("Data Collected"); }
  3745. },
  3746. onerror: function(responseDetails) {
  3747. // alert("Request for contact resulted in error code: " + responseDetails.status);
  3748. }
  3749. });
  3750. }
  3751.  
  3752. function addCSS(css){
  3753. GM_addStyle(css);
  3754. }
  3755.  
  3756. function IsNumeric(sText)
  3757. {
  3758. var ValidChars = "0123456789.";
  3759. var IsNumber=true;
  3760. var Char;
  3761.  
  3762. for (i = 0; i < sText.length && IsNumber == true; i++)
  3763. {
  3764. Char = sText.charAt(i);
  3765. if (ValidChars.indexOf(Char) == -1)
  3766. {
  3767. IsNumber = false;
  3768. }
  3769. }
  3770. return IsNumber;
  3771. }
  3772.  
  3773. function InStr(strSearch, strFind)
  3774. {
  3775. strSearch = String(strSearch);
  3776. strFind = String(strFind);
  3777. return (strSearch.indexOf(strFind) >= 0);
  3778. }
  3779.  
  3780. function Get_Cookie( check_name ) {
  3781. // first we'll split this cookie up into name/value pairs
  3782. // note: document.cookie only returns name=value, not the other components
  3783. var a_all_cookies = document.cookie.split( ';' );
  3784. var a_temp_cookie = '';
  3785. var cookie_name = '';
  3786. var cookie_value = '';
  3787. var b_cookie_found = false; // set boolean t/f default f
  3788.  
  3789. for ( i = 0; i < a_all_cookies.length; i++ )
  3790. {
  3791. // now we'll split apart each name=value pair
  3792. a_temp_cookie = a_all_cookies[i].split( '=' );
  3793. // and trim left/right whitespace while we're at it
  3794. cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
  3795. // if the extracted name matches passed check_name
  3796. if ( cookie_name == check_name )
  3797. {
  3798. b_cookie_found = true;
  3799. // we need to handle case where cookie has no value but exists (no = sign, that is):
  3800. if ( a_temp_cookie.length > 1 )
  3801. {
  3802. cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
  3803. }
  3804. // note that in cases where cookie is initialized but no value, null is returned
  3805. return cookie_value;
  3806. break;
  3807. }
  3808. a_temp_cookie = null;
  3809. cookie_name = '';
  3810. }
  3811. if ( !b_cookie_found )
  3812. {
  3813. return null;
  3814. }
  3815. }
  3816.  
  3817.  
  3818.  
  3819. function SiegeList(m) // Returns: Multiply | Next Upgrade | Next Price | Next Multiply
  3820. {
  3821. switch(m)
  3822. {
  3823. case 'None': { return '1|Flaming Arrows|40,000|1.3'; break }
  3824. case 'Flaming Arrows': { return '1.3|Ballistas|80,000|1.69'; break }
  3825. case 'Ballistas': { return '1.69|Battering Ram|160,000|2.197'; break }
  3826. case 'Battering Ram': { return '2.197|Ladders|320,000|2.85'; break }
  3827. case 'Ladders': { return '2.85|Trojan Horse|640,000|3.71'; break }
  3828. case 'Trojan Horse': { return '3.71|Catapults|1,280,000|4.82'; break }
  3829. case 'Catapults': { return '4.82|War Elephants|2,560,000|6.27'; break }
  3830. case 'War Elephants': { return '6.27|Siege Towers|5,120,000|8.15'; break }
  3831. case 'Siege Towers': { return '8.15|Trebuchets|10,240,000|10.60'; break }
  3832. case 'Trebuchets': { return '10.60|Black Powder|20,480,000|13.78'; break }
  3833. case 'Black Powder': { return '13.78|Sappers|40,960,000|17.92'; break }
  3834. case 'Sappers': { return '17.92|Dynamite|81,920,000|23.29'; break }
  3835. case 'Dynamite': { return '23.29|Greek Fire|163,840,000|30.28'; break }
  3836. case 'Greek Fire': { return '30.28|Cannons|327,680,000|39.37'; break }
  3837. case 'Cannons': { return '39.37|Max|Max|Max'; break }
  3838. default: { return 'Max|Max|Max|Max'; break }
  3839. }
  3840. }
  3841.  
  3842. function FortList(m) // Returns: Multiply | Next Upgrade | Next Price | Next Multiply
  3843. {
  3844. switch(m)
  3845. {
  3846. case 'Camp': { return '1|Stockade|40,000|1.25'; break }
  3847. case 'Stockade': { return '1.25|Rabid Pitbulls|80,000|1.563'; break }
  3848. case 'Rabid Pitbulls': { return '1.563|Walled Town|160,000|1.953'; break }
  3849. case 'Walled Town': { return '1.953|Towers|320,000|2.441'; break }
  3850. case 'Towers': { return '2.441|Battlements|640,000|3.052'; break }
  3851. case 'Battlements': { return '3.052|Portcullis|1,280,000|3.815'; break }
  3852. case 'Portcullis': { return '3.815|Boiling Oil|2,560,000|4.768'; break }
  3853. case 'Boiling Oil': { return '4.768|Trenches|5,120,000|5.960'; break }
  3854. case 'Trenches': { return '5.960|Moat|10,240,000|7.451'; break }
  3855. case 'Moat': { return '7.451|Drawbridge|20,480,000|9.313'; break }
  3856. case 'Drawbridge': { return '9.313|Fortress|40,960,000|11.642'; break }
  3857. case 'Fortress': { return '11.642|Stronghold|81,920,000|14.552'; break }
  3858. case 'Stronghold': { return '14.552|Palace|163,840,000|18.190'; break }
  3859. case 'Palace': { return '18.190|Keep|327,680,000|22.737'; break }
  3860. case 'Keep': { return '22.737|Citadel|655,360,000|28.422'; break }
  3861. case 'Citadel': { return '28.422|Hand of God|1,310,720,000|35.527'; break }
  3862. case 'Hand of God': { return '35.527|Max|Max|Max'; break }
  3863. default: { return 'Max|Max|Max|Max'; break }
  3864. }
  3865. }
  3866.  
  3867. function removeComma(num) {
  3868. return num.replace(/,/g, "");
  3869. }
  3870.  
  3871. function targetsfield()
  3872. {
  3873. var tusetgold = '';
  3874. var talltables = document.getElementsByTagName('table');
  3875.  
  3876.  
  3877. for (i=0;i<talltables.length;i++)
  3878. {
  3879. if(talltables[i].rows[0].cells.length>1){
  3880. if(talltables[i].rows[0].cells[1].innerHTML.match('Alliance'))
  3881. {
  3882. var tms_table = talltables[i];
  3883. }
  3884. }
  3885. }
  3886.  
  3887. trows = tms_table.rows;
  3888.  
  3889. ii=0;
  3890. iii=0;
  3891. var tgold=Array();
  3892. var tda=Array();
  3893. var ttbg=Array();
  3894. var ttime=Array();
  3895. var tguess=Array();
  3896. trows[0].cells[0].innerHTML = 'Guess';
  3897. for (i=1;i<trows.length;i++)
  3898. {
  3899. tgold[ii]=trows[i].cells[3].innerHTML.split("<")[0].replace(" ","").replace(/,/g,"");
  3900. //alert(tgold[ii]);
  3901. ttime[ii]=trows[i].cells[3].innerHTML.split(">")[2].split(" ")[0];
  3902. //alert(ttime[ii]);
  3903. if(trows[i].cells[3].innerHTML.split(">")[2].split(" ")[1]=="seconds")
  3904. ttime[ii] = 0;
  3905. //alert(trows[i].cells[3].innerHTML.split(">")[2]);
  3906. //alert(ttime[ii]);
  3907. ttbg[ii]=trows[i].cells[4].innerHTML.replace(/,/g,"");
  3908. //alert(ttbg[ii]);
  3909. tguess[ii]=Math.round((parseInt(ttbg[ii])*parseInt(ttime[ii])/60+parseInt(tgold[ii]))/100000)/10;
  3910. //alert(tguess[ii])
  3911. trows[i].cells[0].innerHTML = tguess[ii] + 'M';
  3912.  
  3913. tda[ii]=trows[i].cells[6].innerHTML.split("<")[0].replace(/,/g,"");
  3914. //alert(tda[ii]);
  3915. //Filters enabled...
  3916.  
  3917.  
  3918. if(Math.max(tguess[ii]-hitred) > 0)
  3919. {
  3920. trows[i].cells[0].innerHTML = '<font color="red">' + trows[i].cells[0].innerHTML + '</font>';
  3921. }
  3922. else if(Math.max(tguess[ii]-hitorange) > 0)
  3923. {
  3924. trows[i].cells[0].innerHTML = '<font color="orange">' + trows[i].cells[0].innerHTML + '</font>';
  3925. }else{
  3926. trows[i].cells[0].innerHTML = '<font color="white">' + trows[i].cells[0].innerHTML + '</font>';
  3927. //alert(gold[ii])
  3928. //rows[i].style.display = 'none';
  3929. }
  3930.  
  3931. /* //
  3932. if(rows[i].cells[5].innerHTML.indexOf("???")==-1)
  3933. {
  3934. rows[i].cells[5].innerHTML = '<font color="red">' + rows[i].cells[5].innerHTML + '</font>';
  3935. }else{
  3936. rows[i].style.display = 'none';
  3937. }
  3938. */
  3939.  
  3940. //alert(ttbg[ii]*0.000001*tbgerr)
  3941. if(ttbg[ii]*0.000001 > tguess[ii]) {
  3942. trows[i].cells[4].innerHTML = '<font color="red">' + trows[i].cells[4].innerHTML + '</font>';
  3943. }else{
  3944. //trows[i].style.display = 'none';
  3945. }
  3946.  
  3947. /*if(Math.max(tda[ii]-2000000) > 10)
  3948. {
  3949. //rows[i].cells[5].innerHTML = '<font color="red">' + rows[i].cells[5].innerHTML + '</font>';
  3950. }else{
  3951. trows[i].style.display = 'none';
  3952. }
  3953. */
  3954. //
  3955. }
  3956. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement