[Greasemonkey] Stigmergic user script pattern

Johan Sundström oyasumi at gmail.com
Sat Apr 15 19:12:28 EDT 2006


Inspired by a recent Jon Udell podcast, I just wrote up an article on
some useful GM script practices I've played a lot with recently,
componentizing GM scripts into page miners and microformat consumers.
This mail is the less thought bloated version of said article,

http://ecmanaut.blogspot.com/2006/04/stigmergic-user-script-pattern.html

and the idea is to avoid marrying aspects of scripts that don't
absolutely have to be.

For an "instant gallery browser" script such as
http://userscripts.org/scripts/show/3791 which turns image links into
a gallery browser application, it made sense not to include bits to
parse pages employing the shady practice of using thumbnail click
handlers for image popups (rather than just linking to the larger
images), for instance.

One (or a whole set of) small script(s) that derive proper image links
from more backwards types of image links (this typically needs doing
on a site by site basis), and another script to pick up the image
links and do things with them.

Benefits:
* Each script does one thing well, and can evolve without affecting the other.
* The script actually doing something can be exchanged for other
scripts operating on the same kind of input.

This is not limited to harvesting image links, but can be done just as
well using any kind of microformat as an interfacing point, or message
passing architecture, or whatever you feel like calling the stigmergic
behaviour (communicating by changing the environment).

And maybe this description got a bit needlessly dense, instead. But
it's a very useful practice, and I'd love to see more script
cooperation along these lines. It's something it would be useful to
tag scripts with at userscripts.org -- provides:image-links and
consumes:image-links respectively, in the given example, for being
able to tie together related scripts that plug into one another.

I think you need to install providers prior to consumers to get it to
work properly in GM today. We could probably eventually do with
evolving this metadata right into the GM script headers to have it
resolve and work automatedly for us in the future, once we come up
with good forms for it.

--
 / Johan Sundström, http://ecmanaut.blogspot.com/


More information about the Greasemonkey mailing list