One way to generate an index is by using the current time, which starts counting from 1970 instead of the random time when the user visited the site.
At this moment, the current timestamp reads 1493684749486.
var d = new Date();
// +d === 1493684749486
To convert the current timestamp into an array index, first calculate the number of milliseconds in a week (1000*60*60*24*7), and then determine how many weeks have passed since 1970.
var index = Math.floor(+d / (1000*60*60*24*7));
// 2469 weeks have passed since 1970
// output `mind[index]` now.
For the purpose of this explanation, let's assume you want to update the item on Friday at 9 am. The nearest upcoming Friday at 9 am will be at timestamp 1494000000000.
d.setMilliseconds(0);
d.setSeconds(0);
d.setMinutes(0);
d.setHours(9);
d.setDate(d.getDate() + (7 + 5 - d.getDay()) % 7); // Find out how many days until Friday from Monday and add it to the current date.
This results in being 315250514 milliseconds away. You can use setTimeout with this delay to trigger the next update.
Once the item changes, set a new timeout for the following update. Using setTimeout for this purpose is recommended over setInterval.
function displayNextItem() {
var d = new Date();
var timestamp = +d;
var index = Math.floor(timestamp / (1000*60*60*24*7));
wfmind.innerHTML = mind[index % mind.length];
d.setMilliseconds(0);
d.setSeconds(0);
d.setMinutes(0);
d.setHours(9);
d.setDate(d.getDate() + (7 + 5 - d.getDay()) % 7); // Find out how many days until Friday from Monday and add it to the current date.
setTimeout(displayNextItem, +d - timestamp);
}
displayNextItem();