我使用下面的代码在 Firefox Australis 下面的导航工具栏中自动添加工具栏按钮。
var buttonId = "toolbarbutton-toolbarbutton";
var navBar = document.getElementById("nav-bar");
var currentSet = navBar.currentSet;
var curSet = currentSet.split(",");
if (curSet.indexOf(buttonId) == -1)
{
navBar.insertItem(buttonId);
navBar.setAttribute("currentset", navBar.currentSet);
document.persist("nav-bar", "currentset");
try
{
top.BrowserToolboxCustomizeDone(true);
}
catch (e)
{
}
}
由于 Australis 的用户界面和模块发生了更改,因此需要更新代码。如何正确添加 Australis 工具栏按钮?
最佳答案
您必须使用CustomizableUI
module :
try
{
Components.utils.import("resource:///modules/CustomizableUI.jsm");
CustomizableUI.createWidget({
id: "toolbarbutton-toolbarbutton",
defaultArea: "nav-bar",
removable: true,
label: "My button",
tooltiptext: "My tooltip text",
onClick: function()
{
alert("Clicked");
}
});
}
catch (e)
{
Components.utils.reportError(e);
// No such module? Try the old approach.
...
}
请注意,不再需要为每个浏览器窗口添加小部件,只需添加一次即可。不幸的是,模块文档现在几乎不存在,上面的代码是从 module's source code 推导出来的。 。不过,文档应该很快就会改进。
如果有帮助的话,Adblock Plus 源代码包含 emulation of the CustomizableUI API对于较旧的 Firefox 版本。然而,这还远未完成,它只是为了满足 Adblock Plus 的需求。
关于firefox - 如何为 Firefox Australis 添加工具栏按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20919288/