By Amoulier
—
Last update
Oct 9, 2008
—
Installed
1,360 times.
// ==UserScript==
// @name New Leecher Checker v 0.1.9
// @namespace http://hightekcafe.com/ikariam
// @description A script for Ikariam that colors leechers
// @include http://s*.ikariam.*/*
// @exclude http://board.ikariam.*/*
// ==/UserScript==
// Original script built by Leecher Checker v 1.2.3
// New script built by Joshua Pack
var lversion = "0.1.9";
var updatesite = "http://ikariamlibrary.com/?content=Vejidas%20Leecher%20Checker";
/**
* Parses a string of format 123,456 to an int in format 123456
*/
function toInt(string)
{
var temp,result;
temp = string.split(',');
result = '';
for(var i=0; i < temp.length; i++)
{
result += temp[i];
}
return parseInt(result);
}
/**
* Depending on how well a person donates, he gets a color:
* 0-90 Leecher, color is red
* 90-100 Sort of leecher, color is blue
* 100-110 Donates enough, color is orange
* 110 - ?? Good donater, coller is green
*/
function getLeecherStatus(percentage)
{
if (percentage > 110)
return '#c7fac6';
if (percentage >= 100)
return '#faf4c6';
if (percentage >= 90)
return '#c6dafa';
if (percentage == undefined) //error value
return 'black';
return '#fac6c6';
}
/**
* Parses a string of format 10 into 010
*/
function tothree(percent)
{
var result2 = percent;
if (percent < 10) {
result2 = "<font color='"+getLeecherStatus(percent)+"'>00</font>"+percent;
} else if(percent < 100) {
result2 = "<font color='"+getLeecherStatus(percent)+"'>0</font>"+percent;
} else {
result2 = percent;
}
return result2;
}
/**
* Check to see if you have updated version!
*/
function check_for_update()
{
GM_xmlhttpRequest({
method:"GET",
url:updatesite,
headers:{
"User-Agent":"monkeyagent",
"Accept":"text/monkey,text/xml",
},
onload:function(details) {
var is_it_updated, updatecolor;
if (details.readyState == 4) {
var update_version = details.responseText.split('<span id="lversion">')[1];
update_version = update_version.split('</span>')[0];
if (update_version != lversion) {
is_it_updated = "<a href='"+updatesite+"'><b>Out Of Date</b></a>";
updatecolor = "RED";
} else {
is_it_updated = "Up To Date";
updatecolor = "GREEN";
}
} else {
is_it_updated = "<a href='"+updatesite+"'>Unknown [Could not find update]</a>";
updatecolor = "GRAY";
}
var footer_update = document.getElementById('resourceUsers').childNodes[1];
footer_update.innerHTML += " (<font color='"+updatecolor+"'>Leecher Checker is "+is_it_updated+"</font>)";
}
});
}
window.addEventListener('load', function()
{
try
{
// The id of the body tag contains which page you are on
var page = document.getElementsByTagName('body')[0].id;
// Check if you are at a resource deposit
if ( (page == 'tradegood') || (page == 'resource') )
{
var donationList = document.getElementById('resourceUsers').childNodes[3].childNodes[1];//.childNodes[5-offset].childNodes[1];
var name, playerName, donated, lvl, workers, percentage, param, method, mill_number, milllevel, actionmess;
sort_all_mills = GM_getValue("sort_all_mills",0);
// Depending on the type of resource, get the right variables
if (page == 'resource')
{
mill_number = 23;
method = GM_getValue("method_building",1);
param = GM_getValue("param_building",10);
workplace = new Array();
// Workers / lvl up / cumulative
workplace[1] = new Array( 30, 0, 0);
workplace[2] = new Array( 40, 350, 350);
workplace[3] = new Array( 52, 590, 940);
workplace[4] = new Array( 66, 1010, 1950);
workplace[5] = new Array( 81, 1810, 3760);
workplace[6] = new Array( 98, 3010, 6770);
workplace[7] = new Array(114, 4810, 11580);
workplace[8] = new Array(134, 7060, 18640);
workplace[9] = new Array(154, 10060, 28700);
workplace[10] = new Array(175, 13910, 42610);
workplace[11] = new Array(196, 18410, 61020);
workplace[12] = new Array(219, 25010, 86030);
workplace[13] = new Array(242, 32160, 118190);
workplace[14] = new Array(265, 41160, 159350);
workplace[15] = new Array(290, 52560, 211910);
workplace[16] = new Array(315, 67510, 279420);
workplace[17] = new Array(341, 85060, 364480);
workplace[18] = new Array(367, 105210, 469690);
workplace[19] = new Array(394, 127960, 597650);
workplace[20] = new Array(422, 155960, 753610);
workplace[21] = new Array(450, 197960, 951570);
workplace[22] = new Array(479, 791840, 1743410);
workplace[23] = new Array( -1, 1583680, 3327090);
}
else
{
mill_number = 18;
method = GM_getValue("method_luxury",1);
param = GM_getValue("param_luxury",10);
workplace = new Array();
// Workers / lvl up / cumulative
workplace[1] = new Array( 20, 0, 0);
workplace[2] = new Array( 33, 550, 550);
workplace[3] = new Array( 49, 1110, 1660);
workplace[4] = new Array( 68, 2440, 4100);
workplace[5] = new Array( 88, 4540, 8640);
workplace[6] = new Array(110, 7620, 16260);
workplace[7] = new Array(134, 12660, 28920);
workplace[8] = new Array(159, 19660, 48580);
workplace[9] = new Array(185, 28760, 77340);
workplace[10] = new Array(213, 40520, 117860);
workplace[11] = new Array(242, 54730, 172590);
workplace[12] = new Array(271, 72420, 245010);
workplace[13] = new Array(302, 95050, 340060);
workplace[14] = new Array(334, 122250, 462310);
workplace[15] = new Array(367, 157560, 619870);
workplace[16] = new Array(400, 203760, 823630);
workplace[17] = new Array(434, 815040, 1638670);
workplace[18] = new Array(-1, 1630080, 3268750);
}
// Find Mills level, only for Strict Breafuios
if (method == 2) { milllevel = document.getElementById('resUpgrade').childNodes[3].childNodes[3].innerHTML.split('</span>')[1];}
if (sort_all_mills==1) {
// Order mills
var go_in_order = new Array();
var go_in_order_sort = new Array();
var new_var = 0;
var donated_int2, donated_int;
for (var jj = 1; jj < donationList.rows.length; jj++)
{
name = donationList.rows[jj].cells[1].innerHTML;
playerName = donationList.rows[jj].cells[0].innerHTML;
donated = donationList.rows[jj].cells[4].innerHTML;
donated_int = toInt(donationList.rows[jj].cells[4].innerHTML.split(' ')[0]);
lvl = donationList.rows[jj].cells[2].innerHTML;
workers = donationList.rows[jj].cells[3].innerHTML;
actionmess = donationList.rows[jj].cells[5].innerHTML;
if (isNaN(donated_int)) {donated_int = donated_int2;}
// Player / town / level/ workers/ donated/ actions/ donated_int
go_in_order[new_var] = new Array(playerName, name, lvl, workers, donated, actionmess, donated_int);
// sorting array
if (isNaN(donated_int)) {donated_int = donated_int2;}
go_in_order_sort[new_var] = donated_int;
new_var++;
donated_int2 = donated_int;
}
go_in_order_sort = go_in_order_sort.sort(function(a,b){return b - a});
var new_order = 1;
var add_town;
var ordered_towns = new Array();
for (var jj2 = 0; jj2 < new_var; jj2++)
{
for (var jj3 = 0; jj3 < new_var; jj3++)
{
playerName = go_in_order[jj3][0];
name = go_in_order[jj3][1];
donated = go_in_order[jj3][4];
donated_int = go_in_order[jj3][6];
lvl = go_in_order[jj3][2];
workers = go_in_order[jj3][3];
actionmess = go_in_order[jj3][5];
if (go_in_order_sort[jj2]==donated_int) {
add_town = go_in_order[jj3];
go_in_order[jj3] = [];
break;
}
}
ordered_towns[new_order] = add_town;
new_order++;
}
for (var jj4 = 1; jj4 < new_order; jj4++)
{
donationList.rows[jj4].cells[0].innerHTML=ordered_towns[jj4][0];
donationList.rows[jj4].cells[1].innerHTML=ordered_towns[jj4][1];
donationList.rows[jj4].cells[2].innerHTML=ordered_towns[jj4][2];
donationList.rows[jj4].cells[3].innerHTML=ordered_towns[jj4][3];
donationList.rows[jj4].cells[4].innerHTML=ordered_towns[jj4][4];
donationList.rows[jj4].cells[5].innerHTML=ordered_towns[jj4][5];
}
}
// Start Rules and Laws
for (var j = 1; j < donationList.rows.length; j+=cities)
{
// Name | Player name | Donated | Level | Number of workers | Actions
name = donationList.rows[j].cells[1].innerHTML;
playerName = donationList.rows[j].cells[0].innerHTML;
donated = toInt(donationList.rows[j].cells[4].innerHTML.split(' ')[0]);
lvl = donationList.rows[j].cells[2].innerHTML.split(' ')[1];
workers = donationList.rows[j].cells[3].innerHTML.split(' ')[0];
// Check how many cities this player has
var j3 = j;
var cum_city_lvl = 0;
var cities = 1;
j3++;
while ( (j3 < donationList.rows.length) && (" " == donationList.rows[j3].cells[0].innerHTML) )
{
workers2 = donationList.rows[j3].cells[3].innerHTML.split(' ')[0];
workers = workers*1;
workers2 = workers2*1;
cities = cities*1;
cities = (cities+1);
j3++;
}
var needed_wood;
if (method == 1 || method == 2) //Breafuios and Strict Breafuios
{
var strict = "1";
if (method == 1) {strict = "1.5";}
var breafuios_new;
// Check which level is used
for(workers_lvl = 1; workers_lvl < mill_number; workers_lvl++)
{
if (workers <= strict * workplace[workers_lvl][0])
break;
}
if (method == 2) { if (workers > workplace[milllevel][0]) {workers_lvl = milllevel;}}
breafuios_new = workplace[workers_lvl][2]*param/100;
var j2 = j;
j2++;
while ( (j2 < donationList.rows.length) && (" " == donationList.rows[j2].cells[0].innerHTML) )
{
for(workers_lvl2 = 1; workers_lvl2 < mill_number; workers_lvl2++)
{
workers2 = donationList.rows[j2].cells[3].innerHTML.split(' ')[0];
if (workers2 <= strict * workplace[workers_lvl2][0])
break;
}
if (method == 2) { if (workers2 > workplace[milllevel][0]) {workers_lvl2 = milllevel;}}
breafuios_new = (breafuios_new+(workplace[workers_lvl2][2]*param/100));
j2++;
}
if (" " != playerName) {
percentage = ((donated / (breafuios_new))) * 100;
}
if (percentage=="Infinity") {percentage = 110.1;}
if (percentage>999) {percentage = 999;}
needed_wood = breafuios_new-donated+1;
needed_wood110 = (breafuios_new*1.10)-donated+1;
}
else // ZEN Rule
{
// Check which level is used
for(workers_lvl = 1; workers_lvl < 19; workers_lvl++)
{
if (workers <= 1.5 * workplace[workers_lvl][0])
break;
}
if (" " != playerName) {
percentage = ((donated / (workplace[workers_lvl][2]*param/100))/cities) * 100;
}
if (percentage=="Infinity") {percentage = 110.1;}
if (percentage>999) {percentage = 999;}
needed_wood = breafuios_new-donated+1;
needed_wood110 = (breafuios_new*1.10)-donated+1;
}
for (j2 = 0; j2 < cities; j2++)
{
if (workers < 1 && percentage < 91) {
donationList.rows[j+j2].style.backgroundColor = getLeecherStatus('90.1');
}
else
{
donationList.rows[j+j2].style.backgroundColor = getLeecherStatus(percentage);
}
if(sort_all_mills==1) {donationList.rows[j+j2].className = "avatar ";}
}
if (!percentage) {percentage = 0;}
newpercent = Math.round(percentage);
donationList.rows[j].cells[4].innerHTML += " <name title='Needs "+Math.round(needed_wood)+" Wood to be at 100% and Needs "+Math.round(needed_wood110)+" Wood to be at 110%'>"+tothree(newpercent)+"%</name>";
}
check_for_update();
}
// Add options menu
if (page == 'options')
{
var allElements = document.getElementsByTagName('form');
for (var i = 0; i < allElements.length; i++)
{
var thisElement = allElements[i];
if (thisElement.elements[0].value == 'Options')
{
var breafious_building, sbreafious_building, ZEN_building, breafious_luxury,sbreafious_luxury, ZEN_luxury,debug_mode_on,debug_mode_off,sort_all_mills_on,sort_all_mills_off;
var method_building = GM_getValue('method_building','1');
var param_building = GM_getValue('param_building','15');
var method_luxury = GM_getValue('method_luxury','1');
var param_luxury = GM_getValue('param_luxury','15');
var debug_mode = GM_getValue('debug_mode','0');
var sort_all_mills = GM_getValue('sort_all_mills','0');
if (method_building == 1)
breafious_building = "checked='checked'";
if (method_building == 2)
sbreafious_building = "checked='checked'";
if (method_building == 3)
ZEN_building = "checked='checked'";
if (method_luxury == 1)
breafious_luxury = "checked='checked'";
if (method_luxury == 2)
sbreafious_luxury = "checked='checked'";
if (method_luxury == 2)
ZEN_luxury = "checked='checked'";
if (debug_mode == 0)
debug_mode_off = "checked='checked'";
if (debug_mode == 1)
debug_mode_on = "checked='checked'";
if (sort_all_mills == 0)
sort_all_mills_off = "checked='checked'";
if (sort_all_mills == 1)
sort_all_mills_on = "checked='checked'";
var div;
div = document.createElement('div');
div.innerHTML =
"<div id='leecher_checker'>"+
"<h3>Vejida's Leecher Checker V "+lversion+" Options</h3>"+
"<table cellpadding='0' cellspacing='0'>"+
"<tr>"+
"<td align='center' colspan='2'><i>Building Material</i></td>"+
"</tr>"+
"<tr>"+
"<th>Method:</th>"+
"<td>"+
"<input id='radio_1' type='radio' class='radio' name='method_building' value='1' "+breafious_building+"/> Breafious Rule<br />"+
"<input id='radio_2' type='radio' class='radio' name='method_building' value='2' "+sbreafious_building+" /> Strict Breafious Rule<br />"+
//"<input id='radio_3' type='radio' class='radio' name='method_building' value='3' "+ZEN_building+" /> ZEN"+
"</td>"+
"</tr>"+
"<tr>"+
"<th>Param:</th>"+
"<td><input id='text_1' type='textfield' class='textfield' name='param_building' size='10' value="+param_building+" /></td>"+
"</tr>"+
"<tr>"+
"<td align='center' colspan='2'><i>Luxury Resource<i></td>"+
"</tr>"+
"<tr>"+
"<th>Method:</th>"+
"<td>"+
"<input id='radio_4' type='radio' class='radio' name='method_luxury' value='1' "+breafious_luxury+"/> Breafious Rule<br />"+
"<input id='radio_5' type='radio' class='radio' name='method_luxury' value='2' "+sbreafious_luxury+" /> Strict Breafious Rule<br />"+
//"<input id='radio_6' type='radio' class='radio' name='method_luxury' value='3' "+ZEN_building+" /> ZEN"+
"</tr>"+
"<tr>"+
"<th>Param:</th>"+
"<td><input id='text_2' type='textfield' class='textfield' name='param_luxury' size='10' value="+param_luxury+" /></td>"+
"</tr>"+
"<tr>"+
"<td align='center' colspan='2'><i>Other Options<i></td>"+
"</tr>"+
"<tr>"+
"<th>Debug Mode:</th>"+
"<td>On<input id='radio_7' type='radio' class='radio' name='debug_mode' value='1' "+debug_mode_on+"/> Off<input id='radio_8' type='radio' class='radio' name='debug_mode' value='0' "+debug_mode_off+"/></td>"+
"</tr>"+
"<tr>"+
"<th>Sort Mills by Most Donated:</th>"+
"<td>On<input id='radio_9' type='radio' class='radio' name='sort_all_mills' value='1' "+sort_all_mills_on+"/> Off<input id='radio_10' type='radio' class='radio' name='sort_all_mills' value='0' "+sort_all_mills_off+"/></td>"+
"</tr>"+
"</table>"+
"</div>";
thisElement.insertBefore(div, document.getElementById('options_debug'));
document.getElementById('radio_1').addEventListener('change',function(event){GM_setValue('method_building','1');document.getElementById('text_1').value='15';GM_setValue('param_building','15')},true);
document.getElementById('radio_2').addEventListener('change',function(event){GM_setValue('method_building','2');document.getElementById('text_1').value='10';GM_setValue('param_building','10')},true);
//document.getElementById('radio_3').addEventListener('change',function(event){GM_setValue('method_building','3');document.getElementById('text_1').value='15';GM_setValue('param_building','15')},true);
document.getElementById('radio_4').addEventListener('change',function(event){GM_setValue('method_luxury','1');document.getElementById('text_2').value='15';GM_setValue('param_luxury','15')},true);
document.getElementById('radio_5').addEventListener('change',function(event){GM_setValue('method_luxury','2');document.getElementById('text_2').value='10';GM_setValue('param_luxury','10')},true);
//document.getElementById('radio_6').addEventListener('change',function(event){GM_setValue('method_luxury','3');document.getElementById('text_2').value='15';GM_setValue('param_luxury','15')},true);
document.getElementById('radio_7').addEventListener('change',function(event){GM_setValue('debug_mode','1');},true);
document.getElementById('radio_8').addEventListener('change',function(event){GM_setValue('debug_mode','0');},true);
document.getElementById('radio_9').addEventListener('change',function(event){GM_setValue('sort_all_mills','1');},true);
document.getElementById('radio_10').addEventListener('change',function(event){GM_setValue('sort_all_mills','0');},true);
document.getElementById('text_1').addEventListener('change',function(event){GM_setValue('param_building',document.getElementById('text_1').value)},true);
document.getElementById('text_2').addEventListener('change',function(event){GM_setValue('param_luxury',document.getElementById('text_2').value)},true);
}
}
}
}
catch(er)
{
var debug_mode = GM_getValue('debug_mode','0');
if (debug_mode == 1) {
alert("Vejida\'s Leecher Checker v"+lversion+"\n If you think this is a critical error, post it in the ikariamlibrary.com forums.\n\n\n" + er)
}
}
},
true);