[Greasemonkey] How about script library and caching support?

John gm at plsek.id.au
Mon Jul 18 23:35:59 EDT 2005

wyns nnnnn wrote:

> Library support:
> Add a function like GM_include(path)
> the function works like GM_log function and can be called from any
> user.js
> path is relative path to a library sub folder in greasemonkey which
> works like the script (so script can't load other local files with
> some security checking in path name)

I was playing around with just such a thing ... I created
GM_library(), and

basically, the changes I made work like this
a script with meta data
// @type library
won't get injected, however, normal include/exclude rules apply

however, the format of the script is more like an object, if you know
what I mean ... eg

// ==UserScript==
// @name Library
// @namespace test
// @description test for GM_library and GM_globalLibrary
// @include *
// @type library
// ==/UserScript==
getValue:function(){return this.val;},
setValue:function(x){return this.val=x;}

when a script wants to load this script, it simply calls
var xxx=GM_library("test/Library");

where test/Library is the namespace/name meta data ... not exactly sure
what the namespace or name are if not specified in meta data ... haven't
looked into that ... however running
var yyy=GM_library();
will return an array of all available libraries namespace/name strings,
if you get my meaning

so, with the above library, you can

xxx.val = 32;


the GM_globalLibrary is identical in function, however all scripts
within a particular window "share" the one copy of the library. I
haven't done any extensive testing of this, but thought it may be useful.

anyway, I've included the four changed greasmonkey files and a test
library (with the above simple stuff and also a wittled down
EventManager I'm using for testing GM_globalLibrary) plus two simple
test scripts that just, hopefully, demonstrate the difference between
global and "private" - maybe I should rename "global" to "shared"??

NOTE: the greasemonkey files are based on the thrid incarnation of
GreaseMonkey 0.4 attempt III - in other words, based on the latest and
greatest ;-)

Have a look, see if I've done anything obviously STUPID ... my
additions/changes are marked with the word "jaro" (long story)

Have fun

-------------- next part --------------
A non-text attachment was scrubbed...
Name: GM_library.zip
Type: application/zip
Size: 26927 bytes
Desc: not available
Url : http://mozdev.org/pipermail/greasemonkey/attachments/20050718/75ddfed4/GM_library-0001.zip

More information about the Greasemonkey mailing list