Screensaver Blocker

https://www.google.com/ を開いている間、スクリーンセーバーを抑止する

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Screensaver Blocker
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description https://www.google.com/ を開いている間、スクリーンセーバーを抑止する
// @author       anonymous
// @match        https://www.google.com/
// @icon         https://www.google.com/s2/favicons?domain=google.com
// @license        public domain
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    let wl;
    const init = async () => {
        if (wl && !wl.released) {
            return true;
        }
        wl = null;
        if (document.visibilityState !== 'visible') {
            return;
        }
        console.log('WakeLock request');
        try {
            wl = await navigator.wakeLock.request('screen');
            console.log(wl);
            wl.addEventListener('release',e => {
                console.log('WakeLock released ');
                start();
            });
        } catch (e) {
            console.warn('e', e);
            return false;
        }
        console.log(' WakeLock locked');
        return true;
    };

    const start = async () => {
        if (!await init()) {
            setTimeout(start, 1000);
        }
    };

    start();
})();