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.1
  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. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14. // For debugging, run localStorage.setItem('_daua_debug', 'true') in your console
  15. const debug = localStorage.getItem('_daua_debug')
  16. // Intercept all focus events
  17. const origEvtListener = window.addEventListener // eslint-disable-no-undef
  18. window.addEventListener = (a, b, c) => {
  19. if (a === 'blur' || a === 'focus' || a === 'visibilitychange' || a === 'webkitvisiblitychange') {
  20. if (debug) {
  21. console.debug('Nooping eventListener: ', a, b, c)
  22. }
  23. return undefined
  24. } else {
  25. return origEvtListener(a, b, c)
  26. }
  27. }
  28. window.addEventListener.toString = () => {
  29. return origEvtListener.toString()
  30. }
  31. })();