[Greasemonkey] Trying to change image before browser fetches
James Sheridan
stuff at phosphor-ink.com
Thu Feb 16 01:07:55 EST 2006
I'm trying to create a script that looks for a particular string in
image "src" attributes and changes it, *before* the browser sends out
for the image. The code below does indeed change the "src" attr, but it
seems to do it after the images are already loaded. That doesn't help me.
Any pointers, please?
Thanks
<code>
var doc, xpath, xpr;
doc = window.document;
xpath = "//*[(contains(@src,'www.someplace.com'))]";
xpr =
document.evaluate(xpath,doc,null,XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,null);
for ( i = 0; img = xpr.snapshotItem(i); i++ ) {
src = img.getAttribute( "src" );
src = src.replace( /http:\/\/www\.someplace\.com\//g,
"http://www.someotherplace.com/" );
img.setAttribute( "src", src );
}
</code>
--
James
--
James
More information about the Greasemonkey
mailing list