0

I am trying to add a folderpane to the main view (something like http://extensions.sanjer.nl/xpi/tb/contactssidebar-1.7pre.xpi). This seems to give a nice tool to start with but I want to add an event listener so that every time I click an email it will allow me to do some "extra work" to retrieve some data from a server (i.e. a crm system based on the email). I want to be able to use something like the contactssidebar as a template to learn from or similar but my challenge is that I can try to get this working by adding the following to the file contactsSideBar.js file at the top, to learn from and test it out

  window.addEventListener("load", function load(event) {
          window.removeEventListener("load", load, false);
          myExtension.init();
  }, false);

  var myExtension = {
    init: function() {
          var appcontent = document.getElementById("appcontent"); // browser app content
          if (appcontent) {
                  appcontent.addEventListener("OMContentLoaded", myExtension.onPageLoad, true);
          }
          var messagepane = document.getElementById("messagepane"); // tunderbird message pane
          if(messagepane) {
                  messagepane.addEventListener("load", function(event) { myExtension.onPageLoad(event); }, true);
          }
    },
    onPageLoad: function(aEvent) {

        var win = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService(Components.interfaces.nsIWindowMediator).getMostRecentWindow("mail:3pane");
        var currentMsg = win.gFolderDisplay.selectedMessages[0];
        var currentEmail = currentMsg.mime2DecodedAuthor.replace(/^.*</, "").replace(/>$/, "");

        document.getElementById("searchInputElem").value = currentEmail;
        aEvent.originalTarget.defaultView.addEventListener("unload", function(event) { myExtension.onPageUnload(event); }, true);
    },

    onPageUnload: function(aEvent) {
      // No action necessary yet
    }
  };

However I can not seem to be able to locate the element in the DOM for

  document.getElementById("searchInputElem")  

it is null

I think I have to access some other pane or window but not sure. This element is found in the chrome\content\contactssidebar\search.xml Jar file that I have used (contactssidebar). I didnt write it but just trying to be able to update an element

Does someone know how to do this?

user1320651
  • 808
  • 2
  • 15
  • 42
  • You have to be searching in the correct DOM. Look at the extension that you are modifying and see how it references that element. – Makyen Feb 24 '16 at 06:52
  • BTW: If you had linked to an add-on that was either hosted on Mozilla add-ons, or on Github, I might have gone through the effort of installing it and taking a look. As it is, I would have to first check through the entire add-on to see if there was anything it was doing that I don't want to have happen on my machine (i.e. nothing malicious). In other words, the amount of work to begin helping you is too high. – Makyen Feb 24 '16 at 07:00

0 Answers0