赞
踩
参考:https://developer.mozilla.org/en-US/Add-ons/SDK
最近看了很多关于Mozilla Firefox扩展开发的东西,Extension、add-on、plugin,着实有些迷糊了。还好后来发现了jpm:
jpm:Jetpack Manager for Node.jsReplacing the previous python tool for developing Firefox Add-ons, cfx, jpm is a utility for developing, testing, and packaging add-ons.
jpm是专门用于开发、测试和打包Firefox Add-ons的。下面就来说说如何使用jpm开发add-on吧!
1、安装node.jshttps://developer.mozilla.org/en-US/Add-ons/SDK/Tutorials/Adding_a_Button_to_the_Toolbar
第3步中index.js内容改为如下即可:
- var buttons = require('sdk/ui/button/action');
- var tabs = require("sdk/tabs");
-
- var button = buttons.ActionButton({
- id: "mozilla-link",
- label: "Visit Mozilla",
- icon: {
- "16": "./icon-16.png",
- "32": "./icon-32.png",
- "64": "./icon-64.png"
- },
- onClick: handleClick
- });
-
- function handleClick(state) {
- tabs.open("https://www.mozilla.org/");
- }
同时在my-addon目录下创建data目录,下面放icon-16.png、icon-32.png、icon-64.png三张图片。jpm run即可看到效果。
2)、Add a Context Menu Itemhttps://developer.mozilla.org/en-US/Add-ons/SDK/Tutorials/Add_a_Context_Menu_Item
第3步中index.js内容改为如下即可:
- var contextMenu = require("sdk/context-menu");
- var menuItem = contextMenu.Item({
- label: "Log Selection",
- context: contextMenu.SelectionContext(),
- contentScript: 'self.on("click", function () {' +
- ' var text = window.getSelection().toString();' +
- ' self.postMessage(text);' +
- '});',
- onMessage: function (selectionText) {
- console.log(selectionText);
- }
- });
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。