Disable page visibility API

Block autoplay and pagevisibility events

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