Last active
April 10, 2017 14:34
-
-
Save thybzi/b8b38328922e003c77a0dca2d9613555 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
window.lastActivityTime = 0; | |
window.refreshInterval = 10000; | |
window.idleInterval = 60000; | |
resetRefreshTimer(); | |
document.body.addEventListener('mousemove', resetRefreshTimer); | |
document.body.addEventListener('keypress', resetRefreshTimer); | |
setTimeout(refresh, window.refreshInterval); | |
if (document.addEventListener) { | |
if ('onwheel' in document) { | |
// IE 9+, Firefox 17+, Chrome 31+ | |
document.addEventListener('wheel', onWheel); | |
} else if ('onmousewheel' in document) { | |
// old event name | |
document.addEventListener('mousewheel', onWheel); | |
} else { | |
// Firefox 16- | |
document.addEventListener('MozMousePixelScroll', onWheel); | |
} | |
} else { | |
// IE 8- | |
document.attachEvent('onmousewheel', onWheel); | |
} | |
function onWheel(e) { | |
var delta, scrollBy; | |
e = e || window.event; | |
if (e.altKey) { | |
// wheelDelta doesn't contain the amount of scrolled pixels | |
delta = e.deltaY || e.detail || e.wheelDelta; | |
scrollBy = (delta > 0) ? 100 : -100; | |
window.scrollBy(scrollBy, 0); | |
e.preventDefault ? e.preventDefault() : (e.returnValue = false); | |
} | |
} | |
})(); | |
function resetRefreshTimer() { | |
window.lastActivityTime = new Date().getTime(); | |
} | |
function refresh() { | |
if ((new Date().getTime() - window.lastActivityTime) >= window.idleInterval) { | |
window.location.reload(true); | |
} else { | |
setTimeout(refresh, window.refreshInterval); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment