Colonies Administration

Add more info to the colony administration page

  1. // ==UserScript==
  2. // @name Colonies Administration
  3. // @namespace bitbucket.org/Odahviing
  4. // @include http://www.war-facts.com/overview.php?view=1
  5. // @version 1.2
  6. // @description Add more info to the colony administration page
  7. // @grant GM_getValue
  8. // @grant GM_setValue
  9. // ==/UserScript==
  10.  
  11. // Version 1.0 - Add Total Size and Density
  12. // Version 1.1 - Add Ship Upkeep
  13. // Version 1.2 - Add Avg population // need to re build the script - not write good
  14.  
  15. function manyReplaces(text, amount)
  16. {
  17. for (var index = 0; index <amount; index++)
  18. text = text.replace(',','');
  19. return text;
  20. }
  21.  
  22. function realNumber(text)
  23. {
  24. return Number(text).toLocaleString('en');
  25. }
  26.  
  27.  
  28. var title = document.getElementsByClassName('dark bold centertext largetext150 padding5 box tbborder')[0];
  29.  
  30. if (title.innerHTML == "C O L O N Y &nbsp;&nbsp; A D M I N I S T R A T I O N")
  31. {
  32. var colonyLine = document.getElementsByClassName('padding5 tbborder fullwidth')[0];
  33. var colonyAmount = colonyLine.innerHTML.split(' ')[2];
  34. var peopleLine = document.getElementsByClassName('padding5 tbborder fullwidth')[1];
  35. var peopleAmount = peopleLine.innerHTML.split(' ')[2];
  36.  
  37. peopleAmount = manyReplaces(peopleAmount,2);
  38. var value = GM_getValue('size');
  39. var density = parseInt(peopleAmount) / value;
  40. peopleLine.outerHTML += "<div class='padding5 tbborder fullwidth'>Total Size: " +
  41. realNumber(value) + " (" + density.toFixed(2) + " Density)</div>";
  42. var incomeLine = document.getElementsByClassName('padding5 tbborder fullwidth')[4];
  43. var tmp = document.getElementsByTagName('li')[9];
  44. var totalIncome = tmp.innerHTML.substring(tmp.innerHTML.indexOf('alt="income"') +14);
  45. totalIncome = manyReplaces(totalIncome.substring(0, totalIncome.indexOf('cr')),3);
  46. var income = manyReplaces(incomeLine.innerHTML.substring
  47. (incomeLine.innerHTML.indexOf(' ') + 1,
  48. incomeLine.innerHTML.indexOf('cr'))
  49. ,3);
  50. var ship = parseInt(income) - parseInt(totalIncome);
  51. var corruptionLine = document.getElementsByClassName('padding5 tbborder fullwidth')[3];
  52. corruptionLine.innerHTML = "Ship Upkeep: " + Number(ship).toLocaleString('en') + " cr";
  53. avgPop = realNumber(Math.round(parseInt(peopleAmount) / parseInt(colonyAmount)));
  54. incomeLine.outerHTML += "<div class='padding5 tbborder fullwidth'>Avg Population: " + avgPop;
  55. }
  56. else
  57. {
  58. var mainTable = document.getElementsByClassName('width100 box lineheight')[0];
  59. var allColonies = mainTable.getElementsByClassName('dark padding5');
  60. var allSize = 0;
  61. for (var index = 0; index < allColonies.length; index++)
  62. {
  63. var colonyFrame = allColonies[index].getElementsByClassName('strong');
  64. var sizeLine = colonyFrame[3].innerHTML;
  65. var popLine = colonyFrame[1].innerHTML;
  66. var size = parseInt(sizeLine.substring(0, sizeLine.indexOf(' ')).replace(",","").replace(",",""));
  67. var pop = parseInt(popLine.substring(0, popLine.indexOf(' ')).replace(",","").replace(",",""));
  68.  
  69. allSize += size;
  70. allColonies[index].getElementsByClassName('head')[1].innerHTML += "&nbsp;(" + (pop/size).toFixed(2) + " d)";
  71. }
  72.  
  73. GM_setValue('size', allSize);
  74. }