Userscript Updater Generator is a GAE application for Greasemonkey scriptwrights to make any userscript on userscripts.org auto-updatable.
In the metadata section of your userscript, add
// @require http://userscript-updater-generator.appspot.com/?id=<userscript id>[&day=<update interval>][&hour=<update interval>]
[// @title <userscript alias>]
[// @version <userscript version>]
[/* @reason
<update notes>
@end */]
and it is done. Parameters and options are explained below.
Required. The id of your userscript on userscript.org, whose homepage is http://userscripts.org/scripts/show/<userscript id>.
Optional. Must be a postive integer. Stand alone or combined with parameter hour to specify the minimal time between two checks for update, which by default is 12 hours.
Optional. Must be a postive integer. Stand alone or combined with parameter day to specify the minimal time between two checks for update, which by default is 12 hours.
Optional. Would appear in concerned menu items and prompts replacing the original name of your userscript specified by @name. Should not contain any double quotation mark(").
Optional. Should not contain any double quotation mark("). Userscript Updater Generator decides there is a new release when auto-generated @uso:version increases. If meanwhile @version (that you specifies) increases as well, it will be displayed in the update messagebox. Any character other than 0~9 and "." in @version will be neglected when compared.
Optional. Anything you write with @reason would show up along with @version in the update messagebox, i.e., if @version is not shown, neither is @reason. I often list fixed bugs and new features here.
简单到只需要在你开发的脚本的注释段(也称meta部分)添加一行代码:
// @require http://userscript-updater-generator.appspot.com/?id=<脚本id>
对于你的脚本,将<脚本id>换成其在userscripts.org上的id即可。加入这行代码后并上传到userscripts.org后,你的脚本会在Greasemonkey菜单中添加“立即更新xx脚本”的菜单项,并且每12个小时检查一次更新;只要userscripts.org上的脚本有了更新(判断条件是网站自动生成的@uso:version标示的增长,而不是@version标示的增长,因此每一次更新都不会错过),就会弹出对话框提示用户更新脚本。
在url中传递的参数除了必需的id外,还可以有day和hour。这两个参数都是用来设置检查脚本更新时间间隔的,合法的值都是正整数。url里day和hour两个参数并存时,检查间隔是两者之和,比如day=2&hour=12,就是每隔两天半检查一次。当这两个参数都不存在或都不合法时,默认每12个小时检查一次。作为例子,以下三个url都是合法的:
// @require http://userscript-updater-generator.appspot.com/?id=<脚本id>&day=35&hour=57
// @require http://userscript-updater-generator.appspot.com/?id=<脚本id>&day=7
// @require http://userscript-updater-generator.appspot.com/?id=<脚本id>&hour=8
通过在脚本注释段(meta部分)添加其他信息,可以获得更好的提示效果。可以添加的信息有:
// @title <脚本名>
脚本名在添加菜单项和弹出对话框提示里都会用到。如果没有@title,就会以@name的标示作为脚本名;如果连@name都没有(这个一般不会发生),就会以“[<脚本id>]”作为脚本名。很多脚本的@name标示是英文的,如果要显示中文脚本名,可以写在@title里。(脚本名不能包含双引号,结尾带不带“脚本”两个字都行,程序能够自动识别处理:对“xyz脚本”和“xyz”,提示信息都是一样的。)
// @version <版本号>
脚本的更新与否并不依赖@version标示,但是当存在@version标示时,如果新版本的@version标示高于上个版本的@version标示,那么在提示更新时会显示脚本已更新至xxx版。(程序可以识别并比较类似“v1.2.0”和“1.2.0版”的版本号,但是版本号不能包含双引号。)
/* @reason
<更新说明>
@end */
作为@version标示的附属存在。如果@version标示增长了,并且@reason标示存在,那么在提示脚本已更新至xxx版的同时也会显示更新说明。
适用于Firefox和其他支持Greasemonkey中@require, GM_xmlhttpRequest, GM_getValue和GM_setValue的浏览器,并且脚本必须位于userscripts.org上。