[Greasemonkey] ISWEST - Idiot-Simple WEb STorage
Anton Berezin
tobez at tobez.org
Thu Jun 22 15:49:10 EDT 2006
Hi,
People on this list discussed various web-based storage systems. As far
as I can tell, two common complaints were the complexity of the existing
APIs, and the non-free nature of some of them.
It would be nice to have a system that addresses those concerns.
In the context of Greasemonkey, such a system has rather modest
requirements. Mainly it is to supplement local scripts' storage. This
means that there is no intention to pump gigabytes of data in and out.
This also means that things like BitTorrent support are not needed,
while the ability to store and fetch arbitrarily complex Javascript data
structures would come in handy.
I propose the following protocol for GM web storage, dubbed Idiot-Simple
WEb STorage, or ISWEST for short:
http://iswest.tobez.org/docs/api.txt
A simple JavaScript class suitable for use in Greasemonkey scripts would
be:
http://iswest.tobez.org/docs/gm-api.js.txt
Using this class, an example of using ISWEST API from Greasemonkey
scripts would be:
var iswest = new Iswest("http://iswest.tobez.org/iswest.cgi/", "this-is-rw-id");
iswest.put(
function (d) {
iswest.get(
function (r) {
alert("got a: " + r.data.a + ", b: " + r.data.b);
},
"test-key"
);
},
"test-key",
"{a: 1, b: 2}"
);
This example uses pre-stringified JSON ("{a: 1, b: 2}") in the put
request. If one intends storing complex data structures using ISWEST
API, one should use any of the available JSON stringifiers, for
example, from http://www.json.org/. In this case Iswest class
should be modified accordingly, so that put() method itself performs the
JSON stringification.
Quite obviously, other methods could be used, such as creating a script
element pointing to an ISWEST server, using JSONP variety of the API.
In lieu of a real-life example, I also took a liberty to modify the
Google Calendar TODO script from Matias Pelenur
(http://userscripts.org/scripts/show/3827) to use ISWEST API.
The modified version of the script could be found at
http://iswest.tobez.org/examples/google-calender-todo.user.js .
I would imagine that this example would be more useful if it were to ask
for the base URI and for the ID when it runs for the first time, but for
this proof of concept one has to modify the script before the
installation.
The pilot implementation of the API is running with a base URL of
http://iswest.tobez.org/iswest.cgi
For now, to obtain your pair of read-write and read-only IDs, just
drop me an E-mail, and I will generate them for you. For now, I intend
to put moderate restrictions, so that the maximum number of keys per ID
pair will be 5000, the maximum length of the key name will be 256
characters, and the maximum length of the data per key will be 500000
bytes. I estimate this to be more than enough for GM web storage needs.
In fact, I would be reluctant to provide the service with limits that
high to the general public. I assume that the crowd on this list is the
responsible one, and won't abuse my puny server.
The usual "no warranties of any kind, it will kill your hamster, yada
yada yada" applies here.
If you wish to roll out your own server, the version that currently runs
at http://iswest.tobez.org/ can be found right there.
If you create a Web-based ID generation script (E-mail activation,
anyone?) before I do so myself, I'd appreciate it if you let me know and
share the sources.
Cheers,
\Anton.
--
An undefined problem has an infinite number of solutions.
-- Robert A. Humphrey
More information about the Greasemonkey
mailing list