-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimers.min.js
1 lines (1 loc) · 1.57 KB
/
timers.min.js
1
var Timers=function(){function e(){return(new Date).getTime()-this.start}function t(e){let t=0;arr.forEach(i=>{i.id!==e?t++:arr.splice(t,1)})}function i(t,i,r){if(r.length<=1||0===r[1])return;const n=e();arr.push({type:i,id:t.id,delay:r[1],function:r[0].name?r[0].name:r[0].toString(),start:n,stop:n+r[1],remain:"",recycle:"·/·"})}return this._originalSetTimeout=window.setTimeout,this._originalClearTimeout=window.clearTimeout,this._originalSetInterval=window.setInterval,this._originalClearInterval=window.clearInterval,this.arr=[],this.start=(new Date).getTime(),window.clearTimeout=function(){void 0!==arguments[0]?(t(arguments[0]),_originalClearTimeout(id)):console.log("%cTimers error: clearTimeout ID is undefined.","color: red")},window.setTimeout=function(){let e={id:_originalSetTimeout.apply(null,arguments)};return i(e,"timeout",arguments),e},window.clearInterval=function(){void 0!==arguments[0]?(t(arguments[0]),_originalClearInterval(arguments[0])):console.log("%cTimers error: clearInterval ID is undefined.","color: red")},window.setInterval=function(){let e={id:_originalSetInterval.apply(null,arguments)};return i(e,"interval",arguments),e},{listInterval:function(e){return setInterval(()=>{Timers.list()},e)},list:function(){const i=e();let r;console.log("timers.js List | Start: 0 | Now: "+i),arr.forEach(e=>{r=Math.abs(i-e.stop),"timeout"===e.type?i<=e.stop?e.remain="🕓 "+Math.abs(r):i>e.stop+15e3?t(e.id):e.remain="🔴":(e.remain="🕓 "+r%e.delay,e.recycle="♻️ "+Math.ceil(r/e.delay))}),console.table(arr,["id","type","delay","function","start","stop","remain","recycle"])}}}();