Always on focus


SUBMITTED BY: ccont2246

DATE: Dec. 22, 2022, 12:44 p.m.

FORMAT: Text only

SIZE: 1.3 kB

HITS: 892

  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. unsafeWindow.onblur = null;
  12. unsafeWindow.blurred = false;
  13. unsafeWindow.document.hasFocus = function () {return true;};
  14. unsafeWindow.window.onFocus = function () {return true;};
  15. Object.defineProperty(document, "hidden", { value : false});
  16. Object.defineProperty(document, "mozHidden", { value : false});
  17. Object.defineProperty(document, "msHidden", { value : false});
  18. Object.defineProperty(document, "webkitHidden", { value : false});
  19. Object.defineProperty(document, 'visibilityState', { get: function () { return "visible"; } });
  20. unsafeWindow.document.onvisibilitychange = undefined;
  21. for (event_name of ["visibilitychange",
  22. "webkitvisibilitychange",
  23. "blur", // may cause issues on some websites
  24. "mozvisibilitychange",
  25. "msvisibilitychange"]) {
  26. window.addEventListener(event_name, function(event) {
  27. event.stopImmediatePropagation();
  28. }, true);
  29. }

comments powered by Disqus