Happy Snail

A collection of Ikariam Tutorials from a hard-core player and Java Script programmer

Greasemonkey Madness

The purpose of this tutorial is to introduce you, dear reader to joys of programming and automation. This is part of the initiative to teach programming to all and is supported by

Programming for the Masses project.

So, you always wanted to learn programming but found it boring and nobody told you were to start.  Why not start with basics and move to the games you love?

A simplest program could be as simple as this:

<html>

<script>

 document.write(  56797777 + 678784456  );

</script>  

</html> 

Usually programming lessons start with outputting "hello world" to the screen.  This is pretty boring and of itself useless.  The above code - is a little more useful.  It would output a sum of 56797777 + 678784456.  Try to work it out in your head!  Any fool can type "hello world", you don't need a computer program for that, but very few people can work out the maths above without a calculator or at least a pen and paper.  Copy the code above to notepad and save it with a .html or .htm extension.  Voila! you have created your first application. Change the numbers in the code, and the output will change too.


The little beauty below removes dangerous accelerate loading buttons. These buttons pop up every time you start loading something in your port.  Due to proximity of the accelerate and recall buttons is all to easy to click a wrong button.  Imagine you accidentally order sending coal to Newcastle, notice your mistake and instead of hitting the recall button you hit the silly accelerate button and waste your Ambrosia? Mistakes like this do wonders for player's blood pressure, therefore it is in the interest of the Public Health to run this script that will remove the dangerous little accelerate buttons.

             // ==UserScript==
// @name           remove stupid accelerators
// @namespace      removes dangerous accelerate loading buttons
// @author         TestUser
// @license        GNU GPL v3 (http://www.gnu.org/copyleft/gpl.html)
// @homepage       http://userscripts.org/scripts/show/50784
// @description    Removes Plus features as a test - I am not against paying to play
// @include        http://s*.ikariam.*/index.php*
// @include        http://s*.*.ikariam.*/index.php*
// @version        0.02
// @exclude        http://board.ikariam.*/*
// @exclude        http://support*.ikariam.*/*
//
// ==/UserScript==


// this is the code that gets a random number for delay - between 500 and 1500 miliseconds.
var delay = getRandomInt (500, 1500);
function getRandomInt (min, max) {
    return Math.floor(Math.random() * (max - min + 1)) + min;
}

var accelerate;  // accelerate loading of ships (military view)
function removeAccelerate(){
accelerate= document.evaluate("//a[contains(@id,'AccLoading')]", document.body, null, 9, null).singleNodeValue; 
 if (accelerate) { //alert('accelerate');
 accelerate.parentNode.removeChild(accelerate);
 window.clearInterval(ac);
 } 
}

delay = getRandomInt (500, 1500);
var ac = setInterval( removeAccelerate, delay );

var accelerateInPort;  // accelerate loading of ships (port view)
function removeAccelerateInPort(){
accelerateInPort= document.evaluate("//a[contains(@id,'js_accloading')]", document.body, null, 9, null).singleNodeValue; 
 if (accelerateInPort) { //alert('accelerate');
 accelerateInPort.parentNode.removeChild(accelerateInPort);
 window.clearInterval(accloading);
 } 
}
delay = getRandomInt (500, 1500);
var accloading = setInterval( removeAccelerateInPort, delay );

How does it work? First we get the element we want to remove - we use Xpath expression, but document.getElementById("id_of_element");  would also work, but you need to use a full id,  and that id can change. Xpath is so much more advanced. For example we obtain the element whose id contains "AccLoading", we only need a partial match.  It would even match jscript_dfdfAccLoading88f".

accelerate= document.evaluate("//a[contains(@id,'AccLoading')]", document.body, null, 9, null).singleNodeValue;  

 

 

This little script clicks the get daily bonus button, so you don't have to! Of course both of these scripts can be combined into one.

// ==UserScript==
// @name           click
// @namespace      clicks the button to get daily bonus after a random delay
// @author         TestUser
// @license        GNU GPL v3 (http://www.gnu.org/copyleft/gpl.html)
// @homepage       http://userscripts.org/scripts/show/50784
// @description    Removes Plus features as a test - I am not against paying to play
// @include        http://s*.ikariam.*/index.php*
// @include        http://s*.*.ikariam.*/index.php*
// @version        0.02
// @exclude        http://board.ikariam.*/*
// @exclude        http://support*.ikariam.*/*
//
// ==/UserScript==


// this is the code that gets a random number for delay - between 500 and 1500 miliseconds.
var delay = getRandomInt (500, 1500);
function getRandomInt (min, max) {
    return Math.floor(Math.random() * (max - min + 1)) + min;
}

var btn = document.getElementsByClassName("button okButton")[0]; // gets all buttons by this class name - there should be only one
// this is the code that activates clicking of a button  after a random delay
if ( btn )  {  //  only runs on the first page load - when there is the button we want to click
setTimeout( click_it, delay );
}

// this is the code that actually clicks the button
function click_it() {   
document.evaluate("//input[@value='Confirm' and @type='submit' and contains(@class, 'button okButton')]", document, null, 9, null).singleNodeValue.click();
}

 

More scrips are coming soon. I intend to write a detailed Greasemonkey tutorial using Ikariam as an example.  Whatch this space.

And this little piece of delightful code will keep clicking "Capture" button in the Pirate Fortress - it will keep doing so 24/7 - earning you a lot of capture points, while saving you from repetitive strain syndrome and shortage of sleep. This code is like a Terminator - it will absolutely not stop. I have run a test - and the amount of cupture points collected was insane!  A human would have to spend hours sitting in front of computer clicking a button every 2.5 minutes to get the same result.

function click_townView(){
var townView=document.evaluate("//a[@title='Inspect the selected town']", document.body, null, 9, null).singleNodeValue;   
if ( townView ){ delay = getRandomInt (1000, 2000); townView.click(); }
} //eof

function click_pirateFort(){
var pirateFort=document.evaluate("//a[contains(@title,'Pirate Fortress')]", document.body, null, 9, null).singleNodeValue;   
if ( pirateFort ){ pirateFort.click(); }
else{ delay = getRandomInt (1000, 2000); click_townView(); }
} //eof

/* click_captureSmuglersBtn() is the function that keep clicking "Capture" button
   every 2.5 minutes.
   But if we are thrown out of the pirate fort, we need to get back into Town View,
   and then into the Pirate Fort, so we have click_townView() and click_pirateFort() too
*/

function click_captureSmuglersBtn(){
var captureSmuglersBtn=document.evaluate("//a[contains(@class,'button capture')]", document.body, null, 9, null).singleNodeValue;   
if ( captureSmuglersBtn  ){ captureSmuglersBtn.click();
//setTimeout( clickBtn, 1500 );  // go to next city
window.clearInterval(int1);
setTimeout( myPause, 151000 ); // pause for 2.5 minutes and 1 sec
}
else{ delay = getRandomInt (1000, 2000); click_pirateFort(); }
} //eof

var delay = getRandomInt (1000, 3000);

function myPause(){  int1=setInterval( click_captureSmuglersBtn, delay); }

var int1=setInterval( click_captureSmuglersBtn, delay);

//************  calculate random delays  **************
function getRandomInt (min, max) {
    return Math.floor(Math.random() * (max - min + 1)) + min;
}

 

Filed under: Ikariam bot, Ikariam auto, Ikariam Pirate, Ikariam pirate fortress, Ikariam pirate script, Ikariam piracy automation