NoSleep.js

在任何 Android 或 iOS Web 浏览器中阻止显示器睡眠并启用唤醒锁定。(Prevent display sleep and enable wake lock in any Android or iOS web browser.)

Github stars Tracking Chart

NoSleep.js

在所有 Android 和 iOS Web 浏览器中阻止显示器睡眠并启用唤醒锁定。

在任何 Android 或 iOS 网络浏览器中查看实时演示

安装

该库可在 Bower 上作为 nosleep 使用。

bower install nosleep

该软件包以 nosleep.js 的形式发布到 npm,可以安装:

npm install nosleep.js

或者,您可以手动将 NoSleep.js 添加到项目(或 缩小版)。

从源代码构建

安装所有开发依赖项:

npm install

要构建此库,请运行:

npm run build

现在,/dist 目录中将提供 NoSleep.jsNoSleep.min.js 的新版本。

用法

创建一个新的 NoSleep 对象,然后在需要时启用或禁用它。

要创建新的 NoSleep 对象:

var noSleep = new NoSleep();

要启用唤醒锁定:

注意:此函数调用必须封装在用户输入事件处理程序中,例如鼠标或触摸处理程序

// Enable wake lock.
// (must be wrapped in a user input event handler e.g. a mouse or touch handler)
document.addEventListener('click', function enableNoSleep() {
  document.removeEventListener('click', enableNoSleep, false);
  noSleep.enable();
}, false);

禁用唤醒锁定

// Disable wake lock at some point in the future.
// (does not need to be wrapped in any user input event handler)
noSleep.disable();

有关更多信息,请参见 example/index.html (和 在线演示)。

反馈

如果您发现任何错误或问题,请在 NoSleep.js 问题跟踪器上报告。

如果您想为此项目做出贡献,请考虑 派生该存储库,进行更改,然后创建一个新的 Pull Request 到主代码库。

许可

MIT。 版权所有(c)Rich Tibbett

请参阅 LICENSE 文件。

Main metrics

Overview
Name With Ownerrichtr/NoSleep.js
Primary LanguageJavaScript
Program languageHTML (Language Count: 2)
PlatformAndroid, iOS
License:MIT License
所有者活动
Created At2015-04-21 08:10:40
Pushed At2024-07-30 09:03:21
Last Commit At2020-12-16 01:44:59
Release Count13
Last Release Namev0.12.0 (Posted on )
First Release Namev0.1.0 (Posted on 2015-04-22 16:38:44)
用户参与
Stargazers Count2.3k
Watchers Count38
Fork Count379
Commits Count92
Has Issues Enabled
Issues Count105
Issue Open Count49
Pull Requests Count18
Pull Requests Open Count15
Pull Requests Close Count26
项目设置
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private

NoSleep.js

Prevent display sleep and enable wake lock in all Android and iOS web browsers.

Check out the live demo in any Android or iOS web browser.

Installation

This library is available on Bower as nosleep.

bower install nosleep

This package is published to npm as nosleep.js and can be installed with:

npm install nosleep.js

Alternatively, you can manually add NoSleep.js to your project (or the minified version).

Build from source

Install all development dependencies with:

npm install

To build this library run:

npm run build

A new build of NoSleep.js and NoSleep.min.js will now be available in the /dist directory.

Usage

Create a new NoSleep object and then enable or disable it when needed.

To create a new NoSleep object:

var noSleep = new NoSleep();

To enable wake lock:

NOTE: This function call must be wrapped in a user input event handler e.g. a mouse or touch handler

// Enable wake lock.
// (must be wrapped in a user input event handler e.g. a mouse or touch handler)
document.addEventListener('click', function enableNoSleep() {
  document.removeEventListener('click', enableNoSleep, false);
  noSleep.enable();
}, false);

To disable wake lock:

// Disable wake lock at some point in the future.
// (does not need to be wrapped in any user input event handler)
noSleep.disable();

See example/index.html (and the live demo) for more information.

Feedback

If you find any bugs or issues please report them on the NoSleep.js Issue Tracker.

If you would like to contribute to this project please consider forking this repo, making your changes and then creating a new Pull Request back to the main code repository.

License

MIT. Copyright (c) Rich Tibbett.

See the LICENSE file.