[Greasemonkey] Re: Trying to change image before browser fetches

Andre gm at andrecgn.de
Thu Feb 16 09:38:32 EST 2006


As far as I remember earlier discussions on this list, this is not 
possible with GM at all.

The script is injected at a time when the DOM has been built. At that 
time the images will have started to load.

When the US wakes up again, the GM-Gurus will help, I am sure.

Andre

Arvid Jakobsson wrote:
> 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