[Greasemonkey] replacing a script with my own
esquifit
esquifit at googlemail.com
Wed Sep 13 16:08:55 EDT 2006
GM can access the DOM (in particular <scripts> tags) only after it has been
completely built, and before it is rendered. By the time GM runs, the code
contained in <script> tags has already been executed. This makes sense IMHO
because the code within <script> tags could potentially modify or even
completelly specify (eg. document.write() ) the DOM that has to be rendered.
Even if one is sure about the script not modifying the document structure, I
do not know of any work-around (that would be fantastic, for instance for
getting rid of Red Sheriff intrusive scripts).
2006/9/13, jjazz <jvasile at gmail.com>:
>
>
> I frequent a website that loads a script in the head section with
>
> <script type="text/javascript" src=" review.js"></script>
>
> I would like Greasemonkey to get in there and replace review.js with
> another
> url-- i.e. one that points to my customized version. I am having trouble
> getting in there and making the change. I am doing the following, which
> does changes the src of the script tag, but doesn't affect the operation
> of
> the site.
>
> var allScripts = document.evaluate( '//script[@src]', document, null,
> XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
> for (var i = 0; i < allScripts.snapshotLength; i++) {
> var thisScript = allScripts.snapshotItem(i);
> if (thisScript.src == 'http://url.of.site/review.js') {
> thisScript.src = 'http://url.to.my.version/newscript.js';
> }
> }
>
> I feel like I've missed somethig simple (I have little javascript or DOM
> experience). Any hints would be most appreciated.
>
> Thanks.
> --
> View this message in context:
> http://www.nabble.com/replacing-a-script-with-my-own-tf2264406.html#a6283229
> Sent from the MozDev - greasemonkey forum at Nabble.com<http://nabble.com/>
> .
>
> _______________________________________________
> Greasemonkey mailing list
> Greasemonkey at mozdev.org
> http://mozdev.org/mailman/listinfo/greasemonkey
>
More information about the Greasemonkey
mailing list