So far GM_setValue and GM_getValue
only support integers, boolean and strings. It would be nice if
they supported objects as well, in order to load/save a bunch of
values (this object properties) at once.
As i see it, a preferences branch would be named after the
key parameter, with object properties saved as
key.propertyName values of this branch.
Example code:
// ==UserScript==
// @name name
// @namespace namespace
// ==/UserScript==
var object = {
aBoolean = true,
aInt = 1,
aString = "string"
}
GM_setValue("key", object);
about:config would thus contain the following:
webmonkey.scriptvals.namespace/name.key.aBoolean = true
webmonkey.scriptvals.namespace/name.key.aInt = 1
webmonkey.scriptvals.namespace/name.key.aString = string
GM_getValue("key") would perform the opposite
operation.
Notes:
- Such preferences values would also be reachable individually
using the standard syntax.
- The mechanism could be recursive: it could support properties
of
Object type as well, as long as there is no
reference loops (same as JSON).
- Safe manipulation of the (possibly trapped) object is
required