Always on focus

Prevents websites from knowing that you switched tabs or unfocused the window

目前为 2023-10-05 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Always on focus
  3. // @namespace https://github.com/daijro/always-on-focus
  4. // @author daijro
  5. // @version 1.5
  6. // @description Prevents websites from knowing that you switched tabs or unfocused the window
  7. // @include *
  8. // @run-at document-start
  9. // ==/UserScript==
  10.  
  11.  
  12. unsafeWindow.onblur = null;
  13. unsafeWindow.blurred = false;
  14.  
  15. unsafeWindow.document.hasFocus = () => true;
  16. unsafeWindow.window.onFocus = () => true;
  17.  
  18. // kill dom property names
  19. [
  20. "hidden",
  21. "mozHidden",
  22. "msHidden",
  23. "webkitHidden"
  24. ].forEach(prop_name => {
  25. Object.defineProperty(document, prop_name, {value: false});
  26. })
  27.  
  28. Object.defineProperty(document, "visibilityState", {get: () => "visible"});
  29. Object.defineProperty(document, "webkitVisibilityState", {get: () => "visible"});
  30.  
  31. unsafeWindow.document.onvisibilitychange = undefined;
  32.  
  33.  
  34. var event_handler = (event) => {
  35. if (["blur", "mouseleave", "mouseout"].includes(event.type) &&
  36. (event.target instanceof HTMLInputElement ||
  37. event.target instanceof HTMLAnchorElement ||
  38. event.target instanceof HTMLSpanElement)) {
  39. return // exclude input, anchor, and span elements
  40. }
  41. event.preventDefault();
  42. event.stopPropagation();
  43. event.stopImmediatePropagation();
  44. }
  45.  
  46. // kill event listeners
  47. [
  48. "visibilitychange",
  49. "webkitvisibilitychange",
  50. "blur",
  51. "hasFocus",
  52. "mouseleave",
  53. "mouseout",
  54. "mozvisibilitychange",
  55. "msvisibilitychange"
  56. ].forEach(event_name => {
  57. window.addEventListener(event_name, event_handler, true);
  58. document.addEventListener(event_name, event_handler, true);
  59. })

QingJ © 2025

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