[javascript] How to detect idle time in JavaScript elegantly?