@requirehelper libraries, the user script take on Ruby's
require, or the C family's
#includepre-processor directive. For security reasons, the required library is downloaded a single time at script installation time, and from a functional perspective, is equivalent to pasting the script or scripts referenced at the top of your script, in the order of the
@requirelines listed. (
==UserScript==headers in the referenced files are presently ignored, so a library may not yet use
@resourcelines of its own.)
@requirein practice makes user scripting scale down better, which is essentially to lower the threshold towards getting a job done, to a level where implementation cost to scratch an itch is so low that rather than feeling that mild annoyance with something twice, you address the issue once, and never see it happen again -- on that site, or the web at large. We are still far from there (in as much as "getting there" would ever happen -- that threshold can always be chipped off further, I assure you) -- but
@requireis healthy progress.
This is what the feature can look like in an example script of mine which adds image captions to online comics, by default Dinosaur Comics and xkcd (expect another upcoming post about
// ==UserScript== // @name Image title captions // @namespace http://code.google.com/p/ecmanaut/ // @require http://ecmanaut.googlecode.com/svn/trunk/lib/gm/$x$X.js // ==/UserScript==
I'll be sharing some of my own helpers here, in a little series of "Fun with Greasemonkey" posts. I encourage you to write, and share, your own, on your blog, as well. User script authorship is a very social form of software, especially when you share your results on userscripts.org, and your best practices, for instance by way of blogging.