Block Page Visibility

Block page visibility events smartly

目前為 2022-04-20 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name Block Page Visibility
  3. // @namespace https://www.androidacy.com/?f=disable_pva
  4. // @version 0.2
  5. // @description Block page visibility events smartly
  6. // @author Androidacy
  7. // @match *
  8. // @icon https://www.androidacy.com/wp-content/uploads/cropped-cropped-cropped-cropped-New-Project-32-69C2A87-1-192x192.jpg
  9. // @grant none
  10. // @run-at document-start
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15. // For debugging, run localStorage.setItem('_daua_debug', 'true') in your console
  16. const debug = localStorage.getItem('_daua_debug')
  17. // Intercept all focus events
  18. const origEvtListener = window.addEventListener // eslint-disable-no-undef
  19. window.addEventListener = (a, b, c) => {
  20. if (a === 'blur' || a === 'focus' || a === 'visibilitychange' || a === 'webkitvisiblitychange') {
  21. if (debug) {
  22. console.debug('Nooping eventListener: ', a, b, c)
  23. }
  24. return undefined
  25. } else {
  26. return origEvtListener(a, b, c)
  27. }
  28. }
  29. window.addEventListener.toString = () => {
  30. return origEvtListener.toString()
  31. }
  32. })();