[Greasemonkey] Trying to change image before browser fetches

Matt Sargent matt.sargent at earthlink.net
Thu Feb 16 10:25:25 EST 2006


You might try converting it to an extension.

On 16 Feb 2006 at 1:07, James Sheridan wrote:

> 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_T
> YPE,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
> _______________________________________________
> Greasemonkey mailing list
> Greasemonkey at mozdev.org
> http://mozdev.org/mailman/listinfo/greasemonkey
> 




More information about the Greasemonkey mailing list