http-on-examine-response上的FireFox Addon getElementById没有返回任何值

时间:2015-04-09 14:33:16

标签: javascript firefox-addon getelementbyid xpcom content-script

我正在尝试从http-on-examine-response上的活动页面中的元素获取值。我的下面的脚本可以很好地作为一个没有行之间的插件

var tabs = require("sdk/tabs");

contentScript: contentScriptString

但是当我添加这些行时,它会访问文本文件,但不会写任何内容。我无法在控制台中看到任何错误消息,因为我不使用SDK,因为新的SDK使用了复杂的东西,我必须在此处了解更多信息。 (现在我只是编辑组件文件夹中的js文件并更新chrome.manifest和install.rdf,如果有的话,然后压缩它们然后将其重命名为xpi并在firefox中打开它并且效果很好)。我用Google搜索了如何使用sdk调试此脚本并尝试了许多标题为“getelementbyid firefox addon'没有运气即使你说哪个sdk应该使用它也会有所帮助(一个愚蠢的问题。但是无法帮助自己)。

Components.utils.import('resource://gre/modules/XPCOMUtils.jsm');
function GetCity() {
var GetCity = {
observe: function(subject, topic, data) {
  if (topic == "http-on-examine-response") {
    var httpChannel = subject.QueryInterface(Components.interfaces.nsIHttpChannel);
    if (httpChannel.responseStatusText == "OK")
    {
    var buffer =  httpChannel.URI.spec;
      var pw = buffer.search("mywebsite.com/release");
      if (pw > 0)
      {
      var date = new Date();
      var TimeStamp = date.toLocaleString();
      var pfum = buffer.search("flag=release1");
      if (pfum > 0 )
      {
      var flagname = "1";
      var flagnum = 4;
      }
      var pfuk = buffer.search("flag=release2");
      if (pfuk > 0 )
      {
      var flagname = "2";
      var flagnum = "1";
      }
      var pfup = buffer.search("flag=release3");
      if (pfup > 0 )
      {
      var flagname = "3";
      var flagnum = 2;
      }
      var pfap = buffer.search("flag=release4");
      if (pfap > 0 )
      {
      var flagname = "4";
      var flagnum = 3;
      }
      if (flagnum > 0)
      {
      var tabs = require("sdk/tabs");
      var contentScriptString = 'var cityname = document.getElementById("city").value ;'
      tabs.activeTab.attach({
      contentScript: contentScriptString
      });
      buffer += "^" + ThisUserName + "^" + ThisComputerName + "^" + TimeStamp + "^" + flagname + "\r\n";
      fos.write(buffer, buffer.length);
      }
      }
  }
}
}
};
var nsIEnvironment = Components.classes["@mozilla.org/process/environment;1"].getService(Components.interfaces.nsIEnvironment);
var ThisUserName = nsIEnvironment.get("UserName");
var ThisComputerName = nsIEnvironment.get("ComputerName");

var FileUtils = Components.utils.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( "T:\\-\\CityList\\" + 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 = Components.classes["@mozilla.org/network/file-output-stream;1"]
                  .createInstance(Components.interfaces.nsIFileOutputStream);
// PR_WRONLY | PR_CREATE_FILE | PR_APPEND
fos.init(file, 0x02 | 0x08 | 0x10, -1, 0);

var observerService = Components.classes["@mozilla.org/observer-service;1"]
                              .getService(Components.interfaces.nsIObserverService);
observerService.addObserver(HotelMappingCounter, "http-on-examine-response", false);
}

var NSGetFactory = XPCOMUtils.generateNSGetFactory([CityList]);

0 个答案:

没有答案