使用Firefox 17.0.1我使用名为 KeyConfig 20110522 的插件来设置一些新热键,并为我的新密钥设置acceltext
menuitems
以及那些无需费心的附加组件。
我希望当Firefox启动时要设置的acceltext
menuitems
,但目前我只是使用热键执行以下针对UI的代码通过 KeyConfig :
document.getElementById("tabmix-menu")
.setAttribute("acceltext","Alt+Ctrl+Shift+T");
// more of the same...
我需要几个初学者提示:
如何以与通过控制台对HTML页面执行相同的方式对UI执行任意代码?
在没有深入研究XUL开发的情况下,是否有一种偷偷摸摸的方法可以在浏览器启动时获得一堆代码?
有没有办法跟踪针对UI执行的命令,这样当我设置热键时,我可以获取命令调用而不是使用触发器:
document.getElementById("tabmix-menu").click();
欢迎任何有关此类低级别黑客攻击的其他提示。
答案 0 :(得分:0)
你可以从一个插件对Firefox UI执行任意代码,但正如你所说,做所有与XUL相关的东西有点无聊: - )
输入“Bootstrapped”扩展程序!
第1部分:
“Bootstrapped”(或重新启动)扩展只需要一个install.rdf文件来识别插件,并需要一个bootstrap.js文件来实现bootstrap接口。
Bootstrapped Extension:https://developer.mozilla.org/en-US/docs/Extensions/Bootstrapped_extensions
很好的例子:http://blog.fpmurphy.com/2011/02/firefox-4-restartless-add-ons.html
引导程序界面可以非常简单地实现:
function install() {}
function uninstall() {}
function shutdown(data, reason) {}
function startup(data, reason) { /* YOUR ARBITRARY CODE HERE! */ }
通过将install.rdf
和bootstrap.js
放入新zip文件的顶层来编译扩展,并将zip文件扩展名重命名为.xpi。
第2部分:
您的代码具有特权,可以使用任何Mozilla平台API。然而,存在时间问题。 “启动”功能执行的时刻是尚未存在Chrome窗口对象的时刻!
如果您的代码对您有Chrome窗口很重要,我们需要等待它出现:
// useful services.
Cu.import("resource://gre/modules/Services.jsm");
var loader = Cc["@mozilla.org/moz/jssubscript-loader;1"]
.getService(Ci.mozIJSSubScriptLoader);
var wmSvc = Cc["@mozilla.org/appshell/window-mediator;1"]
.getService(Ci.nsIWindowMediator);
var logSvc = Cc["@mozilla.org/consoleservice;1"]
.getService(Ci.nsIConsoleService);
// get the first gBrowser
var done_startup = 0;
var windowListener;
function do_startup(win) {
if (done_startup) return;
done_startup = 1;
wmSvc.removeListener(windowListener);
var browserEnum = wmSvc.getEnumerator("navigator:browser");
var browserWin = browserEnum.getNext();
var tabbrowser = browserWin.gBrowser;
/* your code goes here! */
}
// window listener implementation
windowListener = {
onWindowTitleChange: function(aWindow, aTitle) {},
onCloseWindow: function(aWindow) {},
onOpenWindow: function(aWindow) {
var win = aWindow.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowInternal || Ci.nsIDOMWindow);
win.addEventListener("load", function(aEvent) {
win.removeEventListener("load", arguments.callee, false);
if (aEvent.originalTarget.nodeName != "#document") return;
do_startup();
}
};
// CODE ENTRY POINT (put this in bootstrap "startup" function)
wmSvc.addListener(windowListener);