如何在首次安装时在插件栏上添加图标?

发布于 2024-10-31 06:30:21 字数 1423 浏览 2 评论 0原文

我按照此文档 Mozilla 开发者网络:创建工具栏按钮 为我的插件创建一个按钮。它确实有效,但是当我第一次安装插件时,图标没有显示在插件栏上。

如何让图标在用户安装我的插件后立即出现在插件栏上,然后保留他的位置首选项?

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="chrome://.../content/firefox/browser.css"?>

<overlay xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">

  <script type="text/javascript" src="chrome://...../content/firefox/browser.js" />

  <toolbarpalette id="BrowserToolbarPalette">
    <toolbarbutton id=".....-button" class="toolbarbutton-1 chromeclass-toolbar-additional"
      label="...." tooltiptext="Facebook Manager"
      oncommand="System.......Toolbar.Show(event)" />
  </toolbarpalette>

</overlay>

如何将按钮自动添加到插件栏一次?

我发现这段代码以编程方式添加按钮,它显示了我的按钮,但它与其他按钮混淆了。

var myId    = "myaddon-button";
var navBar  = document.getElementById("addon-bar");
var curSet  = navBar.currentSet.split(",");

if (curSet.indexOf(myId) == -1) {
    var set = curSet.slice(0, curSet.length).concat(myId).concat(curSet.slice(curSet.length));

    navBar.setAttribute("currentset", set.join(","));
    navBar.currentSet = set.join(",");
    document.persist(navBar.id, "currentset");
    try {
        BrowserToolboxCustomizeDone(true);
    }
    catch (e) {}
}

I followed this doc Mozilla Developer Network: Creating toolbar buttons to create a button for my addon. It does work, but when I install the addon the first time the icon doesn't show on the addon bar.

How can I make the icon appear on the addon bar right after the user install my addon and then keep his location preference?

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="chrome://.../content/firefox/browser.css"?>

<overlay xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">

  <script type="text/javascript" src="chrome://...../content/firefox/browser.js" />

  <toolbarpalette id="BrowserToolbarPalette">
    <toolbarbutton id=".....-button" class="toolbarbutton-1 chromeclass-toolbar-additional"
      label="...." tooltiptext="Facebook Manager"
      oncommand="System.......Toolbar.Show(event)" />
  </toolbarpalette>

</overlay>

How can I add the button automatically to addon bar only once?

I found this code to add the button programmatically, it shows my button, but it messes up with the other buttons.

var myId    = "myaddon-button";
var navBar  = document.getElementById("addon-bar");
var curSet  = navBar.currentSet.split(",");

if (curSet.indexOf(myId) == -1) {
    var set = curSet.slice(0, curSet.length).concat(myId).concat(curSet.slice(curSet.length));

    navBar.setAttribute("currentset", set.join(","));
    navBar.currentSet = set.join(",");
    document.persist(navBar.id, "currentset");
    try {
        BrowserToolboxCustomizeDone(true);
    }
    catch (e) {}
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

迷荒 2024-11-07 06:30:21

插件栏工作正常。

你只需要把你的元素放在工具栏中并给它一个 addon-bar 的 id
示例:

你的 js 放在这里

    <toolbar id="addon-bar">
        <menulist>
            <your dropdown blah blah blah>
        </menulist>
    </toolbar
</overlay>

addon-bar is working fine.

you just have to put your elements inside the toolbar and give it an id of addon-bar
example:

your js goes here

    <toolbar id="addon-bar">
        <menulist>
            <your dropdown blah blah blah>
        </menulist>
    </toolbar
</overlay>
梦旅人picnic 2024-11-07 06:30:21

添加按钮不是“安装操作”。您只需将该按钮声明为叠加层的一部分,并在应用扩展叠加层时将其添加进去。

无论如何,看起来您正在将按钮添加到工具栏选项板中...因此,当您右键单击顶部工具栏并单击“自定义...”时,它将显示在按钮的大列表中

插件栏位于底部,您可以像这样添加:

<toolbar id="addon-bar">
  <!-- your elements go here. toolbarbutton, etc -->
</toolbar>

It's not an "install action" to add your button. You simply declare the button as part of the overlay and it's added in when your extension overlay is applied.

Anyway, it looks like you're adding the button to the toolbar palette... so it will show up in the big list of buttons when you right click on the top toolbar and click "Customize..."

The addon bar is at the bottom and you can add to it like so:

<toolbar id="addon-bar">
  <!-- your elements go here. toolbarbutton, etc -->
</toolbar>
听不够的曲调 2024-11-07 06:30:21

看来 addon-bar 已损坏,但我可以通过查看 Firebug 的代码将其添加到 nav-bar 上。

if (firstrun) // from preferences
{
    Services.prefs.setBoolPref("extensions.addon.FirstRun", false);
    Services.prefs.setCharPref("extensions.addon.InstalledVersion", curVersion);

    var startButtonId = "addon-button";
    var navBar = document.getElementById("nav-bar");
    var currentSet = navBar.getAttribute("currentset");
    if (!currentSet)
        currentSet = navBar.currentSet;

    var curSet = currentSet.split(",");
    if (curSet.indexOf(startButtonId) == -1)
    {
        var set = curSet.concat(startButtonId);
        navBar.setAttribute("currentset", set.join(","));
        navBar.currentSet = set.join(",");
        document.persist(navBarId, "currentset");

        try
        {
            BrowserToolboxCustomizeDone(true);
        }
        catch (e) {}
    }
}

It seems that the addon-bar is broken, but I could add it on nav-bar looking at Firebug's code.

if (firstrun) // from preferences
{
    Services.prefs.setBoolPref("extensions.addon.FirstRun", false);
    Services.prefs.setCharPref("extensions.addon.InstalledVersion", curVersion);

    var startButtonId = "addon-button";
    var navBar = document.getElementById("nav-bar");
    var currentSet = navBar.getAttribute("currentset");
    if (!currentSet)
        currentSet = navBar.currentSet;

    var curSet = currentSet.split(",");
    if (curSet.indexOf(startButtonId) == -1)
    {
        var set = curSet.concat(startButtonId);
        navBar.setAttribute("currentset", set.join(","));
        navBar.currentSet = set.join(",");
        document.persist(navBarId, "currentset");

        try
        {
            BrowserToolboxCustomizeDone(true);
        }
        catch (e) {}
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文