Disable HTML5 Videos autoplay/preload

Prevent webbrowser from automatically playing/downloading HTML5 videos

As of 2016-02-18. See the latest version.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==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);
}());