【发布时间】:2010-09-21 18:11:59
【问题描述】:
我想写一个 Firefox 扩展。此扩展不是通用扩展,而是专门用于需要突出显示特定 html 组件的域。
我该怎么做?我只想在用户浏览特定域时加载 js。
我当前的overaly.js 基本上是空的(由扩展向导生成):
var myextension = {
onLoad: function() {
// initialization code
this.initialized = true;
this.strings = document.getElementById("myextension-strings");
},
onMenuItemCommand: function(e) {
var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
.getService(Components.interfaces.nsIPromptService);
promptService.alert(window, this.strings.getString("helloMessageTitle"),
this.strings.getString("helloMessage"));
},
onToolbarButtonCommand: function(e) {
// just reuse the function above. you can change this, obviously!
myextension.onMenuItemCommand(e);
}
};
window.addEventListener("load", myextension.onLoad, false);
而我的ff-overlay.xul 是:
myextension.onFirefoxLoad = function(event) {
document.getElementById("contentAreaContextMenu")
.addEventListener("popupshowing", function (e){ myextension.showFirefoxContextMenu(e); }, false);
};
myextension.showFirefoxContextMenu = function(event) {
// show or hide the menuitem based on what the context menu is on
document.getElementById("context-myextension").hidden = gContextMenu.onImage;
};
window.addEventListener("load", myextension.onFirefoxLoad, false);
我正在考虑去尼安德特人并在myextension.onFirefoxLoad 内部进行检查,以查看当前页面是否是我想要的页面,但这需要用户单击上下文菜单上的正确项目。
【问题讨论】:
标签: firefox firefox-addon