简体   繁体   English

如何将Greasemonkey脚本发布为Firefox附加组件?

[英]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 SDKJPM 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.

相关问题 是否可以通过Greasemonkey脚本使用Firefox附加SDK? - Is it possible to use Firefox Add-on SDK from a Greasemonkey script? 如何从greasemonkey脚本关闭firefox选项卡? - How do I close a firefox tab from a greasemonkey script? 如何从Greasemonkey脚本创建Firefox插件? - How do I create a Firefox addon from a Greasemonkey script? 如何通过Greasemonkey脚本在Firefox中存储数组? - How do I store an array in Firefox from a Greasemonkey script? 如何保留 Firefox 附加弹出窗口的复选框 state? - How do I keep the checkbox state for Firefox add-on popup? 如何在Firefox扩展程序(附加组件)中要求文件? - How do I require files in Firefox extension (add-on)? 将Firefox 30之前的Greasemonkey脚本迁移到GM4 +时,如何替换unsafeWindow? - How do I replace unsafeWindow when migrating a pre-Firefox 30 Greasemonkey script to GM4+? 如何将Greasemonkey脚本转换为无重启的Firefox插件? - How can I convert a Greasemonkey script into a restartless Firefox addon? 如何在 Firefox 控制台中访问附加内容脚本? - How to access add-on content script in Firefox console? 如何知道哪个内容脚本与 Firefox 附加组件中的后台通信? - How to know which content script communicates with the background in a Firefox add-on?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM