我想寫一個Firefox擴展。此擴展不是一個通用的擴展,但專門爲需要突出顯示特定html組件的域而工作。限制Firefox的擴展到一個特定的域
我該怎麼做?我只想在用戶瀏覽特定域時加載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
以查看當前頁面是否是我想要的頁面,但需要用戶單擊上下文菜單上的適當項目。
這是'onPageLoad'我正在尋找。我有第二個問題與此有關。由於我不需要編輯瀏覽器UI,我是否仍然需要'overlay.xul'?在這一點上,它應該是一個默認的'overlay.xul',只有'script'標籤來調用擴展js文件? – dierre 2010-09-23 11:52:25
是的,我想是的。只需包含您的腳本標籤,並且可能需要一個字符串來將字符串外部化。然後,如果您稍後決定添加其他內容,則始終可以這樣做。 – MatrixFrog 2010-09-23 18:17:23