I am making an extension for me and people at my school which, to not get into too much detail, attempts to save your courses and tells you your upcoming schedule for months in advance. This is all possible because my school runs on a "Day" system. This means that on 'Day One' you might have math, science, english and gym, and on 'Day Two' you might have history, spanish, etc... you get the point. Anyway, for this extension to run, I need to keep track of the given day that I am on. This is only possible if someone opens the extension, which runs the script to check if a day has passed, and if so, will increment the variable. However, my problem is that some people might not open the extension for many days in a row, causing my program to lose what day it is, making it useless. So I need a way for my program to increment the days in the background without having to open the extension. Another way for me to do this is to somehow figure out how many days the user has been gone, and do some math to find out what day it is supposed to be.
If anyone can lend me some help that would be greatly appreciated. I have linked some of my code below.
This happens when the user first logs into my program, saving the day of the week they are on.
var today = new Date()
localStorage.setItem('day-of-week', today.getDay())
This 'checker' then gets run every time the extension is loaded, and if it notices any difference between the locally stored day of the week and the one right now, it will increment the school 'Day' and then store the new day of the week. (My school's day system only goes up to 4 so it wraps around back to one once it reaches 4)
function checkDate(prevDate) {
var today = new Date()
if (today.getDay() != prevDate) {
day = parseInt(day)
if (day == 4) {
day = 1
} else {
day += 1
}
localStorage.setItem('day', day)
localStorage.setItem('day-of-week', today.getDay())
}}