JSFiddle - React, Tailwind, and code Playground
HTML
Еще получат <span id="ress"></span> человек
JavaScript
$(function(){
var num = 9,
output = $('#ress'),
LS_allowed=('localStorage' in window),
restart=1/60/60*10;//Convert 1 hour to 10 seconds
if(LS_allowed){
var save_time=parseInt(localStorage.getItem('timer-time'))||0;
if(save_time+restart*60*60*10>=(new Date()).getTime())
num=localStorage.getItem('timer-num')||num;
};
output.text(num);
(function changeNum(){
setTimeout(function(){
if(num<=1)
return;
output.text(--num);
if(LS_allowed){
localStorage.setItem('timer-num',num);
localStorage.setItem('timer-time',(new Date()).getTime());
};
changeNum();
},1000+(9-num)*1000);
})();
});