Firefox插件无法转换为bootstrap

时间:2015-09-25 14:00:36

标签: javascript firefox firefox-addon-restartless

下面我有 xul addon 的代码,预计可以使用。

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

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

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

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

What does paragraph about figuring out XUL elements mean in MDN document: "How to convert an overlay extension to restartless"

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

1 个答案:

答案 0 :(得分:0)

我弄清楚了我错过了什么。作为firefox javascript的初学者,我错过了添加&#39;注册&#39;&#39;取消注册&#39;功能。我做了多么愚蠢的错误?唷。无论如何,我希望这个答案能对像我这样的新手有所帮助。 谢谢。