您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Block autoplay and pagevisibility events
当前为
// esversion: 6 // ==UserScript== // @name Disable autoplay and visiblity API // @namespace https://www.androidacy.com/ // @version 0.7.3 // @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-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 for (let i of ["blur", "focus", "visibilitychange", "webkitvisiblitychange"]) { if (debug) { console.debug("Nooping " + i + " events"); } window.addEventListener(i, function(event) { event.stopImmediatePropagation(); console.debug("Stopped " + i + " from triggering"); }, true); } // Disable autoplay window.addEventListener('DOMContentLoaded', () => { 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 && !window._apun) { if (debug) { console.debug("Unblocking play because user clicked on:"); console.debug(evt.target); } i.play = i.origPlay; i.play(); window._apun = true; } }); i.parentNode.addEventListener("click", (evt) => { if (evt.isTrusted && !window._apun) { if (debug) { console.debug("Unblocking play because user clicked on:"); console.debug(evt.target); } i.play = i.origPlay; i.play(); window._apun = true; } }); } }) })();