Colonies Administration

Add more info to the colony administration page

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        Colonies Administration
// @namespace   bitbucket.org/Odahviing
// @include     http://www.war-facts.com/overview.php?view=1
// @version     1.2
// @description Add more info to the colony administration page
// @grant       GM_getValue
// @grant       GM_setValue
// ==/UserScript==

// Version 1.0 - Add Total Size and Density
// Version 1.1 - Add Ship Upkeep
// Version 1.2 - Add Avg population // need to re build the script - not write good

function manyReplaces(text, amount)
{
    for (var index = 0; index <amount; index++)
        text = text.replace(',','');
    return text;
}

function realNumber(text)
{
    return Number(text).toLocaleString('en');
}


var title = document.getElementsByClassName('dark bold centertext largetext150 padding5 box tbborder')[0];

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")
{
    var colonyLine = document.getElementsByClassName('padding5 tbborder fullwidth')[0];
    var colonyAmount = colonyLine.innerHTML.split(' ')[2];
    
    var peopleLine = document.getElementsByClassName('padding5 tbborder fullwidth')[1];
    var peopleAmount = peopleLine.innerHTML.split(' ')[2];

    peopleAmount = manyReplaces(peopleAmount,2);
    var value = GM_getValue('size');
    var density = parseInt(peopleAmount) / value;
    
    peopleLine.outerHTML += "<div class='padding5 tbborder fullwidth'>Total Size: " +
        realNumber(value)  + " (" + density.toFixed(2) + " Density)</div>";     
    var incomeLine = document.getElementsByClassName('padding5 tbborder fullwidth')[4];
    var tmp = document.getElementsByTagName('li')[9];
    var totalIncome = tmp.innerHTML.substring(tmp.innerHTML.indexOf('alt="income"') +14);
    totalIncome = manyReplaces(totalIncome.substring(0, totalIncome.indexOf('cr')),3);
    var income = manyReplaces(incomeLine.innerHTML.substring
          (incomeLine.innerHTML.indexOf(' ') + 1,
           incomeLine.innerHTML.indexOf('cr'))
                              ,3);
    var ship = parseInt(income) - parseInt(totalIncome);
    var corruptionLine = document.getElementsByClassName('padding5 tbborder fullwidth')[3];
    corruptionLine.innerHTML = "Ship Upkeep: " + Number(ship).toLocaleString('en') + " cr";
    avgPop = realNumber(Math.round(parseInt(peopleAmount) / parseInt(colonyAmount)));
    incomeLine.outerHTML += "<div class='padding5 tbborder fullwidth'>Avg Population: " + avgPop;
}
else
{
    var mainTable = document.getElementsByClassName('width100 box lineheight')[0];
    var allColonies = mainTable.getElementsByClassName('dark padding5');
    var allSize = 0;
    for (var index = 0; index < allColonies.length; index++)
    {
        var colonyFrame = allColonies[index].getElementsByClassName('strong');
        var sizeLine = colonyFrame[3].innerHTML;
        var popLine = colonyFrame[1].innerHTML;
        
        var size = parseInt(sizeLine.substring(0, sizeLine.indexOf(' ')).replace(",","").replace(",",""));
        var pop = parseInt(popLine.substring(0, popLine.indexOf(' ')).replace(",","").replace(",",""));

        allSize += size;
        allColonies[index].getElementsByClassName('head')[1].innerHTML +=  "&nbsp;(" + (pop/size).toFixed(2) + " d)";
    }

    GM_setValue('size', allSize);
}