Disable autoplay and visiblity API

Block autoplay and pagevisibility events

目前為 2022-03-03 提交的版本,檢視 最新版本

// esversion: 6
// ==UserScript==
// @name         Disable autoplay and visiblity API
// @namespace    https://www.androidacy.com/
// @version      0.6
// @description  Block autoplay and pagevisibility events
// @author       Androidacy
// @include      http://*
// @include      https://*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=google.com
// @grant        none
// @run-at       document-end
// ==/UserScript==

(function() {
    'use strict';
    // Intercept all focus events
    for (let i of ["blur", "focus", "visibilitychange"]) {
        console.debug("Nooping event: " + i);
        window.addEventListener(i, function(event) {
            console.debug("Blocked event: " + i);
            event.stopImmediatePropagation();
        }, true);
    }
    // Disable autoplay
    let x = document.querySelectorAll('video')
    for (let i of x) {
        i.removeAttribute('autoplay');
        i.pause();
        i.origPlay = i.play;
        i.play = function () {};
        i.addEventListener("click", (evt) => {
            if (evt.isTrusted) {
                i.play = i.origPlay;
                i.origPlay();
            }
        });
    }
})();