[Greasemonkey] How to create a library.

Aaron Boodman zboogs at gmail.com
Wed Sep 7 19:21:59 EDT 2005


I think people are talking about different things.

If you're just trying to avoid having the same code in multiple files
while you develop, that is really not a job for GM, but something like
what nik said.

If you want the actual user script that you ship to also not have this
duplicate code, then you need GM_import or whatever. But then you need
to host the file somewhere, with the obvious performance downsides.

I had planned to add the GM_import one because that could be useful as
a poor-man's autoupdate, and because people need it. You can actually
do it now with GM_xmlhttpRequest + eval, but it doesn't block so you
need to run the rest of your script after the call returns in the
onload handler.

-- 
Aaron

On 9/7/05, chris feldmann <cfeldmann at gmail.com> wrote:
> On 9/7/05, Nikolas Coukouma <lists at atrus.org> wrote:
> > Jeremy Dunck wrote:
> > > On 9/7/05, Pedro Del Gallego <pedro.delgallego at gmail.com> wrote:
> > >
> > >> Hi,
> > >>
> > >> I need to create few scripts with similar feature. I like to reuse
> > >> several function, but i don't find how to call they after.
> > >>
> > >> Has GM something like the include sentence in C?
> > >>
> > >> It will be nice do if a could do :
> > >>
> > >> include ( ./libraries/foo.user.js, myNameSpace)
> > >> myNameSpace.foo();
> > >>
> > >
> > > It doesn't.
> > >
> > > Feel free to add a request for an API:
> > > http://dunck.us/collab/GreaseMonkeyUserScripts#head-68cca0b4cd20c940c1410bb1ccc58e403dc42d06
> > Instead of a path, I'd suggest specifying the namespace and scriptname
> > or just a script name and assuming/requiring that it's in the same
> > namespace. Or, we could use the namespace as a base path. There's
> > nothing requiring that namespaces be URIs, much less URLs ("I hate
> > namespaces" is just as valid as "http://namespacehate.com/"). It seems
> > intuitive to support it, especially sine we use the URL to make the
> > default namespace and script name.
> >
> > I've mentioned the m4 preprocessor. and mention it again. You'd write:
> >
> > include(utils.js)
> >
> > to include utils.js and then run m4 somescript.user.js and save the
> > output. Somthing like:
> > m4 someScript.user.js > someScript.dist.user.js
> >
> > Still, people seem to want this in Greasemonkey itself and there was
> > never a decision that I recall. Implementing includes within
> > Greasemonkey shouldn't be hard anyway.
> 
> Is this not merely a workaround to defeat the same-domain restrictions
> of xmlhttprequests? Are there not, thus, security implications? I
> suppose if it's only one-way, many concerns would be obviated, and the
> others maybe just fall under the category of "one can never be
> trusting anyway if there's an active script on a page,"  but I'm not
> as good as others at thinking of exploits.
> 
> chris
> >
> > Cheers,
> > -Nikolas
> > _______________________________________________
> > Greasemonkey mailing list
> > Greasemonkey at mozdev.org
> > http://mozdev.org/mailman/listinfo/greasemonkey
> >
> 
> _______________________________________________
> Greasemonkey mailing list
> Greasemonkey at mozdev.org
> http://mozdev.org/mailman/listinfo/greasemonkey
> 
> 
>


More information about the Greasemonkey mailing list