function onSomeAction() {
var delay = 1000*60*5;
var currTime = new Date();
var nextTime = new Date(currTime + delay);
localStorage.nextAction = nextTime;
setTimeout(callSomeOtherAction, delay);
}
window.onload = function() {
var currTime = new Date();
if (localStorage.nextAction) {
var delay = localStorage.nextAction - currTime;
if (delay >= 0) {
setTimeout(callSomeOtherAction, delay);
} else {
delete localStorage.nextAction;
}
}
}
function callSomeOtherAction() {
delete localStorage.nextAction;
someOtherAction();
}
function someAction() { console.log(1); onSomeAction(); }
function someOtherAction() { console.log(2); }