https://github.com/fireworkweb/inactivejs
Detect when a user is idle. No dependencies, small footprint (5.47kb).
https://github.com/fireworkweb/inactivejs
idle inactive javascript timer user
Last synced: about 1 year ago
JSON representation
Detect when a user is idle. No dependencies, small footprint (5.47kb).
- Host: GitHub
- URL: https://github.com/fireworkweb/inactivejs
- Owner: fireworkweb
- License: mit
- Created: 2018-03-28T16:54:43.000Z (over 8 years ago)
- Default Branch: develop
- Last Pushed: 2022-12-08T18:51:20.000Z (over 3 years ago)
- Last Synced: 2025-05-26T17:57:23.902Z (about 1 year ago)
- Topics: idle, inactive, javascript, timer, user
- Language: JavaScript
- Homepage:
- Size: 1.18 MB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 18
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# inactivejs
[](https://travis-ci.org/fireworkweb/inactivejs)
Detect when a user is idle or when he change tabs/apps. Small footprint package (5.47kb). Inspired by [Idle.js](https://github.com/shawnmclean/Idle.js)
## Usage
Install with npm/yarn:
```sh
npm install inactivejs
yarn add inactivejs
```
Import on your js file:
```js
const InactiveJS = require('inactivejs');
import InactiveJS from 'inactivejs';
```
Instantiate:
```js
const onAway = () => {
console.log('user is away');
};
const onBack = () => {
console.log('user is back');
};
const inactiveInstance = new InactiveJS({
timeout: 5000,
onAway: onAway,
onBack: onBack,
});
```
Config options:
- **timeout** (ms): how much time should wait
- **onAway** (callback): callback to be executed when the user is away
- **onBack** (callback): callback to be executed when the user is back
- **onVisible** (callback): callback to be executed when the tab is visible
- **onHidden** (callback): callback to be executed when the tab is hidden
- **events** (array): events to listen for
- **autoStart** (boolean): if start timer automatically
- **throttle** (ms): ms to throttle the event listeners, undefined/false to disable it
Available methods:
- **start()**: if you configured autoStart to false, this method will start the timer
- **stop()**: if needed, this will stop the timer
## License
MIT.