NoSleep.js

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

Github星跟踪图

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 文件。

主要指标

概览
名称与所有者richtr/NoSleep.js
主编程语言JavaScript
编程语言HTML (语言数: 2)
平台Android, iOS
许可证MIT License
所有者活动
创建于2015-04-21 08:10:40
推送于2024-07-30 09:03:21
最后一次提交2020-12-16 01:44:59
发布数13
最新版本名称v0.12.0 (发布于 )
第一版名称v0.1.0 (发布于 2015-04-22 16:38:44)
用户参与
星数2.3k
关注者数38
派生数379
提交数92
已启用问题?
问题数105
打开的问题数49
拉请求数18
打开的拉请求数15
关闭的拉请求数26
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?

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.