OGame: Resources in Flight

By Vess Last update Feb 15, 2010 — Installed 9,226 times.

Pb...

in
Subscribe to Pb... 5 posts, 3 voices



jeanc Scriptwright
FirefoxWindows

I tried this script but.... I am on firefox 2, and there is no getElementsByClassName function supported... maybe adding it if it does not exist would be a good thing!

 
Vess Script's Author
OperaWindows

FF 2.x doesn't support this JavaScript method? Strange... I'm using Opera right now and it works there like charm...

OK, I made a local implementation of the method. I had to fix the script anyway - it was failing during a hostile attack (nothing was displayed in that case). I can't test it under Firefox right now (neither 2.x nor 3.x) - could you please check whether it works for you?

This whole thing can probably be done better with a clever usage of XPath. Unfortunately, I tried reading the documentation for that a few times and got my brain fried. :-( So, a manual parsing of the elements will have to do for now. If you have an idea how to do it with XPath - feel free to educate me. :-)

 
Vess Script's Author
OperaWindows

Hmmm... If I understand the XPath documentation correctly, one way to implement the fuction processFlightType is like this:

function processFlightType (type, character, info)
{
	var allFlights = document.evaluate ("//[@class='" + type + "']", document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
	for (var i = 0; i < allFlights.snapshotLength; i++)
	{
		var links = allFlights.snapshotItem (i).getElementsByTagName ('a');
		if ((links.length < 5) || (links [5] == null))
			continue;
		var elements = links [5].title.split (": ");
		var type = character + links [4].innerHTML;
		var res = new Array (0, 0, 0);
		for (var j = 0; j < 3; j++)
			res [j] = parseInt (elements [j + 2].replace (/\./g, ''));
		any = true;
		if (info [type])
			for (var j = 0; j < 3; j++)
				info [type] [j] += res [j];
		else
			info [type] = new Array (res [0], res [1], res [2], 0);
	}
	return info;
}

This works in Opera - does it work in Firefox?

 
Vess Script's Author
FirefoxWindows

Sigh... The script, as published, works under Firefox 2.x. However, the XPath-using variant suggested above does not - causes an error about illegal expression... :-( If anybody has an idea how to fix it - yell.

 
Booboo Scriptwright
FirefoxWindows

@Vess

I've run into your script by chance, and the problem is that you haven't specified the tag you search for.

function processFlightType (type, character, info){
	var allFlights = document.evaluate ("//*[@class='" + type + "']", document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
	for (var i = 0; i < allFlights.snapshotLength; i++)
	{
		var links = allFlights.snapshotItem (i).getElementsByTagName ('a');
		if ((links.length < 5) || (links [5] === null))
			continue;
		var elements = links [5].title.split (": ");
		var type = character + links [4].innerHTML;
		var res = new Array (0, 0, 0);
		for (var j = 0; j < 3; j++)
			res [j] = parseInt (elements [j + 2].replace (/\./g, ''));
		any = true;
		if (info [type])
			for (var j = 0; j < 3; j++)
				info [type] [j] += res [j];
		else
			info [type] = new Array (res [0], res [1], res [2], 0);
	}
	return info;
}

Look at the "*" after //, it matches every element that has the given className.
I hope it works! ;)

Regards!
Booboo

Cross
Presentational HTML allowed.
Use <code> for inline code and <pre> for code blocks. Use &lt; and &gt; for literal < and >.
We help break paragraphs and link your links.
or cancel