[Greasemonkey] Script scoping
Aaron Boodman
zboogs at gmail.com
Mon May 2 11:44:16 EDT 2005
We can remove this; I'm not married to it.
The main reason I added it was to make GM_* functions local to user
scripts, but I can probably (?) think of another way to accomplish
that. Mark would have to revise his book.
It seems to be causing lots of problems and gotchas.
--
Aaron
On 5/2/05, Jeremy Dunck <jdunck at gmail.com> wrote:
> On 5/2/05, Andrew Hayward <greasemonkey at mooncalf.me.uk> wrote:
> > I've just got round to installing GM0.3b, after finally getting fed up
> > of not having the new features at my disposal. However, I noticed the
> > following in the change log...
> >
> > > Improved error handling by isolating scripts from one another. Errors
> > > in one script will no longer stop other scripts from running. Errors
> > > loading a script will not stop other scripts from being loaded.
> >
> > That's all well and good, but what happens if I actually want to access
> > another script?
>
> Hey Andrew, cross-script dependencies, eh. There'd been some talk
> about this, but no support for it yet.
>
> Others have already suggested the window.foo = yourfirstsscriptfunc() approach.
>
> The only downside of this is that your first script has to be
> injected, err, first. Which is the same as it was before, modulo the
> scoping issue.
>
> That is to say, if you had cross script dependencies before, even
> without the anon function scoping added in 0.3b, the dependant script
> would have to inject after the lib script.
>
> So.. that suggestion may already solve your problem.
>
> Otherwise, I like the idea of @scriptinclude
> yournamespace/yourlibname, which, the way I'm thinking, would inject
> another (already installed) script, regardless of its
> @include/@exclude.
>
> Would that work for you? ...Injection would get more complicated,
> because the order of injection would have to be smarter to resolve
> dependencies.
>
> Hmm, also, GM_getValue and GM_setValue on the library would be
> something else to discuss. Should values stored as a library
> injection be under the top script name, or the lib script name?
>
> ...Sure you can't preprocess just your user.js to just include all the
> stuff you want into the deployed user.js file?
>
> We can work this out, but for now, I recommend you hack up your
> greasemonkey install.
> browser.xul line 124:
> runBrowserScript(
> doc,
> [ "(function(){",
> "var GM_xmlhttpRequest = window.GM_xmlhttpRequest;",
> "var GM_registerMenuCommand = window.GM_registerMenuCommand;",
> "var GM_setValue = window.GM_setValue;",
> "var GM_getValue = window.GM_getValue;",
> "var GM_log = window.GM_log;\n",
> getContents(getScriptChrome(script.filename)),
> "})();"
> ].join("\n")
> );
> to:
> runBrowserScript(
> doc,
> [
> "var GM_xmlhttpRequest = window.GM_xmlhttpRequest;",
> "var GM_registerMenuCommand = window.GM_registerMenuCommand;",
> "var GM_setValue = window.GM_setValue;",
> "var GM_getValue = window.GM_getValue;",
> "var GM_log = window.GM_log;\n",
> getContents(getScriptChrome(script.filename))
> ].join("\n")
> );
> _______________________________________________
> Greasemonkey mailing list
> Greasemonkey at mozdev.org
> http://mozdev.org/mailman/listinfo/greasemonkey
>
More information about the Greasemonkey
mailing list