Created
June 19, 2012 15:04
-
-
Save boyvanamstel/2954676 to your computer and use it in GitHub Desktop.
Firefox Extension: Add a button to the navigation toolbar
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Source: http://stackoverflow.com/questions/5572632/firefox-how-can-i-add-modify-toolbars-using-the-add-on-sdk-jetpack | |
| // Only works on first window opened.. | |
| var data = require("self").data; | |
| var {Cc, Ci} = require("chrome"); | |
| var mediator = Cc['@mozilla.org/appshell/window-mediator;1'].getService(Ci.nsIWindowMediator); | |
| exports.main = function(options, callbacks) { | |
| addToolbarButton(); | |
| // other stuff | |
| }; | |
| function addToolbarButton() { | |
| var document = mediator.getMostRecentWindow("navigator:browser").document; | |
| var navBar = document.getElementById("nav-bar"); | |
| if (!navBar) { | |
| return; | |
| } | |
| var btn = document.createElement("toolbarbutton"); | |
| btn.setAttribute('type', 'button'); | |
| btn.setAttribute('class', 'toolbarbutton-1'); | |
| btn.setAttribute('image', data.url('img/icon16.png')); // path is relative to data folder | |
| btn.setAttribute('orient', 'horizontal'); | |
| btn.setAttribute('label', 'My App'); | |
| btn.addEventListener('click', function() { | |
| // use tabs.activeTab.attach() to execute scripts in the context of the browser tab | |
| console.log('clicked'); | |
| }, false) | |
| navBar.appendChild(btn); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment