Skip to content

Instantly share code, notes, and snippets.

@tranchausky
Created April 1, 2024 01:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tranchausky/06dce21b712bb7bffea2121c15fb89a9 to your computer and use it in GitHub Desktop.
Save tranchausky/06dce21b712bb7bffea2121c15fb89a9 to your computer and use it in GitHub Desktop.
jqueyr auto call function after 5 minus if no event mouse or keyboard in page
let idleTime = 0;
// Increment idle time every second
setInterval(timerIncrement, 1000);
// Reset idle time on mouse or keyboard event
$(document).on('mousemove keydown', function() {
idleTime = 0;
});
function timerIncrement() {
idleTime++;
if (idleTime > 300) { // 300 seconds = 5 minutes
// Call your function here
console.log('No activity for 5 minutes');
idleTime = 0; // Reset idle time
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment