[Greasemonkey] Trying to change image before browser fetches

Arvid Jakobsson arvid.jakobsson at gmail.com
Thu Feb 16 09:18:28 EST 2006


I'm sorry, but I think that's impossible. Try removing the image and
then replace it with your new image instead. Dunno of that works
better though.

On 2/16/06, James Sheridan <stuff at phosphor-ink.com> 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_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
> _______________________________________________
> Greasemonkey mailing list
> Greasemonkey at mozdev.org
> http://mozdev.org/mailman/listinfo/greasemonkey
>


More information about the Greasemonkey mailing list