[Solved] How to set 2 time intervals for the same function?


One possible approach is to keep track of the time when the last notification was displayed and always check if 5 minutes have passed since. E.g.:

/* Put these 2 lines at the very top of your script */
var interval = 5 * 60 * 1000;   // 5 minutes in milliseconds
var lastNotification = 0;

Then, inside the updateIcon() function, replace this line:

chrome.notifications.create(...);

with these lines:

var now = new Date().getTime();
if (now - lastNotification > interval) {
    lastNotification = now;
    chrome.notifications.create(...);
}

The above piece of code will make sure the notification is created only if 5 minutes have passed since the last time a notification was created. It will also update the lastNotification variable with the present time.

6

solved How to set 2 time intervals for the same function?