I am trying to write a Firefox add-on for personal use and to learn a bit more about both JavaScript and the Firefox Add-on SDK. The add-on should open a vivo.sx
URL and then automatically start the player, but I have 2 issues. I hope you guys can help me.
The relevant add-on-code:
function vivoplay()
{
pageMod.PageMod({
include: "https://vivo.sx/*",
contentScriptFile: "./vivoplay.js",
onAttach: play
});
function play(worker) //Fires 2 Times
{
console.log("Timeout");
tmr.setTimeout(sendplay, 14000);
function sendplay()
{
var a = 0;
worker.port.emit("start", a);
}
}
}
content-script
self.port.on("start", function(a) {
console.log("Load");
flowplayer().load(); //ReferenceError: flowplayer is not defined
console.log("Loaded");
});
The first problem is that the function play
fires 2 times, but should only run once. It's probably the onAttach
that does not work correctly. What do you think about that?
The more important problem is the ReferenceError
. I have a Greasemonkey script where I use the function flowplayer().load();
. I thought the content script is running like a Greasemonkey script. So, I should be able to use this function. Is that correct? How can I fix this?
my greasemonkey script
// ==UserScript==
// @name 3. Vivo
// @namespace Autoplay
// @include https://vivo.sx/*
// @version 1
// @grant none
// ==/UserScript==
window.setTimeout(Play, 2000);
function Play()
{
flowplayer().load();
console.log("Loaded");
flowplayer().fullscreen();
console.log("Fullscreen started");
}
I am quite new to this so please be patience with me :)
If you need more information, please leave a comment.
flowplayer()
? – Threescoreflowplayer()
already exists in the page in which you are wanting your content script loaded and you are wanting to call the methodflowplayer().load()
which exists in the page script for the web page you are viewing. Is that accurate? – Threescore