I want to create a HTML list that will shuffle itself once a week and anybody who accesses the website will view the same shuffled list. The shuffling JavaScript is identical to the highest upvoted question on the matter so I will refrain from posting that here.
The problem with this, is that the shuffled list is inconsistent across devices. I had attempted to set a timer to control when the script activates, as you can view here:
var ul = document.querySelector("ul"), // get the list
temp = ul.cloneNode(true); // clone the list
// shuffle the cloned list (better performance)
for (var i = temp.children.length + 1; i--; )
temp.appendChild(temp.children[Math.random() * i |0] );
var weekInMilliseconds = 60*1000; // == 604800000 ms
var lastInfo = parseInt(localStorage.getItem('info'), 10); // either NaN or timestamp
if(isNaN(lastInfo))
lastInfo = 0; // 1970, mind you
// if last info showed earlier than one week ago:
if(lastInfo < (Date.now() - weekInMilliseconds)){
localStorage.setItem('info',Date.now()); // set info date now
ul.parentNode.replaceChild(temp, ul); // copy shuffled back to 'ul' // display your information
}
My problems with this were that, again the list wasn't consistent, and, though it did successfully stop the script from activating until sufficient time had passed, since there was no actual alteration to the HTML, if there was a refresh before the interval the page would just load with the default, unshuffled, list order, as written in the original HTML.
I'm quite new to web design so I'm unsure what to try next and and my browsing of W3 has been unfruitful. Any help would be appreciated, thanks!