Disable page visibility API

Block autoplay and pagevisibility events

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// esversion: 6
// ==UserScript==
// @name         Disable page visibility API
// @namespace    https://www.androidacy.com/pva/
// @version      1.2
// @description  Block autoplay and pagevisibility events
// @author       Androidacy
// @include      *
// @exclude      https://www.google.com/adsense/new/*
// @icon         https://www.androidacy.com/wp-content/uploads/cropped-cropped-cropped-cropped-New-Project-32-69C2A87-1-192x192.jpg
// @grant        none
// @run-at       document-start
// ==/UserScript==

(function() {
    'use strict';
    // For debugging, run localStorage.setItem('_daua_debug', 'true') in your console
    const debug = localStorage.getItem('_daua_debug')
    // Intercept all focus events
    const origEvtListener = window.addEventListener // eslint-disable-no-undef
    window.addEventListener = (a, b, c) => {
        if (a === 'blur' || a === 'focus' || a === 'visibilitychange' || a === 'webkitvisiblitychange') {
            if (debug) {
                console.debug('Nooping eventListener: ', a, b, c)
            }
            return undefined
        } else {
            return origEvtListener(a, b, c)
        }
    }
    window.addEventListener.toString = () => {
        return origEvtListener.toString()
    }
})();