|
var doc = document; |
|
var win = doc.defaultView; |
|
|
|
var toolbox = doc.querySelector('#navigator-toolbox'); |
|
|
|
var buttonId = 'bpMyBtn'; |
|
var button = doc.getElementById(buttonId); |
|
if (!button) { |
|
button = doc.createElementNS('http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul', 'toolbarbutton'); |
|
button.setAttribute('id', buttonId); |
|
button.setAttribute('label', 'My Button'); |
|
button.setAttribute('tooltiptext', 'My buttons tool tip if you want one'); |
|
button.setAttribute('class', 'toolbarbutton-1 chromeclass-toolbar-additional'); |
|
button.style.listStyleImage = 'url("https://gist.githubusercontent.com/Noitidart/9266173/raw/06464af2965cb5968248b764b4669da1287730f3/my-urlbar-icon-image.png")'; |
|
button.addEventListener('command', function() { |
|
alert('you clicked my button') |
|
}, false); |
|
|
|
toolbox.palette.appendChild(button); |
|
} |
|
|
|
//move button into last postion in nav-bar |
|
var navBar = doc.querySelector('#nav-bar'); |
|
navBar.insertItem(buttonId); //if you want it in first position in navBar do: navBar.insertItem(buttonId, navBar.firstChild); |
|
navBar.removeChild(button); |
|
|
|
/* |
|
//move button into last postion in TabsToolbar (i tested in this Australis I dont know if version less than 29 allow icons in toolbar) |
|
var tabsToolbar = doc.querySelector('#TabsToolbar'); |
|
tabsToolbar.insertItem(buttonId); //if you want it in first position in tabsToolbar do: tabsToolbar.insertItem(buttonId, tabsToolbar.firstChild); |
|
|
|
//move button into last postion in addon-bar (Australis doesnt have addon bar anymore, but a shim is in place so it will auto get moved to navBar) |
|
var addonBar = doc.querySelector('#addon-bar'); |
|
addonBar.insertItem(buttonId); //if you want it in first position in navBar do: addonBar.insertItem(buttonId, addonBar.firstChild); |
|
*/ |
README
Rev1
Fork from dgutov / bmreplace / bootstrap.js
Discussion about this method on Mozillazine - Programmatically add a button to toolbar palette?
Updated article on MDN: Creating toolbar buttons (Customize Toolbar Window) - Adding the Button Bootstrap Style
The Gist is not yet in a snippet form, so can't copy pate to Scratchpad yet.
This is the XUL Overlay equivalent of:
Rev2
Rev3
Rev4
TabsToolbar
andaddon-bar