1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
timer:null,
timeOut: 5 * 1000,
lastTime:new Date().getTime(),
currentTime:new Date().getTime(),
start: function(callback) { localStorage.setItem("lastTime", this.lastTime)
window.document.ontouchstart = function() { localStorage.setItem("lastTime",new Date().getTime()) }
this.timer = setInterval(() => { this.currentTime = new Date().getTime() this.lastTime = localStorage.getItem("lastTime"); if (this.currentTime - this.lastTime > this.timeOut) { callback() localStorage.setItem("lastTime", new Date().getTime()) } }, 1000) },
clear: function() { if (this.timer) { clearInterval(this.timer) } }
|