[Greasemonkey] evaluate and XPCNativeWrapper in 0.6.4
Bruce Perry
bhrperry at comcast.net
Tue Jan 31 09:41:51 EST 2006
I've bought "Greasemonkey Hacks" and I'm trying to get started with
GreaseMonkey. I've installed GreaseMonkey 0.6.4 on Firefox 1.5. I'm
trying to use XPath to get a collection of elements so that I can pull info
from the elements.
Here's the code:
//get the page's h2 elements
var snap = document.evaluate("//h2", document, null,
XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
for (var i = snap.snapshotLength - 1; i>=0; i--){
var elm = snap.snapshotItem(i);
alert('IT '+ elm +" " + elm.getAttribute('outerHTML'));
}
This code gets the right number of elements and iterates through them. The
variable 'elm' shows up in the alert box as '[object XPCNativeWrapper
[object HTMLHeadingElement]]. If I try something like elm.outerHTML, the
result is 'undefined'.
I surmise that the 0.6.4 update has probably changed something. I read
somewhere that in 0.6.4 that almost everything is returned in an
XPCNativeWrapper now.
Similar code in the "Zap Ugly XML Buttons" script works fine, but isn't
trying to get anything out of the items that it's looping on. Can someone
point me at an example of how to get data out of XPNativeWrapper items
returned via XPath?
Thanks,
Bruce
More information about the Greasemonkey
mailing list