Firefox插件无法转换为引导 [英] Firefox addon could not convert to bootstrap
问题描述
以下我已经有了 xul addon 的代码,可以很好地工作。
在浏览器启动时显示用户名和密码输入,当主题是http-on-examine-response时,它将验证并写入指定的文件。
但是当我尝试转换它的引导扩展它甚至不会显示在浏览器启动时输入的用户名密码,当我编译和运行时没有任何显示在控制台中。
我把组件改成Cu / Cc / etc之后,弄不清楚错误的东西。
我在下面提到的链接
https://developer.mozilla.org/en/Add-ons/Bootstrapped_extensions
https://github.com/Noitidart/l10n/tree/xhtml-xul 以下是我的代码: 我弄清楚我错过了什么。作为Firefox的初学者,我错过了添加注册,取消注册的功能。我做了一个多么愚蠢的错误?唷。无论如何,我希望这个答案将有助于像我这样的新手。 Below I have the code for xul addon which works expectedly. i.e. shows username and password input at the browser startup and whenever the topic is http-on-examine-response it validates and write in specified file. But when I try to convert it to a bootstrapped extension it won't even show the username password input at the browser startup and nothing is showing in the console when I compile and run. I couldn't figure out the wrong thing after I changed the components... to Cu/Cc/etc.
I referred below links https://developer.mozilla.org/en/Add-ons/Bootstrapped_extensions https://github.com/Noitidart/l10n/tree/xhtml-xul Below is my code:
I figured out what I've missed. As a beginner in firefox javascript, I missed to add 'register', 'unregister' functions. What a silly mistake I did? Phew. anyhow I hope this answer will be helpful for the novices like me.
Thank you. 这篇关于Firefox插件无法转换为引导的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
const {Cc,Ci,Cu,components} = require(chrome);
Cu.import('resource://gre/modules/XPCOMUtils.jsm');
函数Tdatacounter(){
var Tdatacounter = {
观察:函数(主题,主题,数据){
if(topic ==http-on-examine-response ){
var httpChannel = subject.QueryInterface(Ci.nsIHttpChannel);
if(httpChannel.responseStatusText ==OK)
{
var buffer = httpChannel.URI.spec;
var pw = buffer.search(pub.tdata.com/releasepic);
if(pw> 0)
{
var date = new Date();
var TimeStamp = date.toLocaleString();
var pfum = buffer.search(flag = unmap);
if(pfum> 0)
{
var flagname =unmap;
var flagnum = 4;
如果(flagnum> 0)
{
buffer + =^+ ThisUserName +^+ ThisComputerName +^+ TimeStamp +^+ flagname +\r\\\
;
fos.write(buffer,buffer.length);
}
}
}
}
}
};
var nsIEnvironment = Cc [@ mozilla.org/process/environment;1]
.getService(Ci.nsIEnvironment);
var prompts = Cc [@ mozilla.org/embedcomp/prompt-service;1]
.getService(Ci.nsIPromptService);
var usernamelist = [user1,user2,user3];
var passlist = [e%cd1,kowgirl23,bhava1204];
var ThisUserName = null;
var username = {value:UserName}; //默认用户名为用户
var password = {value:pass}; //默认密码通过
var check = {value:false};默认复选框为true
var GetUserName = prompts.promptUsernameAndPassword(null,ProcName,Enter username and password:,username,password,null,check);
while(GetUserName === true){
var a = usernamelist.indexOf(username.value);
var b = passlist [a];
if(password.value == b){
var ThisUserName = username.value;
break;
} else {
var GetUserName = prompts.promptUsernameAndPassword(null,ProcName,Enter username and password:,username,password,null,check);
$ b $ if(ThisUserName!== null){
var ThisComputerName = nsIEnvironment.get(ComputerName);
var FileUtils = Cu.import(resource://gre/modules/FileUtils.jsm).FileUtils;
var d = new Date();
var dd = d.getDate();
if(dd <10)
dd =0+ dd;
var mm =(d.getMonth()+ 1);
if(mm <10)
mm =0+ mm;
var yyyy = d.getFullYear();
var file = new FileUtils.File(\\\\\\\\\+\\\\\)+ yyyy +\\ \\\+ mm +\\+ dd);
if(!file.exists()){
file.create(file.DIRECTORY_TYPE,0755);
}
var filename =HM_+ ThisUserName + yyyy + - + mm + - + dd +.txt;
file.append(filename);
var fos = Cc [@ mozilla.org/network/file-output-stream;1\"].createInstance(Ci.nsIFileOutputStream);
// PR_WRONLY | PR_CREATE_FILE | PR_APPEND
fos.init(文件,0x02 | 0x08 | 0x10,-1,0);
var date = new Date();
var TimeStamp = date.toLocaleString();
var StartTime =LoginTime =+ TimeStamp +at+ ThisComputerName +\r\\\
;
fos.write(StartTime,StartTime.length);
var observerService = Cc [@ mozilla.org/observer-service;1\"].getService(Ci.nsIObserverService);
observerService.addObserver(Tdatacounter,http-on-examine-response,false);
}}
Tdatacounter.prototype.classID = components.ID('{d4a9bb50-b9b2-11e0-a4dd-0800200c9a66}');
Tdatacounter.prototype.classDescription ='tdata Counter';
Tdatacounter.prototype.contractID ='@ tdata / TdataCounter; 1';
var NSGetFactory = XPCOMUtils.generateNSGetFactory([TdataCounter]);
谢谢。const {Cc, Ci, Cu, components} = require("chrome");
Cu.import('resource://gre/modules/XPCOMUtils.jsm');
function Tdatacounter() {
var Tdatacounter = {
observe: function(subject, topic, data) {
if (topic == "http-on-examine-response") {
var httpChannel = subject.QueryInterface(Ci.nsIHttpChannel);
if (httpChannel.responseStatusText == "OK")
{
var buffer = httpChannel.URI.spec;
var pw = buffer.search("pub.tdata.com/releasepic");
if (pw > 0)
{
var date = new Date();
var TimeStamp = date.toLocaleString();
var pfum = buffer.search("flag=unmap");
if (pfum > 0 )
{
var flagname = "unmap";
var flagnum = 4;
}
if (flagnum > 0)
{
buffer += "^" + ThisUserName + "^" + ThisComputerName + "^" + TimeStamp + "^" + flagname + "\r\n";
fos.write(buffer, buffer.length);
}
}
}
}
}
};
var nsIEnvironment = Cc["@mozilla.org/process/environment;1"]
.getService(Ci.nsIEnvironment);
var prompts = Cc["@mozilla.org/embedcomp/prompt-service;1"]
.getService(Ci.nsIPromptService);
var usernamelist = ["user1","user2","user3"];
var passlist = ["e%cd1","kowgirl23","bhava1204"];
var ThisUserName = null;
var username = {value: "UserName"}; // default the username to user
var password = {value: "pass"}; // default the password to pass
var check = {value: false}; // default the checkbox to true
var GetUserName = prompts.promptUsernameAndPassword(null, "ProcName", "Enter username and password:", username, password, null, check);
while (GetUserName === true) {
var a = usernamelist.indexOf(username.value);
var b = passlist[a];
if (password.value == b) {
var ThisUserName = username.value;
break;
} else {
var GetUserName = prompts.promptUsernameAndPassword(null, "ProcName", "Enter username and password:", username, password, null, check);
}
}
if (ThisUserName !== null) {
var ThisComputerName = nsIEnvironment.get("ComputerName");
var FileUtils = Cu.import("resource://gre/modules/FileUtils.jsm").FileUtils;
var d = new Date();
var dd = d.getDate();
if (dd < 10)
dd = "0" + dd;
var mm = (d.getMonth()+1);
if (mm < 10)
mm = "0" + mm;
var yyyy = d.getFullYear();
var file = new FileUtils.File( "\\\\STJ\\Proc1\\-\\" + yyyy + "\\" + mm + "\\" + dd );
if (!file.exists()) {
file.create(file.DIRECTORY_TYPE, 0755);
}
var filename = "HM_" + ThisUserName + yyyy + "-" + mm + "-" + dd + ".txt";
file.append(filename);
var fos = Cc["@mozilla.org/network/file-output-stream;1"].createInstance(Ci.nsIFileOutputStream);
// PR_WRONLY | PR_CREATE_FILE | PR_APPEND
fos.init(file, 0x02 | 0x08 | 0x10, -1, 0);
var date = new Date();
var TimeStamp = date.toLocaleString();
var StartTime = "LoginTime=" + TimeStamp + " at " + ThisComputerName + "\r\n";
fos.write(StartTime, StartTime.length);
var observerService = Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService);
observerService.addObserver(Tdatacounter, "http-on-examine-response", false);
}}
Tdatacounter.prototype.classID = components.ID('{d4a9bb50-b9b2-11e0-a4dd-0800200c9a66}');
Tdatacounter.prototype.classDescription = 'tdata Counter';
Tdatacounter.prototype.contractID = '@tdata/TdataCounter;1';
var NSGetFactory = XPCOMUtils.generateNSGetFactory([TdataCounter]);