[Greasemonkey] Per-script unique ID

Mihai Parparita mihai.parparita at gmail.com
Mon Apr 25 11:02:10 EDT 2005

I ran into this code pattern this weekend, perhaps others may find it
useful too:

I want each installed instance of my user script to have a unique ID,
so that it can identify itself with a central server (nothing evil, I
promise). I could, instead of serving a static user script file,
generate them on the fly, but that seems like too much hassle. I could
ask the user to input an ID, but then I'd have to check with the
central server to make sure it's unique.

My solution is instead to use a centralized random number generator,
and given a large enough space, collisions are very unlikely to occur.
This sounds like even more hassle, until you realize that random.org
already provides this service. They have a nice REST-y API, and one
can use GM_xmlhttpRequest with a URL like
http://www.random.org/cgi-bin/randbyte?nbytes=16&format=h. The
resulting 16 bytes can be stored with GM_setValue, and will
subsequently uniquely identify the user script.

Yes, this is basically a re-implementation of the session id cookie pattern.


More information about the Greasemonkey mailing list