Disable page visibility API

Block autoplay and pagevisibility events

当前为 2022-04-20 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// esversion: 6
// ==UserScript==
// @name         Disable page visibility API
// @namespace    https://www.androidacy.com/pva/
// @version      1.1
// @description  Block autoplay and pagevisibility events
// @author       Androidacy
// @match        *
// @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()
    }
})();