firefox - 如何让我的 Firefox 扩展工具栏按钮自动出现?

标签 firefox installation toolbar

我创建了一个由工具栏按钮组成的 Firefox 扩展。如何进行设置,以便在安装扩展程序时,该按钮自动出现在主工具栏中。我不希望我的用户必须转到自定义工具栏菜单并将我的按钮拖到上面。

最佳答案

来自https://developer.mozilla.org/En/Code_snippets:Toolbar#Adding_button_by_default --

When you create and deploy your extension and include a toolbar button for it by overlaying the Customize toolbarpalette, it is not available by default. The user has to drag it onto the toolbar. The following code will place your button on the toolbar by default. This should only be done on the first run of your add-on after installation so that if the user decides to remove your button, it doesn't show up again every time they start the application.

Notes

Insert your button by default only once, at first run, or when an extension update adds a new button.

Please only add your button by default if it adds real value to the user and will be a frequent entry point to your extension.

You must not insert your toolbar button between any of the following elements: the combined back/forward button, the location bar, the stop botton, or the reload button. These elements have special behaviors when placed next to eachother, and will break if separated by another element.

/**
 * 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");
}

关于firefox - 如何让我的 Firefox 扩展工具栏按钮自动出现?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/579656/

相关文章:

firefox - 如何在 Firefox 中使用 vimperator 打开下载窗口

javascript - 火狐插件 : Hidden <browser/> in XUL Overlay?

r - 无法安装 gdtools 或 svglite

ruby-on-rails - 在运行 Debian 的虚拟机上使用 RVM 安装 Ruby 无提示失败

html - Firefox 上的 CSS 布局问题,左列末尾和页脚之间有填充空间

javascript - 如何在 Firefox 中监控 ajax 响应?

.net - 安装 ASP.NET 应用程序的先决条件是什么?

android - 带有自定义 View 的 CollapsingToolbarLayout

iPhone - 出现键盘时工具栏向上移动

wpf - 如何恢复工具栏上复选框的默认样式?