I'm learning firefox addon development using the new AddOn SDK. I'm creating a simple utility addon which autohides the comments on SPOJ Problems Page.
Now, to hide comments section, there's a option on problem page which calls a javascript function to do so. Currently I temporarily achieved the functionality by simulating a click on this option, but it uses unsafewindow which is not recommended.
Here's the main.js
var tabs = require("sdk/tabs");
var data = require("sdk/self").data;
var pageMod = require("sdk/page-mod");
tabs.on('ready', function(tab) {
var worker = tab.attach({
contentScriptFile : data.url("autoHide.js")
});
worker.port.emit('hideComments', tabs.activeTab.url);
});
And autoHide.js
self.port.on('hideComments', function(url) {
var elem = document.getElementById('comments_sh');
//toggleComments();
elem = elem.parentNode;
simulateClick(elem);
});
function simulateClick(a) {
var evt = document.createEvent("MouseEvents");
evt.initMouseEvent("click", true, true, unsafeWindow,
0, 0, 0, 0, 0, false, false, false, false, 0, null);
a.dispatchEvent(evt);
}
The function which I want to call is toggleComments().
So my question is How can I call a javascript function of WebPage through Addon Script or ContentScript ??