Pb...
![]() ![]() |
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! |
![]() ![]() |
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. :-) |
![]() ![]() |
Hmmm... If I understand the XPath documentation correctly, one way to implement the fuction 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? |
![]() ![]() |
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. |
![]() ![]() |
@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.
Regards!
|


