nightblade.greyswandir
Contributing Poster
- Reaction score
- 24
Can we have a script that will show the sum of res and average res per village in production view?
javascript:
if (window.location.href.indexOf('&screen=overview_villages&mode=prod') < 0 ){
//relocate
window.location.assign(game_data.link_base_pure + "overview_villages&mode=prod");
}
totalWood=0;
totalStone=0;
totalIron=0;
totalVillages = $("#production_table tr.nowrap").length;
for(var i =0; i< totalVillages;i++)
{
totalWood = parseInt(totalWood) + parseInt($($("#production_table tr.nowrap")[i].children[3].children[0]).text().replace(".",''));
totalStone = parseInt(totalStone) + parseInt($($("#production_table tr.nowrap ")[i].children[3].children[1]).text().replace(".",''));
totalIron = parseInt(totalIron) + parseInt($($("#production_table tr.nowrap ")[i].children[3].children[2]).text().replace(".",''));
}
if($("#counterTable").length>0) $("#counterTable").remove();
$("#content_value").eq(0).prepend(`<div id="counterTable"><table><tr><th><span class="icon header wood"></span>Total wood</th><th><span class="icon header stone"></span>Total clay</th><th><span class="icon header iron"></span>Total iron</th></tr><tr><td id="totalWood">` + numberWithCommas(totalWood) + `</td><td id="totalClay">` + numberWithCommas(totalStone) + `</td><td id="totalIron">` + numberWithCommas(totalIron) + `</td></tr>
<tr><th><span class="icon header wood"></span>Average wood per village</th><th><span class="icon header stone"></span>Average clay per village</th><th><span class="icon header iron"></span>Average iron per village</th></tr><tr><td id="averageWood">` + numberWithCommas(parseInt(totalWood/totalVillages)) + `</td><td id="averageClay">` + numberWithCommas(parseInt(totalStone/totalVillages)) + `</td><td id="averageIron">` + numberWithCommas(parseInt(totalIron/totalVillages)) + `</td></tr></table></div>`)
function numberWithCommas(x) {
x = x.toString();
var pattern = /(-?\d+)(\d{3})/;
while (pattern.test(x))
x = x.replace(pattern, "$1.$2");
return x;
}