0

下面我有预期工作的xul 插件的代码。

即在浏览器启动时显示用户名和密码输入,每当主题为 http-on-examine-response 时,它​​都会验证并写入指定文件。

但是当我尝试将其转换为引导扩展时,它甚至不会在浏览器启动时显示用户名密码输入,并且当我编译和运行时控制台中也没有显示任何内容。

将组件更改为 Cu/Cc/etc 后,我无法弄清楚错误的事情。我提到了下面的链接

https://developer.mozilla.org/en/Add-ons/Bootstrapped_extensions

MDN 文档中关于找出 XUL 元素的段落是什么意思:“如何将覆盖扩展转换为无重启”

https://github.com/Noitidart/l10n/tree/xhtml-xul

下面是我的代码:

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]);
4

1 回答 1

0

我发现我错过了什么。作为 Firefox javascript 的初学者,我错过了添加“注册”、“取消注册”功能。我犯了什么愚蠢的错误?呸。无论如何,我希望这个答案对像我这样的新手有所帮助。谢谢你。

于 2015-09-30T10:41:05.380 回答