Greasemonkey每天运行一次脚本

时间:2015-09-02 21:14:56

标签: javascript greasemonkey tampermonkey

我正在尝试这样做,所以我的脚本最多每天运行一次。这是我现在拥有的:

var q = new Date();
var m = q.getMonth();
var d = q.getDate();
var y = q.getFullYear();

var currdate = new Date(y,m,d);
if (GM_getValue("date", "") < currdate) {
    GM_setValue("date", currdate);
    console.log("Set new date. Continuing to run script");
}
else {
    console.log("No need to fetch data. Quitting");
    throw new Error("Halted Script.");
}

但它似乎没有起作用。存储自纪元以来已经过了多少天更好Here

1 个答案:

答案 0 :(得分:0)

看起来我是对的。在24小时内,脚本将再次运行,因为计数器已更改。

var now = new Date();
var currdate = Math.floor(now/8.64e7);
if (GM_getValue("date2", "") < currdate) {
    GM_setValue("date2", currdate);
    console.log("Continuing to run script");
}
else {
    console.log("No need to fetch data. Quitting");
    throw new Error("Halted Script.");
}