Always on focus

Prevent websites from knowing that you switched tabs

目前為 2021-07-20 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name Always on focus
  3. // @namespace https://github.com/daijro/always-on-focus
  4. // @description Prevent websites from knowing that you switched tabs
  5. // @author daijro
  6. // @version 1.1
  7. // @description Trick websites into thinking the tab is always on focus
  8. // @include *
  9. // @run-at document-start
  10. // ==/UserScript==
  11.  
  12. unsafeWindow.onblur = null;
  13. unsafeWindow.blurred = false;
  14.  
  15. unsafeWindow.document.hasFocus = function () {return true;};
  16. unsafeWindow.window.onFocus = function () {return true;};
  17.  
  18. Object.defineProperty(document, "hidden", { value : false});
  19. Object.defineProperty(document, "mozHidden", { value : false});
  20. Object.defineProperty(document, "msHidden", { value : false});
  21. Object.defineProperty(document, "webkitHidden", { value : false});
  22. Object.defineProperty(document, 'visibilityState', { get: function () { return "visible"; } });
  23.  
  24. unsafeWindow.document.onvisibilitychange = undefined;
  25.  
  26. for (event_name of ["visibilitychange",
  27. "webkitvisibilitychange",
  28. "blur", // may cause issues on some websites
  29. "mozvisibilitychange",
  30. "msvisibilitychange"]) {
  31. window.addEventListener(event_name, function(event) {
  32. event.stopImmediatePropagation();
  33. }, true);
  34. }

QingJ © 2025

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