Disable HTML5 Videos autoplay/autopreload

Prevent webbrowser from automatically playing/downloading HTML5 videos

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name        Disable HTML5 Videos autoplay/autopreload
// @namespace   default
// @include     *
// @version     2.0
// @grant       none
// @description Prevent webbrowser from automatically playing/downloading HTML5 videos
// ==/UserScript==


document.addEventListener("DOMContentLoaded", function(e) {

    var disable_videos = function() {
        var videos = document.getElementsByTagName("video");

        if (document.readyState !== "interactive") {
            Array.forEach(videos, function(video) {
                if (!video.getAttribute("gm_processed")) return;
                //Now that document has completed loading, bring back video's original url
                video.setAttribute("src", video.getAttribute("gm_src"));
                video.pause();
                video.removeAttribute("gm_processed");
            });
            return;
        }
        setTimeout(disable_videos, 1000);

        Array.forEach(videos, function(video) {
            if (video.getAttribute("gm_processed")) return;
            var old_url = video.currentSrc;
            //Only process a video if it has "src" but not one starting with mediasource:
            if (old_url && (!old_url.startsWith("mediasource:"))) {
                console.log("GMoneky: disabling autoplay for ", video);
                video.removeAttribute("autoplay");
                video.removeAttribute("autobuffer");
                video.setAttribute("preload", "metadata");

                video.setAttribute("src", "about:blank");
                video.setAttribute("gm_src", old_url);
                video.setAttribute("gm_processed", true);
            }
        });
    };
    disable_videos();
});