我怎样才能把它编译成一个firefox插件?我曾尝试使用位于 https://builder.addons.mozilla.org的 Firefox 插件构建器,但是当我单击测试时,它显示“XPI 未构建”。谁能告诉我如何将这段代码变成一个函数 firefox 扩展?谢谢你。
//create an nsIObserver implementor
var listener = {
observe : function(aSubject, aTopic, aData) {
var httpChannel = aSubject.QueryInterface(Components.interfaces.nsIHttpChannel);
if (aTopic == "http-on-modify-request") {
var channel= aSubject.QueryInterface(Components.interfaces.nsIHttpChannel);
if(channel.requestMethod == "POST")
{
channel=channel.QueryInterface(Components.interfaces.nsIUploadChannel);
channel = channel.uploadStream;
channel.QueryInterface(Components.interfaces.nsISeekableStream)
.seek(Components.interfaces.nsISeekableStream.NS_SEEK_SET, 0);
var stream = Components.classes["@mozilla.org/binaryinputstream;1"]
.createInstance(Components.interfaces.nsIBinaryInputStream);
stream.setInputStream(channel);
var postBytes = stream.readByteArray(stream.available());
poststr = String.fromCharCode.apply(null, postBytes);
//change the poststr
// poststr=poststr.replace(....);
// ERROR HERE - stringStream is not defined
stringStream.setData(poststr, poststr.length);
//changing the postdata
channel = channel.QueryInterface(Components.interfaces.nsIUploadChannel);
channel = channel.uploadStream;
channel = channel.QueryInterface(Components.interfaces.nsISeekableStream)
.seek(Components.interfaces.nsISeekableStream.NS_SEEK_SET, 0);
channel.uploadStream.QueryInterface(Components.interfaces.nsIMIMEInputStream);
channel.uploadStream.setData(stringStream);
channel.requestMethod = "POST";
}
}
},
QueryInterface : function(aIID) {
if (aIID.equals(Components.interfaces.nsISupports) ||
aIID.equals(Components.interfaces.nsIObserver))
return this;
throw Components.results.NS_NOINTERFACE;
}
};
var observerService = null;
var Init = {
addObserver : function(){
observerService = Components.classes["@mozilla.org/observer- service;1"].getService(Components.interfaces.nsIObserverService);
observerService.addObserver(listener, "http-on-modify-request", false);
},
removeObserver : function(){
observerService.removeObserver(listener, "http-on-modify-request");
}
};
Init.addObserver();
- 编辑:我已经阅读了官方的 Firefox 文档,但它令人困惑,它主要处理基于 gui 的插件,并且没有提供太多示例,我将如何为此创建扩展。