Block Page Visibility

Block page visibility events smartly

目前为 2022-04-20 提交的版本。查看 最新版本

// ==UserScript==
// @name         Block Page Visibility
// @namespace    https://www.androidacy.com/?f=disable_pva
// @version      0.2
// @description  Block page visibility events smartly
// @author       Androidacy
// @match        *
// @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()
    }
})();