0

I am trying to make it so my script runs once per day at most. Here is what I currently have:

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.");
}

But it does not seem to be working. Would it be better to store how many days have passed since epoch as done Here?

Community
  • 1
  • 1
Bijan
  • 7,737
  • 18
  • 89
  • 149

1 Answers1

0

Looks like I was right. In 24hours, the script will run again because the counter has changed.

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.");
}
Bijan
  • 7,737
  • 18
  • 89
  • 149