Detect when a user is idle. No dependencies, small footprint (2.35kb). Inspired by Idle.js
Install with npm/yarn:
npm install inactivejs
yarn add inactivejsImport on your js file:
const InactiveJS = require('inactivejs');
import InactiveJS from 'inactivejs';Instantiate:
const onAway = () => {
console.log('user is away');
};
const onBack = () => {
console.log('user is back');
};
const inactiveInstance = new InactiveJS({
timeout: 5000,
onAway: onAway,
onBack: onBack,
});Options:
- timeout (ms): How much time should wait
- onAway: callback to be executed when the user is away
- onBack: callback to be executed when the user is back
MIT.