【问题标题】:Add toolbar button and menu item in Firefox在 Firefox 中添加工具栏按钮和菜单项
【发布时间】:2014-02-21 01:34:53
【问题描述】:

我正在尝试开发 Firefox 插件。我已经为扩展开发了基本的 javascript 代码。现在我想要工具菜单中的一个菜单项和一个工具栏按钮。但是,我无法让这两个元素出现(该按钮应出现在自定义菜单、IMO 和工具菜单中的菜单项中)。我做错了什么?

这是 chrome.manifest 文件:

content     droptunesshuffle    chrome/content/
content     droptunesshuffle    chrome/content/ contentaccessible=yes
overlay chrome://browser/content/browser.xul chrome://droptunesshuffle/content/browser.xul

locale  droptunesshuffle    en-US   locale/en-US/

skin    droptunesshuffle    classic/1.0 skin/
style   chrome://global/content/customizeToolbar.xul chrome://droptunesshuffle/skin/skin.css

这里是 browser.xul 覆盖文件:

<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="chrome://global/skin/" ?>
<?xml-stylesheet href="chrome://droptunesshuffle/skin/skin.css" type="text/css"?>
<!DOCTYPE overlay SYSTEM "chrome://droptunesshuffle/locale/en-US/translations.dtd">
<overlay id="sample" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">

        <script type="application/x-javascript src="chrome://droptunesshuffle/content/shuffle.js" />

        <menupopup id="menu_ToolsPopup">

            <menuitem label="Droptunes Shuffle "key="link-target-finder-run-key" oncommand="droptunesshuffle.run()"/>
        </menupopup>


        <keyset>
            <key id="droptunes-shuffle-run-key" modifiers="shift" key="S" oncommand="droptunesshuffle.run()"/>
        </keyset>

        <toolbarpalette id="BrowserToolbarPalette">
            <toolbarbutton id="droptunes-shuffle-toolbar-button" class=”toolbarbutton-1 chromeclass-toolbar-additional” image="chrome://droptunesshuffle/skin/icon.png" label="Droptunes Shuffle" tooltiptext="&droptunesshuffle;" oncommand="droptunesshuffle.run()"/>
        </toolbarpalette>
</overlay>

skin.css 文件:

#droptunes-shuffle-toolbar-button{
list-style-image: url("chrome://droptunesshuffle/skin/icon.png");

}

【问题讨论】:

    标签: firefox firefox-addon


    【解决方案1】:

    这是一个引导插件。运行代码,它将为所有窗口添加一个上下文菜单。

    https://gist.github.com/Noitidart/8776519

    现在只需将添加上下文菜单更改为添加到已经存在的菜单项上下文。 在我的要点中,将上下文菜单 ID 更改为“menu_ToolsPopup”,这会将菜单项添加到工具菜单中。

    要添加工具栏按钮,请执行与创建菜单项相同的操作,但现在创建一个 'toolbarbutton' 元素并将其附加到 id 'nav-bar'。

    【讨论】:

    • 谢谢。我会试试看。你能告诉我,为什么我的代码不起作用?
    • 我不确定,我不太会使用叠加层。我最近才开始使用 chrome.manifest
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-30
    • 1970-01-01
    • 1970-01-01
    • 2011-09-30
    相关资源
    最近更新 更多