Generic Human has set me on the right track with a much needed link. First of all, you need to add the load
event. I will insert part of the code with my most primitive understanding:
window.addEventListener("load", function load(event) { window.removeEventListener("load", load, false); myExtension.init(); }, false);
When this overhead load script loads, run init
.
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); } },
In init
I add a listener that calls onPageLoad
every time a message is displayed. I actually do not use afaik appcontent
.
onPageLoad: function(aEvent) { var doc = aEvent.originalTarget; // doc is document that triggered "onload" event // we can now morph the loaded page // doc.location is a 'Location' object var newDat = mutateBody(doc.body.innerHTML); doc.body.innerHTML = newDat; aEvent.originalTarget.defaultView.addEventListener("unload", function(event) { myExtension.onPageUnload(event); }, true); }, onPageUnload: function(aEvent) { // No action necessary yet } };
doc.body.textContents
seemed like an obvious element, but in fact it did not support formatting (darn HTML) - using innerHTML
works much better for my needs.
source share