[Greasemonkey] Turnabout: More Greasemonkey for IE

Mark Pilgrim pilgrim at gmail.com
Wed Jun 1 09:48:38 EDT 2005


On 5/31/05, chris feldmann <cfeldmann at gmail.com> wrote:
>  How about the possiblility of an XPath translation layer? Most XPath
> queries I've seen (and written) for greasemonkey are "ACTIVE QUERY,
> document, null, standard format, null." Base functionality could be
> replicated with (cringe) regular expressions on the query, am I wrong? The

<jwz>Now you have two problems...</jwz>

I've taken an inventory of all the scripts I've ever written
(including several unreleased ones).  Granted this is not a
representative sample, since I have a particular coding style,
particular interests, etc.  Some of these could undoubtedly be
rewritten without XPath, using the various document.foo properties and
collections.  But here goes:

//*[@accesskey]
//label[@for='some element name determined at runtime']
//a[contains(@href, '?')]
//head/title
//table[@bgcolor='#e5ecf9']
//form[@name='f']
//form[@id='cf']//table//tr//table/tbody
//th/ancestor::table
//td/ancestor::tr
//th|//td
//html/@lang
//input[@type='hidden']
//img[@width='36'][@height='14']
//img[contains(@src, 'MZZZZZZZ')]
//input[@type='submit']
//img[not(@alt)]
//a[starts-with(translate(translate(@href, 'http:', ''),
'.:abcdefghijklmnopqrstuvwxyz0123456789', ''),
'//--')]/ancestor::p[@class='g']
//a[@href='http://validator.w3.org/check/referer']
//p[@class='g']
//img[@width='1'][@height='1'][contains(@src, '?')]
//a[@class='yschttl']
//text()
//*[@rel][@type][@href]
//img[@alt]

All told, 37 scripts, of which 25 use XPath.  It is unlikely that a
"simple" XPath-like compatibility library could faithfully reproduce
all of these expressions.  But it is quite likely that I could rewrite
most of them without using XPath.

-- 
Cheers,
-Mark


More information about the Greasemonkey mailing list