Is it possible to update it using an interval? I have tried:
var timers = require("timers");
var pageMod = require("page-mod");
var mystyle = ....;
function func1(){
pageMod.PageMod({
include: "*.org",
contentScript: mystyle
});
}
func1();
function func2(){
mysyle = http://......
}
timers.setInterval(func2,10000);
The problem is that it will start registering pageMod couple of times every interval. Let's say I have inside of mystyle: alert("hello world"); so I'll go to to some page, after 30 seconds it when I'll refresh that single page it will execute 3 times "hello world" inside of alert box. I want it to execute only once and updateing the mystle every 30 seoncds.
You can directly change the contentScript property if you save the page-mod
First create your page-mod and save the object in a variable, like mod below. Then on your interval you can alter the contentScript property like you see in the func2. Once you've altered the contentScript you'll need the page-mod to re-evaluate the page somehow, I used a page reload since it sounded like from your description that was already happening.
var mod = require("page-mod").PageMod({
include: ["*.org"],
contentScript: "alert('the first alert');"
});
function func2(){
// change the contentScript
mod.contentScript = "alert('the second alert');";
// cause the page-mod to re-evaluate
require("tabs").activeTab.reload();
}
tab = require("tabs").open("http://mozilla.org");
require("timers").setInterval(func2, 5 * 1000);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With