Idle Detection Bypasser

Give a fake active response to the caller of the Idle Detection API

Tính đến 27-09-2021. Xem phiên bản mới nhất.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

Bạn sẽ cần cài đặt một tiện ích mở rộng như Tampermonkey hoặc Violentmonkey để cài đặt kịch bản này.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(Tôi đã có Trình quản lý tập lệnh người dùng, hãy cài đặt nó!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name                Idle Detection Bypasser
// @name:zh             绕过 Idle Detection
// @name:zh-CN          绕过 Idle Detection
// @namespace           https://github.com/flyhaozi
// @version             0.2.1
// @description         Give a fake active response to the caller of the Idle Detection API
// @description:zh      给 Idle Detection API 的调用者一个虚假的 active 响应
// @description:zh-CN   给 Idle Detection API 的调用者一个虚假的 active 响应
// @author              flyhaozi
// @match               https://*/*
// @match               http://*/*
// @run-at              document-start
// @grant               none
// ==/UserScript==

(function() {
    'use strict';
    // https://wicg.github.io/idle-detection/#api
    // https://chromium.googlesource.com/chromium/src/+/01971188f2f12266e0e4d119a294c52f4a3b0f41/third_party/blink/renderer/modules/idle/idle_detector.h
    // https://chromium.googlesource.com/chromium/src/+/01971188f2f12266e0e4d119a294c52f4a3b0f41/third_party/blink/renderer/modules/idle/idle_detector.cc
    const fakeDetector = function() {
        this.userState = null;
        this.screenState = null;
    };

    fakeDetector.requestPermission = async function() {
        return Promise.resolve('granted');
    };

    fakeDetector.prototype = Object.create(EventTarget.prototype);
    
    fakeDetector.prototype.start = async function(options) {
        this.userState = 'active';
        this.screenState = 'unlocked';
        this.dispatchEvent(new Event('change'));
    };

    Object.defineProperty(window, 'IdleDetector', { value: fakeDetector, configurable: false, writable: false });
    console.log('Idle Detector Hijacked!');
})();