egovatwar

Orders and shouts from Alliance Headquarters and Ministry of Defence

As of 06.01.2015. See ბოლო ვერსია.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name        egovatwar
// @namespace   egov4war
// @description Orders and shouts from Alliance Headquarters and Ministry of Defence
// @include     *.erepublik.com/*
// @version     0.2.4
// @author Serj_LV (aVie)
// @grant GM_getValue
// @grant GM_setValue
// ==/UserScript==

function egov4war_start () {

var egov4war = '0.2.4';
var scriptLink = 'http://openuserjs.org/';

var countries = {
	"Albania": 167,
	"Argentina": 27,
	"Armenia": 169,
	"Australia": 50,
	"Austria": 33,
	"Belarus": 83,
	"Belgium": 32,
	"Bolivia": 76,
	"Bosnia-Herzegovina": 69,
	"Bolivia": 76,
	"Brazil": 9,
	"Bulgaria": 42,
	"Canada": 23,
	"Chile": 64,
	"China": 14,
	"Colombia": 78,
	"Croatia": 63,
	"Cuba": 171,
	"Cyprus": 82,
	"Czech-Republic": 34,
	"Denmark": 55,
	"Egypt": 165,
	"Estonia": 70,
	"Finland": 39,
	"France": 11,
	"Georgia": 168,
	"Germany": 12,
	"Greece": 44,
	"Hungary": 13,
	"India": 48,
	"Indonesia": 49,
	"Iran": 56,
	"Ireland": 54,
	"Israel": 58,
	"Italy": 10,
	"Japan": 45,
	"Latvia": 71,
	"Lithuania": 72,
	"Malaysia": 66,
	"Mexico": 26,
	"Moldova": 52,
	"Montenegro": 80,
	"Netherlands": 31,
	"New-Zealand": 84,
	"Nigeria": 170,
	"North-Korea": 73,
	"Norway": 37,
	"Pakistan": 57,
	"Paraguay": 75,
	"Peru": 77,
	"Philippines": 67,
	"Poland": 35,
	"Portugal": 53,
	"Republic-of-China-Taiwan": 81,
	"Republic-of-Macedonia-FYROM": 79,
	"Romania": 1,
	"Russia": 41,
	"Saudi-Arabia": 164,
	"Serbia": 65,
	"Singapore": 68,
	"Slovakia": 36,
	"Slovenia": 61,
	"South-Africa": 51,
	"South-Korea": 47,
	"Spain": 15,
	"Sweden": 38,
	"Switzerland": 30,
	"Thailand": 59,
	"Turkey": 43,
	"Ukraine": 40,
	"United-Arab-Emirates": 166,
	"United-Kingdom": 29,
	"Uruguay": 74,
	"USA": 24,
	"Venezuela": 28
}


function jsonRequest(url, onSuccess) {
	var aR = new XMLHttpRequest();
	aR.onreadystatechange = function() {
		if( aR.readyState == 4 && (aR.status == 200 || aR.status == 304))
			onSuccess(eval('(' + aR.responseText + ')'));
	};
	aR.open('GET', url, true);
	aR.setRequestHeader('Accept', 'application/json, text/javascript, */*; q=0.01');
	aR.send();
};
function $g(aID) {return (aID != '' ? document.getElementById(aID) : null);};
function $gt(str,m) { return (typeof m == 'undefined' ? document:m).getElementsByTagName(str); };
function $gc(str,m) { return (typeof m == 'undefined' ? document:m).getElementsByClassName(str); };
function $at(aElem, att) {if (att !== undefined) {for (var xi = 0; xi < att.length; xi++) {aElem.setAttribute(att[xi][0], att[xi][1]); if (att[xi][0].toUpperCase() == 'TITLE') aElem.setAttribute('alt', att[xi][1]);};};};//Acr111-addAttributes
function $t(iHTML) {return document.createTextNode(iHTML);};
function $e(nElem, att) {var Elem = document.createElement(nElem); $at(Elem, att); return Elem;};
function $ee(nElem, oElem, att) {var Elem = $e(nElem, att); if (oElem !== undefined) if( typeof(oElem) == 'object' ) Elem.appendChild(oElem); else Elem.innerHTML = oElem; return Elem;};
function $am(Elem, mElem) { if (mElem !== undefined) for(var i = 0; i < mElem.length; i++) { if( typeof(mElem[i]) == 'object' ) Elem.appendChild(mElem[i]); else Elem.appendChild($t(mElem[i])); } return Elem;};
function $em(nElem, mElem, att) {var Elem = $e(nElem, att); return $am(Elem, mElem);};
function insertAfter(node, rN) {rN.parentNode.insertBefore(node, rN.nextSibling);};

var useDOMs = typeof window.localStorage == 'undefined' ? false: true;
if ( ! (typeof GM_getValue == 'undefined' || /khtml/i.test(navigator.appVersion)) ) {
	if( useDOMs )
		if( GM_getValue('brokenFF',0) == 1 ) useDOMs = false;
		else {
			GM_setValue('brokenFF',1);
			if( typeof window.localStorage.setItem != "undefined" ) GM_setValue('brokenFF',2);
		}
}
function RB_getValue ( key, defaultValue ) {
	if( useDOMs ) {
		var value = window.localStorage.getItem(key);
		if( value == null ) value = defaultValue;
		return value;
	} else return GM_getValue( key, defaultValue );
}
function RB_setValue( key, value ) {
	if( useDOMs )
		window.localStorage.setItem( key, value );
	else
		GM_setValue( key, value );
}


function getDivision(e) {
    if (e < 35) return 1;
    if (e < 50) return 2;
    if (e < 70) return 3;
    return 4
}
function showPoints(order, countryIdL, countryIdR, wallL, wallR, dominationL, dominationR, totalL, totalR) {
    var str = '<img style="position:absolute;left:210px;top:2px;height:16px;border:solid #666 1px;" src="http://cdn.egov4you.info/img/flags/' + countryIdL + '.gif">'
			+ '<img style="position:absolute;left:276px;top:2px;height:16px;border:solid #666 1px;" src="http://cdn.egov4you.info/img/flags/' + countryIdR + '.gif">'
			+ '<span style="width:14px;text-align:left;position:absolute;left:239px;top:17px;font-size:10px;line-height:10px;color:#333;font-weight:bold;">' + totalL + '</span>'
			+ '<span style="width:14px;text-align:right;position:absolute;left:258px;top:17px;font-size:10px;line-height:10px;color:#333;font-weight:bold;">' + totalR + '</span>'
			+ '<span style="width:30px;text-align:right;position:absolute;left:315px;top:17px;font-size:10px;line-height:10px;color:#333;font-weight:bold;">' + dominationL + '</span>'
			+ '<span style="width:30px;text-align:left;position:absolute;left:627px;top:17px;font-size:10px;line-height:10px;color:#333;font-weight:bold;">' + dominationR + '</span>'
			+ '<div style="position:absolute;left:350px;top:10px;width:270px;height:22px;margin:0;padding:0;'
			+ 'background: -moz-linear-gradient(left,  #33cc33 0%, #33cc33 ' + wallL + '%, #cc3333 ' + wallL + '%, #cc3333 100%);'
			+ 'background: -webkit-gradient(linear, left top, right top, color-stop(0%,#33cc33), color-stop(' + wallL + '%,#33cc33), color-stop(' + wallL + '%,#cc3333), color-stop(100%,#cc3333));'
			+ 'background: -webkit-linear-gradient(left,  #33cc33 0%,#33cc33 ' + wallL + '%,#cc3333 ' + wallL + '%,#cc3333 100%);'
			+ 'background: -o-linear-gradient(left,  #33cc33 0%,#33cc33 ' + wallL + '%,#cc3333 ' + wallL + '%,#cc3333 100%);'
			+ 'background: -ms-linear-gradient(left,  #33cc33 0%,#33cc33 ' + wallL + '%,#cc3333 ' + wallL + '%,#cc3333 100%);'
			+ 'background: linear-gradient(to right,  #33cc33 0%,#33cc33 ' + wallL + '%,#cc3333 ' + wallL + '%,#cc3333 100%);'
			+ 'border:solid #666 1px;">'
			+ '<span style="width:45px;text-align:left;position:absolute;left:7px;bottom:6px;font-size:10px;line-height:10px;color:#fff;font-weight:bold;">' + wallL + '%</span>'
			+ '<span style="width:45px;text-align:right;position:absolute;right:6px;bottom:6px;font-size:10px;line-height:10px;color:#fff;font-weight:bold;">' + wallR + '%</span>'
			+ '</div>';
    $g("order" + order).innerHTML+=str;
}
function showWall(order, countryIdL, countryIdR, wallL, wallR, dominationL, dominationR, totalL, totalR) {
    var str = '<div style="position:absolute;left:137px;top:29px;width:80px;height:11px;margin:0;padding:0;'
			+ 'background: -moz-linear-gradient(left,  #33cc33 0%, #33cc33 ' + wallL + '%, #cc3333 ' + wallL + '%, #cc3333 100%);'
			+ 'background: -webkit-gradient(linear, left top, right top, color-stop(0%,#33cc33), color-stop(' + wallL + '%,#33cc33), color-stop(' + wallL + '%,#cc3333), color-stop(100%,#cc3333));'
			+ 'background: -webkit-linear-gradient(left,  #33cc33 0%,#33cc33 ' + wallL + '%,#cc3333 ' + wallL + '%,#cc3333 100%);'
			+ 'background: -o-linear-gradient(left,  #33cc33 0%,#33cc33 ' + wallL + '%,#cc3333 ' + wallL + '%,#cc3333 100%);'
			+ 'background: -ms-linear-gradient(left,  #33cc33 0%,#33cc33 ' + wallL + '%,#cc3333 ' + wallL + '%,#cc3333 100%);'
			+ 'background: linear-gradient(to right,  #33cc33 0%,#33cc33 ' + wallL + '%,#cc3333 ' + wallL + '%,#cc3333 100%);'
			+ 'border:solid #666 1px;">'
			+ '<img style="position:absolute;left:-16px;bottom:0;width:12px;height:9px;border:solid #666 1px;" src="http://cdn.egov4you.info/img/flags/' + countryIdL + '.gif">'
			+ '<img style="position:absolute;right:-16px;bottom:0;width:12px;height:9px;border:solid #666 1px;" src="http://cdn.egov4you.info/img/flags/' + countryIdR + '.gif">'
			+ '<span style="width:40px;text-align:left;position:absolute;left:3px;bottom:1px;font-size:10px;line-height:10px;color:#fff;font-weight:bold;">' + wallL + '</span>'
			+ '<span style="width:40px;text-align:right;position:absolute;right:2px;bottom:1px;font-size:10px;line-height:10px;color:#fff;font-weight:bold;">' + wallR + '</span>'
			+ '</div>';
    $g("order" + order).innerHTML+=str;
}
function getPointsWall(battleId, order, division) {
	jsonRequest("/en/military/battle-status/" + battleId + "/1", function(json) {
		if (json['message'] != 'BATTLE_CLOSED') {
			var countryIdL = Object.getOwnPropertyNames(json['division'])[0];
			var countryIdR = Object.getOwnPropertyNames(json['division'])[1];
			var domination = Math.round(json['division']['domination'][division] * 1000) / 1000;
			domination = domination.toFixed(3);
			var bar = json['division']['bar'][division];
			if (domination > 50) {
				if (bar == countryIdL) {
					var wallL = domination;
					var wallR = 100 - domination
				} else {
					var wallR = domination;
					var wallL = 100 - domination
				}
			} else {
				if (bar == countryIdL) {
					var wallR = domination;
					var wallL = 100 - domination
				} else {
					var wallL = domination;
					var wallR = 100 - domination
				}
			}
			var dominationL = json['division'][countryIdL][division]['domination'];
			var dominationR = json['division'][countryIdR][division]['domination'];
			var totalL = json['division'][countryIdL]['total'];
			var totalR = json['division'][countryIdR]['total'];
			if (window.location.href.indexOf("/military/campaigns") > 0) {
				wallL = Number(wallL).toFixed(3);
				wallR = Number(wallR).toFixed(3);
				showPoints(order, countryIdL, countryIdR, wallL, wallR, dominationL, dominationR, totalL, totalR)
			} else {
				wallL = Number(wallL).toFixed(2);
				wallR = Number(wallR).toFixed(2);
				showWall(order, countryIdL, countryIdR, wallL, wallR, dominationL, dominationR, totalL, totalR)
			}
			if (order == 6) {
				$g("hq1").style.display="block";
				$g("hq2").style.display="block";
			} else {
				$g("mod1").style.display="block";
				$g("mod2").style.display="block";
				$g("order" + order).style.display="block";
			}
		}
	});
}

var sb = $gc('user_finances');
if( sb.length > 0 ) {
	var egov4Country = RB_getValue('egov4Country',40);

	var str = '';
	str = 'egovatwar <a target="_blank" href="'+scriptLink+'">v' + egov4war + '</a><select id="selectCountry" style="margin-top:3px;width:150px;font-size:10px;">';
	for( var country in countries ) {
		if (countries[country] == egov4Country) {
			str = str + '<option value="' + countries[country] + '" selected="selected">' + country + '</option>'
		} else {
			str = str + '<option value="' + countries[country] + '">' + country + '</option>'
		}
	}
	str = str + '</select>';
	insertAfter($ee('div',str,[['id',"egov4warSidebar"],['style',"font-size:10px;font-weight:bold;color:#333;"]]),sb[0]);
	$g('selectCountry').addEventListener('change', function() {
		RB_setValue('egov4Country', this.value);
		window.location = location.href
	},false);

	jsonRequest('http://www.egov4you.info/orders/data/' + egov4Country, function(json) {
		var division = getDivision(parseInt($gt('b',$gc("user_level")[0])[0].innerHTML));
		var str = '';
		if (json.target && json.target.battle != null && (json.target.div == null || json.target.div == division)) {
			str = str + '<h4 id="hq1" style="display:none;">' + json.alliance + ' HeadQuarters <span style="color:#b6b6b6;font-size:90%;font-weight:normal;">(updated in day ' + json.target.updated + ')</span></h4>';
			str = str + '<ul id="hq2" style="display:none;">';
			str = str + '<li id=\'order6\'>';
			if (json.target.note.length == 0) {
				json.target.note = 'Fight!'
			}
			for (i = 0; i < json.target.stars; i++) {
				position = 4 + (i * 16);
				str = str + '<img style="position:absolute;left:' + position + 'px;top:26px;width:16px;margin:0;" alt="*" src="http://cdn.egov4you.info/img/star.png"></div>'
			}
			str = str + '<span style="position:absolute;left:7px;top:6px;font-size:12px;line-height:12px;color:#333;font-weight:bold;">' + json.target.region + '</span>';
			str = str + '<span style="position:absolute;left:7px;top:17px;font-size:10px;line-height:10px;color:#333;width:195px;overflow:hidden;white-space:nowrap;">' + json.target.note + '</span>';
			if (json.target.side != null) {
				str = str + '<a title="" href="/en/military/battlefield-choose-side/' + json.target.battle + '/' + json.target.side + '"><span>Fight</span></a>'
			} else {
				str = str + '<a title="" href="/en/military/battlefield/' + json.target.battle + '"><span>Fight</span></a>'
			}
			str = str + '</li>';
			str = str + '</ul>'
		}
		if (json.orders) {
			var checkBattles = false;
			for(var index in json.orders) {
				if (json.orders[index].battle != null) {
					checkBattles = true
				}
			}
			if (checkBattles) {
				str = str + '<h4 id="mod1" style="display:none;">Ministry of Defence <span style="color:#b6b6b6;font-size:90%;font-weight:normal;">(updated in day ' + json.updated + ')</span></h4>';
				str = str + '<ul id="mod2" style="display:none;">';
				for(var index in json.orders) {
					if (json.orders[index].battle != null && (json.orders[index].div == null || json.orders[index].div == division)) {
						str = str + '<li id=\'order' + json.orders[index].order + '\' style="display:none;">';
						if (json.orders[index].note.length == 0) {
							json.orders[index].note = 'Fight!'
						}
						for (i = 0; i < json.orders[index].stars; i++) {
							position = 4 + (i * 16);
							str = str + '<img style="position:absolute;left:' + position + 'px;top:26px;width:16px;margin:0;" alt="*" src="http://cdn.egov4you.info/img/star.png"></div>'
						}
						str = str + '<span style="position:absolute;left:7px;top:6px;font-size:12px;line-height:12px;color:#333;font-weight:bold;">' + json.orders[index].region + '</span>';
						str = str + '<span style="position:absolute;left:7px;top:17px;font-size:10px;line-height:10px;color:#333;width:195px;overflow:hidden;white-space:nowrap;">' + json.orders[index].note + '</span>';
						if (json.orders[index].side != null) {
							str = str + '<a title="" href="/en/military/battlefield-choose-side/' + json.orders[index].battle + '/' + json.orders[index].side + '"><span>Fight</span></a>'
						} else {
							str = str + '<a title="" href="/en/military/battlefield/' + json.orders[index].battle + '"><span>Fight</span></a>'
						}
						str = str + '</li>'
					}
				}
				str = str + '</ul>'
			}
		}
		insertAfter($ee('div',str),$g("rw_pop"));
		if (json.target && (json.target.div == null || json.target.div == division)) {
			getPointsWall(json.target.battle, '6', division)
		}
		if (json.orders) {
			if (checkBattles) {
				for(var index in json.orders) {
					if (json.orders[index].battle != null && (json.orders[index].div == null || json.orders[index].div == division)) {
						getPointsWall(json.orders[index].battle, json.orders[index].order, division)
					}
				}
			}
		}
		if (window.location.href.split("/").length == 4) {
			if (json.shouts) {
				var firstPost = $gc("wall_post")[0];
				for(var index in json.shouts) {
					if (json.shouts[index].text.length > 0) {
						var sT = json.shouts[index].alliance != null ? ["/en/main/alliances",2]:["/en/military/campaigns",1];
						firstPost.parentNode.insertBefore($em('li',[
							$em('a',[
								$e('span'),
								$e('img',[['src',"http://cdn.egov4you.info/img/about"+sT[1]+".png"]])
							],[['href',sT[0]],['class',"user_pic"],['target',"_blank"]]),
							$em('div',[
								$em('h6',[
									$ee('a',(sT[1]==2?json.shouts[index].alliance + ' HeadQuarters':'Ministry of Defence'),[['href',sT[0]]]),
									$ee('em','wrote in day ' + json.shouts[index].updated)
								]),
								$ee('p',json.shouts[index].text)
							],[['class',"post_content"]])
						],[['class',"wall_post"]]), firstPost);
					}
				}
			}
		}
	});
}
}

if (window.location.href.split("/").length == 4) {
	egov4war_start();
} else if (window.location.href.indexOf("/military/campaigns") > 0) {
	egov4war_start();
}