I’m looking for a clean way to call/execute/redefine javascript code from a webpage, within firefox, through a firefox extension. My temporary solution is to use the scratchpad (Shift-F4, Ctrl-A, Ctrl-V, Ctrl-R), it works fine but is a sad work-around. Greasemonkey would be my last resort, very very last.
Here’ the code so far:
main.js:
exports.main = function() {
var data = require("self").data;
var pageMod = require("page-mod");
pageMod.PageMod({
include: "*.google.com",
contentScriptFile: data.url("my-script.js")
});
};
my-script.js
$('#mydiv').html('yo')
alreadyHere.sayHello=function (){alert('Bonjour');}
This code halts on line #1 of my-script.js saying that $ is not defined.
Problem of namespace/scope.
How can I work within the namespace/scope of the webpage, from my extension, like I do with the scratchpad?
Edit: There should be a link between window.content of the firefox main window and alreadyHere.sayHello from the webpage, no?
window.content.(things).alreadyHere.sayHello();
What am I missing here?
HELL YEAH.
Thanks Mridang Agarwalla here