Idle Detection Bypasser

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

  1. // ==UserScript==
  2. // @name Idle Detection Bypasser
  3. // @name:zh 绕过 Idle Detection
  4. // @name:zh-CN 绕过 Idle Detection
  5. // @namespace https://github.com/flyhaozi
  6. // @version 0.2.1
  7. // @description Give a fake active response to the caller of the Idle Detection API
  8. // @description:zh 给 Idle Detection API 的调用者一个虚假的 active 响应
  9. // @description:zh-CN 给 Idle Detection API 的调用者一个虚假的 active 响应
  10. // @author flyhaozi
  11. // @match https://*/*
  12. // @match http://*/*
  13. // @run-at document-start
  14. // @grant none
  15. // ==/UserScript==
  16.  
  17. (function() {
  18. 'use strict';
  19. // https://wicg.github.io/idle-detection/#api
  20. // https://chromium.googlesource.com/chromium/src/+/01971188f2f12266e0e4d119a294c52f4a3b0f41/third_party/blink/renderer/modules/idle/idle_detector.h
  21. // https://chromium.googlesource.com/chromium/src/+/01971188f2f12266e0e4d119a294c52f4a3b0f41/third_party/blink/renderer/modules/idle/idle_detector.cc
  22. const fakeDetector = function() {
  23. this.userState = null;
  24. this.screenState = null;
  25. };
  26.  
  27. fakeDetector.requestPermission = async function() {
  28. return Promise.resolve('granted');
  29. };
  30.  
  31. fakeDetector.prototype = Object.create(EventTarget.prototype);
  32. fakeDetector.prototype.start = async function(options) {
  33. this.userState = 'active';
  34. this.screenState = 'unlocked';
  35. this.dispatchEvent(new Event('change'));
  36. };
  37.  
  38. Object.defineProperty(window, 'IdleDetector', { value: fakeDetector, configurable: false, writable: false });
  39. console.log('Idle Detector Hijacked!');
  40. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址