[英]How do I publish a Greasemonkey script as a Firefox add-on?
I recently have worked on a script in Greasemonkey and would like to publish it as an add-on for Firefox. 我最近在Greasemonkey上编写了一个脚本,并希望将其作为Firefox的附加组件发布。 What is the easiest way to do this? 最简单的方法是什么?
While you can "compile" a GreaseMonkey script (see Brock's answer), this solution isn't exactly well-supported. 虽然您可以“编译”GreaseMonkey脚本(请参阅Brock的答案),但此解决方案并未得到完全支持。 The more reliable option would be using the Add-on SDK and JPM . 更可靠的选择是使用Add-on SDK和JPM 。 Your lib/main.js
file can be really simple ( page-mod
module documentation ): 你的lib/main.js
文件非常简单( page-mod
模块文档文档 ):
var data = require("sdk/self").data;
var pageMod = require("sdk/page-mod");
pageMod.PageMod({
include: "*.example.com",
contentScriptWhen: 'end',
contentScriptFile: data.url("contentScript.js")
});
This is equivalent to the following GreaseMonkey script header: 这相当于以下GreaseMonkey脚本标题:
// @include http://example.com/*
// @include http://*.example.com/*
And then you add your GreaseMonkey script as data/contentScript.js
(Add-on SDK will ignore the GreaseMonkey header, the info is specified elsewhere) and build the extension. 然后将GreaseMonkey脚本添加为data/contentScript.js
(附加SDK将忽略GreaseMonkey标头,信息在别处指定)并构建扩展。 In most cases it will just work - unless your GreaseMonkey script uses any special GreaseMonkey API of course, in which case you will need to find a replacement. 在大多数情况下,它只会起作用 - 除非您的GreaseMonkey脚本当然使用任何特殊的GreaseMonkey API,在这种情况下您需要找到替代品。 unsafeWindow
is supported by the way (usual warnings apply). unsafeWindow
受到支持 (通常适用警告)。
Just post your script at
userscripts.org
1 OpenUserJS.org (Or one of the other userscripts.org replacements). 只需在
userscripts.org上
发布您的脚本1 OpenUserJS.org (或其他userscripts.org替换之一)。
Trying to repackage it as an add-on is usually more trouble than it is worth. 尝试将其重新打包为附加组件通常比它的价值更麻烦。
If you really must, you can use the Greasemonkey script compiler to turn your script into an "add-on", and then submit that add-on to Mozilla, via the normal add-on process . 如果你真的必须,你可以使用Greasemonkey脚本编译器将你的脚本变成一个“附加组件”,然后通过正常的附加过程将该附加组件提交给Mozilla 。
Note that Wladimir's answer is better than the Greasemonkey script compiler. 请注意,Wladimir的答案比Greasemonkey脚本编译器更好。
1 Userscripts.org is now long dead . 1 Userscripts.org现在已经死了 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.