Показать сообщение отдельно
  #1 (permalink)  
Старый 05.04.2020, 13:14
Аспирант
Отправить личное сообщение для Pavel_16 Посмотреть профиль Найти все сообщения от Pavel_16
 
Регистрация: 01.04.2020
Сообщений: 46

Как подключить или просто кодам написать следующий таймер?
Есть таймер
function timer(elem, min, sec) {
  (--sec < 0) && (sec = min-- ? 59 : 0);
  min = Math.max(min, 0);
  elem.innerHTML = min + " : " + sec;
  if (sec || min)
    setTimeout(timer.bind(0, elem, min, sec), 1000);
  else {
    alert('Время вышло!');
    location.href = "/rekord.html";
  }
}

timer(document.getElementById('play_timer'), 3, 0);

//Время в игре

function tick() {
  var nowTime = new Date();
  console.log('прошло секунд: ' + (nowTime + timer) / 1000);


А вот нашел таймер который записывает данный в локал стореч(на основе стандартных JQuery )
var interval;
let minutes = 1;
let currentTime = localStorage.getItem('currentTime');
let targetTime = localStorage.getItem('targetTime');
if (targetTime == null && currentTime == null) {
     currentTime = new Date();
     targetTime = new Date(currentTime.getTime() + (minutes * 60000));
     localStorage.setItem('currentTime', currentTime);
     localStorage.setItem('targetTime', targetTime);
}
else{
     currentTime = new Date(currentTime);
     targetTime = new Date(targetTime);
}

if(!checkComplete()){
     interval = setInterval(checkComplete, 1000);
}

function checkComplete() {
     if (currentTime > targetTime) {
       clearInterval(interval);
       alert("Time is up");
     } else {
       currentTime = new Date();
       document.write(
        "\n <font color=\"white\"> Seconds Remaining:" + ((targetTime - currentTime) / 1000) + "</font>");
     }
}

document.onbeforeunload = function(){
     localStorage.setItem('currentTime', currentTime);
}

Подскажите, как переделать, так что бы он работал без подключения просто на JS.
Ответить с цитированием