Disable HTML5 Videos autoplay/preload

Prevent webbrowser from automatically playing/downloading HTML5 videos

当前为 2016-02-18 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        Disable HTML5 Videos autoplay/preload
// @description Prevent webbrowser from automatically playing/downloading HTML5 videos
// @namespace   default
// @include     *
// @exclude     http*://www.youtube.com/*
// @version     1
// @grant       none
// @author      Ramast Magdy (ramast dot com at gmail dot com)
// ==/UserScript==

void(function() {
    var prevent_autoplay = function() {
        var videos = document.getElementsByTagName("video");
        var video;
        for (var i=0; i < videos.length; i++) {
            video = videos[i];
            video.removeAttribute("autoplay");
            video.removeAttribute("autobuffer");
            video.setAttribute("preload", "metadata");
        }
    };
    // after 0.3, 1, 2 and 4 seconds
    // This is because sometimes video is loaded through some JS code
    setTimeout(prevent_autoplay, 300);
    setTimeout(prevent_autoplay, 1000);
    setTimeout(prevent_autoplay, 2000);
    setTimeout(prevent_autoplay, 4000);
}());