我正在创建一个 firefox 插件,当单击工具栏按钮时,它会在新选项卡中打开一个网站。当我单击工具栏按钮时,我没有得到响应。我的代码中有什么遗漏吗?
第1部分:
var app = function () {
var prefManager = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
return {
init : function () {
gBrowser.addEventListener("load", function () {
var toRun = prefManager.getBoolPref("extensions.app.autorun");
if (autoRun) {
app.run();
}
}, false);
},
run : function () {
var head = content.document.getElementsByTagName("head")[0],
style = content.document.getElementById("app-style"),
allLinks = content.document.getElementsByTagName("a"),
foundLinks = 0;
if (!style) {
style = content.document.createElement("link");
style.id = "app-style";
style.type = "text/css";
style.rel = "stylesheet";
style.href = "chrome://app/skin/skin.css";
head.appendChild(style);
}
},
click : function () {
gBrowser.addEventListener("click", function () {
gBrowser.addTab("https://www.google.com");
}, false);
},
}
};
第2部分:
function installButton(toolbarId, id, afterId) {
if (!document.getElementById(id))
var toolbar = document.getElementById(toolbarId);
// If no afterId is given, then append the item to the toolbar
var before = null;
if (afterId) {
var elem = document.getElementById(afterId);
if (elem && elem.parentNode == toolbar)
before = elem.nextElementSibling;
}
toolbar.insertItem(id, before);
toolbar.setAttribute("currentset", toolbar.currentSet);
document.persist(toolbar.id, "currentset");
if (toolbarId == "addon-bar")
toolbar.collapsed = false;
}
};
Application.getExtensions(function (extensions) {
var extension = extensions.get("app@app.com");
installButton("nav-bar", "app-toolbar-button");
});
window.addEventListener("load", app.init, false);
window.addEventListener("click", app.click, false);