document.getElementsByTagName('body')[0].appendChild(scrip
t) is writing
a script tag to the web page, right?
I'm no expert, but wouldn't such a script be executed
within the context
of the web page, like it was any other script tag in a web
page?
Philip Friedman - Auto Europe wrote:
> I'm back at trying to include an external JS/GM
library in my GM scripts.
> Here is as close as I've gotten, based on this post
> http://manalang.com/archives/2006/01
/04/loading-external-javascript-librarie
> s-in-greasemonkey/ by Rich Manalang. I'd appreciate
any pointers or
> explanations of what's going on.
>
> Specifically, why does
>
document.getElementsByTagName('body')[0].appendChild(scrip
t) result in
> unsafeWindow.libraryAlert() working, but not
libraryAlert()?
>
> My desire is to split my working GM scripts and share
pieces with new
> similar scripts. I'd also like to have users install
stubs and be able to
> 'push' updates to them with no action on their part.
I'm not concerned with
> cross site scripting or user security, but I'd like to
remain undetected by
> the visited web server.
>
> I'm using FF 1.5.0.3 and GM 0.6.4.
>
> --
> Regards, Phil Friedman - Auto Europe
>
> libraryTest.user.js:
>
> // ==UserScript==
> // name LibraryTest
> // namespace /phil
> // description Library Test
> // include file://*libraryTest.user.js
> // exclude
> // ==/UserScript==
>
> var script = document.createElement('script');
> script.type = 'text/javascript';
> script.src = 'library.js';
>
document.getElementsByTagName('body')[0].appendChild(scrip
t);
> waitForLibrary();
> GM_log('LibraryTest return');
> return null;
>
> function waitForLibrary() {
> GM_log('waitForLibrary typeof unsafeWindow.library:
'+typeof
> unsafeWindow.library
> +', typeof unsafeWindow.libraryAlert:
'+typeof
> unsafeWindow.libraryAlert);
> if ( 'undefined' == typeof unsafeWindow.library)
> window.setTimeout(waitForLibrary, 1);
> else
> unsafeWindow.libraryAlert();
> libraryAlert();
> }
>
> Library.js:
>
> var library = true;
>
> function libraryAlert() {
> alert('libraryAlert!');
> GM_log('libraryAlert');
> }
>
> Javascript Console:
>
> /phil/LibraryTest: waitForLibrary typeof
unsafeWindow.library: undefined,
> typeof unsafeWindow.libraryAlert: undefined
> -----
> Error: libraryAlert is not defined
> Source File:
> Line: 24
> Source Code:
> 24
> -----
> /phil/LibraryTest: waitForLibrary typeof
unsafeWindow.library: boolean,
> typeof unsafeWindow.libraryAlert: function
> -----
> Error: GM_log is not defined
> Source File:
file:///C:/projects/rateHarvest/_nsExample/library.js
> Line: 5
>
> _______________________________________________
> Greasemonkey mailing list
> Greasemonkey mozdev.org
> http:
//mozdev.org/mailman/listinfo/greasemonkey
>
>
_______________________________________________
Greasemonkey mailing list
Greasemonkey mozdev.org
http:
//mozdev.org/mailman/listinfo/greasemonkey
|