[Greasemonkey] Grab text string in TD

Mark Pilgrim pilgrim at gmail.com
Fri Apr 22 14:54:21 EDT 2005


On 4/22/05, Edward Lee <edilee at gmail.com> wrote:
> On 4/22/05, Paul Roub <paul at roub.net> wrote:
> > Anyone have a simpler variation of this?
> 
> Assuming you have something like this overlay function..
> http://www.mozdev.org/pipermail/greasemonkey/2005-April/001173.html
> 
> overlay('//text()', function(text) { text.nodeValue =
> text.nodeValue.replace(/Google/g, 'Gooogle!'); });
> 
> Note that it'll only replace next nodes and not something like the
> value of the search button, so Google Search remains as that.

That overlay function is very nice.  I did something similar (without
encapsulation) in DumbQuotes:

http://diveintomark.org/projects/greasemonkey/dumbquotes.user.js

But your XPath query is simpler and probably ends up being equivalent.

Bottom line: the best way to do a text search/replace is to loop
through all the text nodes and do the replacement in each of them. 
And the best way to loop through all the text nodes is with an XPath
query of "//text()".

-- 
Cheers,
-Mark


More information about the Greasemonkey mailing list