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

auto-update-page

v1.0.13

Published

自动更新页面插件,支持远程版本对比和动态加载

Readme

AutoUpdatePage

功能描述

AutoUpdatePage 是一个用于检测页面更新并自动刷新的工具。主要功能包括:

  • 通过 IndexedDB 存储页面内容哈希值。
  • 定时轮询检测页面内容是否更新。
  • 支持开发者自定义更新逻辑和回调。

使用方法

  1. 安装依赖

    npm install
  2. 引入模块

    import { AutoUpdatePage } from './AutoUpdatePage';
  3. 初始化并启动

    const updater = new AutoUpdatePage({
      onUpdateAvailable: (confirmed: boolean) => {
        if (confirmed) {
          console.log('页面已更新,即将刷新!');
        } else {
          console.log('用户取消更新,继续轮询。');
        }
      },
    });
       
    updater.start();
  4. 停止轮询

    updater.stop();
  5. 动态设置更新确认状态

    updater.setUpdateConfirmation(true); // 确认更新
    updater.setUpdateConfirmation(false); // 取消更新

使用场景示例

场景1:用户主动触发更新

const updater = new AutoUpdatePage({
  onUpdateAvailable: (confirmed) => {
    if (confirmed) {
      alert('页面已更新,即将刷新!');
      window.location.reload();
    } else {
      console.log('用户取消更新,继续轮询。');
    }
  }
});

// 用户点击确认按钮时调用
document.getElementById('confirm-update').addEventListener('click', () => {
  updater.setUpdateConfirmation(true);
});

场景2:自动更新逻辑

const updater = new AutoUpdatePage({
  onUpdateAvailable: (confirmed) => {
    if (confirmed) {
      window.location.reload();
    }
  }
});

// 检测到更新后自动确认
updater.setUpdateConfirmation(true);

注意事项

  • 确保运行环境支持 IndexedDBfetch API。
  • 轮询间隔默认为 10 分钟,可通过配置调整。
  • 测试时需模拟 window 对象和浏览器 API。