介紹
官方文件
請先看基本 Add-on 製作方法
Context menu 讓你能在右鍵新增選單,你要使用 context menu 模組
首先 index.js 程式碼如下
1 2 3 4 5 6 7 8 9 10 11 12
| 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.error(selectionText); } });
|
你可以在前面加上小圖案
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| var self = require("sdk/self");
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);' + '});', image: self.data.url("icon-16.png"), onMessage: function (selectionText) { console.log(selectionText); } });
|
另外你已可以加入快捷鍵,注意只能一個字元
1 2 3 4 5 6 7 8 9 10 11 12 13
| 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);' + '});', accessKey: "l", onMessage: function (selectionText) { console.log(selectionText); } });
|