Tel*_*nor 6 firefox toolbar firefox-addon firefox-addon-sdk
所以我现在多次查看Add-on SDK的文档,没有哪里可以看到如何创建工具栏或修改现有工具栏.他们有一个关于创建附加栏图标的教程,但这不是我想要的.附加SDK是否支持此功能?如果有,可以有人将我链接到示例/教程.
ken*_*der 11
这对我有用:
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);
}
Run Code Online (Sandbox Code Playgroud)
这是对第一个答案的点缀.
如果您在对顶部响应的评论中遇到dcolish描述的困难,请将此添加到main.js:
var tim = require("timers");
intervalId = tim.setInterval(timerFn,2000);
function timerFn() {
var win = mediator.getMostRecentWindow('navigator:browser');
if (win)
var document = win.document;
else
return;
var isBtn = document.getElementById('myappbutton-id');
if (!isBtn) addToolbarButton();
}
Run Code Online (Sandbox Code Playgroud)
它很粗但很有效.
编辑:更简单,更清洁:
var windows = require("windows").browserWindows;
windows.on('open', function(window) {
addToolbarButton();
});
Run Code Online (Sandbox Code Playgroud)
在我的Mac上,Firefox 15会在关闭窗口时自动删除Icon.所以window.on('close', ...)不需要.
| 归档时间: |
|
| 查看次数: |
3246 次 |
| 最近记录: |