YouTube video/mp4

Plays video in h.264 format.

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        YouTube video/mp4
// @version     1.0
// @description Plays video in h.264 format.
// @author      gvvad
// @run-at      document-start
// @include     *.youtube.com/*
// @grant       none
// @noframes
// @license     MIT; https://opensource.org/licenses/MIT
// @copyright   2020, gvvad
// @namespace   https://greasyfork.org/users/100160
// ==/UserScript==

(function () {
    'use strict';

    function getCustomMimeChecker(producer, isBool) {
        const rejector = /(webm|vp8|vp9|av01)/;

        return function (mime) {
            if (rejector.test(mime)) {
                return (isBool) ? false : '';
            }

            return producer(mime);
        };
    }

    let videoElem = document.createElement('video');
    let v_proto = Object.getPrototypeOf(videoElem);
    v_proto.canPlayType = getCustomMimeChecker(v_proto.canPlayType.bind(videoElem), false);
    Object.setPrototypeOf(videoElem, v_proto);

    if (window.MediaSource === undefined) return;
    window.MediaSource.isTypeSupported = getCustomMimeChecker(window.MediaSource.isTypeSupported, true);
})();