npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

idle-detector-x

v1.0.0

Published

一个轻量级的用户空闲状态检测库,支持跨标签页同步。

Readme

idle-detector-x

一个轻量级的用户空闲状态检测库,支持跨标签页同步。

安装

npm install idle-detector-x

功能特性

  • 🔍 自动检测用户空闲状态
  • 🔄 支持跨标签页同步(基于 localStorage)
  • ⚙️ 可配置超时时间
  • 📦 支持 CommonJS 和 ES Module 两种模块格式
  • 🪶 轻量级,无依赖

使用方法

基础用法

import IdleDetector from 'idle-detector-x'

const detector = new IdleDetector({
  timeout: 30 * 60 * 1000, // 空闲超时时间,默认 30 分钟
  crossTab: true,          // 是否跨标签页同步,默认 true
  onIdle: () => {
    console.log('用户已空闲')
  },
  onActive: () => {
    console.log('用户已激活')
  }
})

detector.start()  // 开始检测
detector.stop()   // 停止检测

配置选项

| 参数 | 类型 | 默认值 | 说明 | |------|------|--------|------| | timeout | number | 1800000 (30分钟) | 空闲超时时间(毫秒) | | crossTab | boolean | true | 是否启用跨标签页同步 | | onIdle | function | () => {} | 用户进入空闲状态的回调函数 | | onActive | function | () => {} | 用户从空闲状态恢复活跃的回调函数 |

API

start()

开始检测用户空闲状态。

stop()

停止检测并清除定时器。

reset()

重置空闲计时器,通常在用户活动时自动调用。

监听的用户活动事件

库会自动监听以下用户活动事件:

  • mousemove - 鼠标移动
  • mousedown - 鼠标按下
  • keydown - 键盘按下
  • scroll - 页面滚动
  • touchstart - 触摸开始

跨标签页同步

crossTab 选项启用时,库会使用 localStorage 在同一域名的不同标签页之间同步用户活动状态。当任意一个标签页检测到用户活动时,其他标签页也会重置空闲计时器。

构建产物

项目构建后会生成以下文件:

  • dist/index.cjs.js - CommonJS 格式
  • dist/index.esm.js - ES Module 格式

许可证

MIT