Verified:

TheMafia Game profile

Member
62

May 20th 2015, 4:36:15

INSTALLATION STEPS AT BOTTOM OF THIS POST UNDER 'SETUP'

What it does ================================================

Score Board: http://tcpm.mrlazyinc.com/..._monkey_script_scores.PNG
Portal Leader Boards: http://tcpm.mrlazyinc.com/...monkey_script_leaders.PNG
Market (v2): http://tcpm.mrlazyinc.com/..._monkey_script_market.PNG
Research (v3): http://tcpm.mrlazyinc.com/...onkey_script_research.PNG
Browser Tab Title (v3): http://tcpm.mrlazyinc.com/..._script_browser_title.PNG
Buildings (v4): http://tcpm.mrlazyinc.com/...nkey_script_buildings.PNG
Building Percentage (v6.8): http://tcpm.mrlazyinc.com/...key_script_build_perc.PNG
Spy (v6): http://tcpm.mrlazyinc.com/...y_script_spy_military.PNG
NEW: -- Turns Left (v6.5): http://tcpm.mrlazyinc.com/...key_script_turns_left.PNG
NEW: -- Attacker defending news summary (7.5): LINK INC.

This script will automate a lot of tedious tasks and do a lot of calculations for you on the fly.

Latest Changes ================================================
Version 8.0 (Dec 2022):
-Fixed an issue with news summary that crashed the script when calculating land for a victorious defense

Version 7.9 (Nov 2022):
-First attempt at fixing news not showing after you get special messages from the game, news would be hidden due to the code calling for news summary too soon and marking it as 'read' in the background, may not have fixed all situations yet, will add more as I see them come up

Version 7.8 (Oct 2022):
-Proud to say you no longer have to click on the 'defending' link to show the news summary, with some fun code this is now available on your main page immediately
-Colour coding has begun in the news summary, next up: total units exchanged for each player

Version 7.6 (Oct 2022):
-Added the number of attacks a player has done to news summary of land lost.

Version 7.5 (Oct 2022):
-New featured start: News summary. This will show you all the players who have attacked you and the amount of land they took total for this round.
Note: This will ONLY show when you are looking at news for your country, for best results click on "Defending" in the news links so that the script can see all attacks and not just for one day.

Version 7.1 (Sept 2022):
-Fixed turns lefts: no more decimals

Version 7.0 (Sept 2022):
-remake of the 'turns left' calculation on 'main menu' (now shows remaining turns correctly for the round)

Version 6.97 (Sept 2022):
-Fixed market tax calculation issue for Democracy (no market tax)

Version 6.95:
-Explore automatically adds '1' to field instead of default of '0'

Version 6.9:
-minor fix for building percentages (total count was off)

Version 6.8:
-New feature: in building page you will now see the percentage each building type occupies on your land.
--Total land is now displayed above the percentages column (see pic)

Version 6.5:
-"Turns Left" added to main page (picture above)
--based on the server you are playing on, the script will try to estimate how many turns you can expect in the future from this moment on.

!Version 6.1:
-fixed calculations to show:
--Defence Points
--Minimum Jets to send


Setup / Installation ================================================

Required:
Browser (like chrome) with a javascript auto execute add on (like 'TamperMonkey', google it) or equvilent
add on needs to support including jQuery library

What you need to do:
Lets say you use tamperMonkey and chrome.
-Open the dashboard for tampermonkey
-start a new script
-copy the script from below into the new page.



// ==UserScript==
// @name EarthEmpires - Assit Tools and Calculations
// @namespace http://www.mrlazyinc.com/
// @version 8.0
// @author TheMafia
// @match *://*.earthempires.com/*
// @match *://earthempires.com/*
// @require http://code.jquery.com/jquery-latest.js
// ==/UserScript==


var currentPage = window.location.href;
var turns = jQuery(".topbar td:contains('Turns:')").last().text().replace("Turns: ", "");
var money = jQuery(".topbar td:contains('Money:')").last().text().replace("Money: ", "");
document.title = "T:("+ turns + ")" + "M:"+ money;

if ((currentPage.indexOf("scores") > 0 || (currentPage.indexOf("market") > 0 && currentPage.indexOf("sell") < 1)) && currentPage.indexOf("forum") <= 0) {
var intv = setTimeout(function(){
var curPage = window.location.href;
window.location = curPage;
}, 60000);
}

if (currentPage.indexOf("explore") > 0){
//Add 1 to field
jQuery("input[name='turns']").val(1);

}


if (currentPage.indexOf("spy") > 0){
//Check if spied
if (jQuery("th:contains('Military Forces')").length > 0){
var parentBody = jQuery("th:contains('Military Forces')").parent().parent();
jQuery(parentBody).append("<tr><td>Defence Points</td><td class='rt' id='forceCalc'></td></tr>");
jQuery(parentBody).append("<tr><td>Min Jets Hit:</td><td class='rt' id='jetCalc'></td></tr>");

var troops = parseInt(jQuery(parentBody).find("tr").eq(2).find("td").eq(1).text().replace(",","").replace(",","")) ;
var turrets = parseInt(jQuery(parentBody).find("tr").eq(4).find("td").eq(1).text().replace(",","").replace(",",""));
var tanks = parseInt(jQuery(parentBody).find("tr").eq(5).find("td").eq(1).text().replace(",","").replace(",",""));
console.log("1: "+ troops + " -2:"+ turrets +" -3:"+ tanks);

var attackMin = (troops) + turrets*2 + (tanks *4);
var jetMin = attackMin / 2;
jQuery("#forceCalc").text(attackMin);
jQuery("#jetCalc").text(jetMin);
}
}


if (currentPage.indexOf("main") > 0){
//Check if spied
var serverType = jQuery("td:contains('Server')").next("td").text();
var timeLeft = jQuery("#maintable").next().next().text();
var turnsLeft = 0;
var timeInterval = 1;
switch(serverType){
case "Express":
timeInterval = 4;
break;
case "Tournament":
timeInterval = 25;
break;
case "Primary":
timeInterval = 30;
break;
case "Team":
timeInterval = 15;
break;
case "Alliance":
timeInterval = 20;
break;
case "Free For All":
timeInterval = 20;
break;
}

if (timeLeft.indexOf("hours") > 0){
timeLeft = timeLeft.replace("The round ends in ", "");
timeLeft = timeLeft.replace("hours.", "");
turnsLeft = (60 * parseFloat(timeLeft)) / timeInterval;
}else if (timeLeft.indexOf("days") > 0){
timeLeft = timeLeft.replace("The round ends in ", "");
timeLeft = timeLeft.replace("days.", "");
turnsLeft = (60 * 24 *parseFloat(timeLeft)) / timeInterval;
}
jQuery("#maintable").next().next().append("<br>Turns left: "+ Math.round(turnsLeft));

jQuery("body").append("<div id='newsSummary' style='position:fixed; top:20px; right: 20px; color:white'></div><div id='newsPull' display='none'></div>");


var tempHTML = jQuery.parseHTML("");

if(jQuery(".recentnewsitem").length == 0 && jQuery("a:contains('Continue to Main Page')").length < 1){
var defUrl = jQuery("#content a:contains('Defending')").attr("href");
console.log(defUrl);

var ajDefending = jQuery.ajax({
url:defUrl, async:true, cache:false, method: "GET"})
.always(function(){

}).done(function(data){
tempHTML = jQuery.parseHTML(data);
//console.log(jQuery(tempHTML).find(".recentnewsitem").html());
//jQuery("#newsPull").html(jQuery(tempHTML).find(".recentnewsitem").html());
var attackers = [];
var playerCount = 0;
jQuery(tempHTML).find(".recentnewscontent:contains('A brigade from')").each(function(){
console.log("tesT");
var sStart = jQuery(this).text().indexOf("A brigade from") + 15;
var sEnd = jQuery(this).text().indexOf(" has invaded your lands");
var attackerName = jQuery(this).text().slice(sStart, sEnd);
var regNum = /\(#(.+?)\)/g;
var attackerNum = jQuery(this).text().match(regNum)[0].replace("(#", "").replace(")", "");

var curIndex = -1;
for(var i = 0; i < attackers.length; i++){
if(attackers[i].attackerNum == attackerNum){
curIndex = i;
break;
}
}

var lostContainer = jQuery(this).find("div:contains('Acres')");
regNum = /.+? Acres/g;
var landLost = parseInt(lostContainer.text().match(regNum)[0].replace(" Acres", ""));

if(curIndex > -1){
attackers[curIndex].land = attackers[curIndex].land + landLost;
attackers[curIndex].attCnt = attackers[curIndex].attCnt + 1;
}else{
attackers[attackers.length] = {attackerName: attackerName, attackerNum: attackerNum, land: landLost, attCnt: 1};
}


});

for(var i = 0; i < attackers.length; i++){
var colour = "white";
if (attackers[i].attCnt > 1){
colour = "yellow";
}
jQuery("#newsSummary").append("<div class='attackerInfo' style='text-align:right; color:"+ colour +"'>"+ attackers[i].attackerName + " "+ attackers[i].attCnt +" times, took: "+ attackers[i].land +"</div>");
}

}).fail(function(){

});
}else{
var attackers = [];
var playerCount = 0;
jQuery(document).find(".recentnewscontent:contains('A brigade from')").each(function(){
console.log("tesT");
var sStart = jQuery(this).text().indexOf("A brigade from") + 15;
var sEnd = jQuery(this).text().indexOf(" has invaded your lands");
var attackerName = jQuery(this).text().slice(sStart, sEnd);
var regNum = /\(#(.+?)\)/g;
var attackerNum = jQuery(this).text().match(regNum)[0].replace("(#", "").replace(")", "");

var curIndex = -1;
for(var i = 0; i < attackers.length; i++){
if(attackers[i].attackerNum == attackerNum){
curIndex = i;
break;
}
}
var landLost = 0;
var lostContainer = jQuery(this).find("div:contains('Acres')");
regNum = /.+? Acres/g;
if (lostContainer.length > 0){
landLost = parseInt(lostContainer.text().match(regNum)[0].replace(" Acres", ""));
}

if(curIndex > -1){
attackers[curIndex].land = attackers[curIndex].land + landLost;
attackers[curIndex].attCnt = attackers[curIndex].attCnt + 1;
}else{
attackers[attackers.length] = {attackerName: attackerName, attackerNum: attackerNum, land: landLost, attCnt: 1};
}


});

for(var i = 0; i < attackers.length; i++){
var colour = "white";
if (attackers[i].attCnt > 1){
colour = "yellow";
}
jQuery("#newsSummary").append("<div class='attackerInfo' style='text-align:right; color:"+ colour +"'>"+ attackers[i].attackerName + " "+ attackers[i].attCnt +" times, took: "+ attackers[i].land +"</div>");
}
}


}




if (currentPage.indexOf("market") > 0){
//Init settings
jQuery("table.contenttable tr").children("td:nth-child(7)").find("input").css({"width":"95px"});
jQuery("table.contenttable tr").children("td:nth-child(1)").each(function(){
jQuery(this).html(jQuery(this).html().replace("Military", "Mil."));
});
//jQuery(this).closest("tr").children("td:nth-child(7)").find("input").css({"width":"90px"});

var tempNum = 0;
var tempVal = 0;
var cashAmount = "";
var taxAdditive = 0;
if (jQuery(".mTax").length > 0){
taxAdditive = (jQuery(".mTax").html().replace("%", "").toLocaleString() / 100);
}else{
taxAdditive = 0;
}
var tax = 1 + taxAdditive;
jQuery("table.contenttable tr").has("td.lt").each(function(){
jQuery(this).find("td:nth-child(5), td:nth-child(6), td:nth-child(2)").hover(
function(){
tempNum = jQuery(this).html();
tempVal = jQuery(this).closest("tr").children("td:nth-child(7)").find("input").val();

cashAmount = "$" + Math.ceil((Math.round(jQuery(this).closest("tr").children("td:nth-child(3)").find("input").val()) * Math.round(jQuery(this).html().replace(",", "").replace(",", "").replace("$", "")) * tax)).toLocaleString();
//jQuery(this).html(cashAmount);
jQuery(this).closest("tr").children("td:nth-child(7)").find("input").val(cashAmount);

}, function(){
//jQuery(this).html(tempNum);
jQuery(this).closest("tr").children("td:nth-child(7)").find("input").val(tempVal);

}
).click(function(){
tempVal = jQuery(this).html(); //jQuery(this).closest("tr").children("td:nth-child(7)").find("input").val();
});
});
}

if (currentPage.indexOf("scores") > 0 || currentPage.indexOf("ranks") > 0 || currentPage.indexOf("clans") > 0){
var self = jQuery("td.c-own").html().split("(")[1].replace(")","");
var land = 0;
var networth = 0;
var perAcre = 0;
var rank = 0;
var selfPer = 0;
var selfLand = 0;
var selfNet = 0;
var selfRank = 0;

jQuery("p:contains('server.')").append(" <a target='_blank' href='http://www.eestats.com/';;;;;;;;;>EeStats</a>");

jQuery(".lt").each(function(){
if(jQuery(this).html().indexOf(self) > 1){
jQuery(this).css({"color":jQuery(this).find("td:nth-child(2)").css("color")});
selfRank = Math.round(jQuery(this).find("td:first").html());
document.title = "R:["+ selfRank +"]" + document.title;

jQuery(this).find(".rt").each(function(){
if (land === 0){
land = Math.round(jQuery(this).html().replace(",", "").replace(",", ""));
}else{
networth = Math.round(jQuery(this).html().replace(",", "").replace(",", "").replace("$", ""));
}
});
selfPer = Math.round(networth / land);
selfLand = Math.round(land);
selfNet = Math.round(networth);
}
});

jQuery(".lt").each(function(){
land = 0;
networth = 0;
perAcre = 0;
rank = 0;

jQuery(this).find("td:nth-child(2)").append(" ["+ jQuery(this).find(".ct").html() +"]");

rank = Math.round(jQuery(this).find("td:first").html());
jQuery(this).find(".rt").each(function(){
if (land === 0){
land = Math.round(jQuery(this).html().replace(",", "").replace(",", ""));
}else{
networth = Math.round(jQuery(this).html().replace(",", "").replace(",", "").replace("$", ""));
}
});
perAcre = Math.round(networth / land);
jQuery(this).find(".ct").html(perAcre);

if ((networth / 2) <= selfNet && (selfNet / 2) <= networth){
jQuery(this).find(".rt:eq(1)").css({"color":"yellow"});
//console.log(jQuery(this).find(".rt:eq(1)").html());
}
if (selfPer > (perAcre * 1.5)){
jQuery(this).find(".ct").css({"color":"red"});
}else if (selfPer > perAcre){
jQuery(this).find(".ct").css({"color":"yellow"});
}

if (((selfLand > land) && (selfRank > rank)) || ((selfLand < land) && (selfRank < rank))){
jQuery(this).find(".rt:first").css({"color":"red"});
}
});
}

if (currentPage.indexOf("research") > 0){
var tpt = Math.round(jQuery(".TPT").html().replace(/,/g, ''));
var curVal = 0.0;
var newVal = 0.0;
var tCount = 0;

jQuery(".turntable tr:nth-child(13)").find("td").append("<div id='tSpent' style='display:inline'></div>");
jQuery(".turntable tr.ct").each(function(){
if (jQuery(this).find("td input[value='Research Technology']").length == 0){
jQuery(this).find("td:nth-child(1)").click(function(evt){
curVal = Math.round(jQuery(this).closest("tr").find("input:text").val());
if(evt.ctrlKey){
mult = 5;
}else if(evt.altKey){
mult = 0.5;
}else{
mult = 1;
}
newVal = Math.floor(curVal + (tpt * mult));
tCount = tCount + mult;
jQuery(this).closest("tr").find("input:text").val(newVal);

jQuery("#tSpent").html(" ("+ tCount + ")");
});
}
});
}

if (currentPage.indexOf("build") > 0){
var bpt = Math.round(jQuery(".BPT").html());
var curVal = 0.0;
var newVal = 0.0;
var tCount = 0;

jQuery(".contenttable tr:nth-child(11)").find("td").append("<div id='tSpent' style='display:inline'></div>");
jQuery(".contenttable tr.rt").each(function(){
if (jQuery(this).find("td input[value='Construct Buildings']").length == 0){
jQuery(this).find("td:nth-child(1)").click(function(evt){
curVal = Math.round(jQuery(this).closest("tr").find("input:text").val());

if(evt.ctrlKey){
mult = 5;
}else if(evt.altKey){
mult = 0.5;
}else{
mult = 1;
}
newVal = Math.floor(curVal + (bpt * mult));
tCount = tCount + mult;
jQuery(this).closest("tr").find("input:text").val(newVal);

jQuery("#tSpent").html(" ("+ tCount + ")");
});
}
});

var totLand = 0;
jQuery(jQuery(".contenttable td.lt").next("td")).each(function(){
totLand += parseInt(jQuery(this).text());
});
totLand += parseInt(jQuery(".contenttable td:contains('Unused Land Area')").next("td").text().replace(" Acres","").replace(",","").replace(",",""));

jQuery(".contenttable").find("tr").each(function(i){
if (jQuery(this).find("th").length < 1){
jQuery(this).append("<td class='b"+ i +"'></td>");
}else{
jQuery(this).append("<th>"+ totLand +"</th>");
}
});

jQuery(jQuery(".contenttable td.lt, .contenttable td:contains('Unused Land Area')").next("td")).each(function(i){
if(parseInt(jQuery(this).text().replace(" Acres","").replace(",","").replace(",","")) > 0){
percB = (parseInt(jQuery(this).text().replace(" Acres","").replace(",","").replace(",","")) / totLand) * 100;
percB = percB.toFixed(2);
jQuery(".b"+(i+1)).text(percB + "%");
}
});

}
//end

Edited By: TheMafia on Dec 1st 2022, 22:28:11
Back To Thread
See Original Post
See Subsequent Edit