我创建了一个由工具栏按钮组成的 Firefox 扩展。如何进行设置,以便在安装扩展程序时,该按钮自动出现在主工具栏中。我不希望我的用户必须转到自定义工具栏菜单并将我的按钮拖过来。
From https://developer.mozilla.org/En/Code_snippets:Toolbar#Adding_button_by_default https://developer.mozilla.org/En/Code_snippets:Toolbar#Adding_button_by_default --
当您创建和部署扩展并包含工具栏按钮时
通过覆盖自定义工具栏调色板来实现它,它不可用
默认情况下。用户必须将其拖到工具栏上。下列
默认情况下,代码会将您的按钮放置在工具栏上。这应该
仅在安装后第一次运行插件时完成,因此
如果用户决定删除您的按钮,它就不会显示
每次他们启动应用程序时都会再次出现。
Notes
默认情况下,仅在首次运行时或扩展更新添加新按钮时插入按钮一次。
仅当您的按钮为用户带来真正的价值并且将成为您的扩展程序的频繁入口点时,才默认添加您的按钮。
不得在以下任何元素之间插入工具栏按钮:组合后退/前进按钮、位置
栏、停止按钮或重新加载按钮。这些元素有
彼此相邻放置时的特殊行为,并且如果
由另一个元素分隔。
/**
* Installs the toolbar button with the given ID into the given
* toolbar, if it is not already present in the document.
*
* @param {string} toolbarId The ID of the toolbar to install to.
* @param {string} id The ID of the button to install.
* @param {string} afterId The ID of the element to insert after. @optional
*/
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) {
let 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;
}
}
if (firstRun) {
installButton("nav-bar", "my-extension-navbar-button");
// The "addon-bar" is available since Firefox 4
installButton("addon-bar", "my-extension-addon-bar-button");
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)