active-timeout.js
Version:
JavaScript library that lets you measure time the user has spent viewing your page. Inactive time will not be counted.
1 lines • 938 B
JavaScript
window.ActiveTimeout=function(){function n(){return o&&document[o.hidden]}function e(n){"undefined"!=typeof requestAnimationFrame?requestAnimationFrame(n):setTimeout(n,1e3/60)}function i(i){var t=0,u=function(){t+=1};d.push(u),function o(c){var r=!1,f=Date.now();t>0?(t-=1,r=!0):r=!!n()||(!c||i(f-c)),!0===r?e(function(){o(f)}):d.splice(d.indexOf(u),1)}()}function t(n){var e=0;i(function(i){return e+=i,n(e,i)})}function u(n,e,i){"number"==typeof e&&(i=e,e=null),t(function(t,u){return"function"==typeof e&&e(i-t,u),!(t>=i)||(n(),!1)})}var o=function(){var n,e;if("hidden"in document)n="hidden",e="visibilitychange";else if("msHidden"in document)n="msHidden",e="msvisibilitychange";else{if(!("webkitHidden"in document))return null;n="webkitHidden",e="webkitvisibilitychange"}return{hidden:n,event:e}}(),d=[];return o&&document.addEventListener(o.event,function(){if(!n())for(var e=d.length-1;e>=0;e--)d[e]()}),{set:u,count:t,pulse:i}}();