Disable HTML5 Videos autoplay/preload

Prevent webbrowser from automatically playing/downloading HTML5 videos

Versione datata 18/02/2016. Vedi la nuova versione l'ultima versione.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

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