The nut of the problem is that I need to use XPath and not having
XPathResult becomes a maintenance issue. I'm porting a GM script to
Jetpack, this scripts manipulates webpages that do not use CSS that
are all generated by a particular website package. The content being
provided by this software comes from a central database though each
provider only has access to a small overlapping portion of the
content; my script allows the user to link together the different
providers, allowing them to "shop around". Each provider has tweaked
the layout slightly but because of the rigidity of the engine these
are pretty minor... but enough to require that all XPath expressions
be pretty fuzzy.
This XPath expression is used to grab rows in a table, each row a
search result.
"//tr[td[1]/b/descendant-or-self::*[contains(text(), ':')] and count
(td) <= 2]/ancestor::table[count(tbody/tr) <= 2 and position() < 3]/
ancestor::tr[1]"
Then we parse each search result for key-value pairs, which we use to
apply an extra filtering layer. This is the expression to find the
keys.
".//tr[count(td) <= 2]/td[1]/b[descendant-or-self::*[contains(text(),
':')]]"
From the key I use the following to grab the value
"./ancestor::tr[1]/td[last()]"
Sure I could rewrite these expressions as a mix of jQuery and
javascript but it would be a huge amount of work, not mentioning that
it would make the code harder to read & maintain.
Now as a GM scripter, I find this to be a bit of a deficiency; GM
exposes this enumeration.
As to the porting progress of my script... well the GM script grew
organically as I came up with new features and learned more about the
software (generating the pages). It wouldn't be so bad if it were only
parsing one webpage but it has code that deals with about a dozen
different pages... and the code for them is kinda... intermixed. It's
hard to read and could do with some proper OO. So as I'm porting it,
I'm rewriting it to give it some OO. Once I get it as a Jetpack I can
add the remaining features.
Mind you, I don't think many people will be interested in this
Jetpack, there hasn't been a lot of interest in the GM script (but
then, most people don't have multiple library cards). It's mostly for
my own use.