1

我已经为 Firefox 开发了一个附加组件,并且可以在 Windows Firefox 中安装,但是在 linux mint 中,我必须转到查看菜单,然后是工具栏并选择个性化以将创建的附加组件按钮放在我的萤火虫附近的工具栏上(我的意思是其他插件共存的地方)

4

1 回答 1

1

要自动将工具栏按钮放在导航栏上,仅创建按钮是不够的。您必须将其添加到工具栏中的“当前集”图标中。如果你不这样做,它只会被添加到

我的猜测是你的代码也不能在 Windows 上运行。您可能前段时间手动将其添加到工具栏中,并且从那以后它就在那里。(尝试在空白配置文件中安装您的插件)。

要使其自动“持久化”,您可以在第一次运行插件时将其添加到当前集合中,如下所示:

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

参考:工具栏 - 代码片段

于 2013-10-13T14:35:42.473 回答