OmniFocus

Make sure websites always think you are focused on them

  1. // ==UserScript==
  2. // @name OmniFocus
  3. // @namespace https://greasyfork.org/en/users/198860-zyenith
  4. // @author zyenith
  5. // @version 0.0.1
  6. // @description Make sure websites always think you are focused on them
  7. // @match *://*/*
  8. // @run-at document-start
  9. // @grant unsafeWindow
  10. // @antifeature Tracking, for compatibility info
  11. // @require https://greasyfork.org/scripts/410512-sci-js-from-ksw2-center/code/scijs%20(from%20ksw2-center).js
  12. // ==/UserScript==
  13.  
  14. const { document } = unsafeWindow;
  15.  
  16. unsafeWindow.onblur = null;
  17. unsafeWindow.blurred = false;
  18.  
  19. unsafeWindow.document.hasFocus = function() {
  20. return true;
  21. };
  22.  
  23. unsafeWindow.document.onvisibilitychange = undefined;
  24.  
  25. const _arr = ["visibilitychange", "webkitvisibilitychange", "blur", "mozvisibilitychange", "msvisibilitychange"];
  26. for (const eventName of _arr) {
  27. unsafeWindow.document.addEventListener(eventName, (event) => {
  28. event.stopImmediatePropagation();
  29. }, true);
  30. }
  31.  
  32. Object.defineProperties(unsafeWindow.document, {
  33. hidden: {
  34. value: false
  35. },
  36. mozHidden: {
  37. value: false
  38. },
  39. msHidden: {
  40. value: false
  41. },
  42. webkitHidden: {
  43. value: false
  44. },
  45. visibilityState: {
  46. get() {
  47. return "visible";
  48. }
  49. }
  50. });