Greasy Fork

Greasy Fork is available in English.

YouTube H.264 (h264ify)

https://github.com/erkserkserks/h264ify

当前为 2023-11-18 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name YouTube H.264 (h264ify) 
// @name:ru YouTube H.264 (h264ify)
// @namespace https://www.youtube.com
// @version 18112023.1
// @description https://github.com/erkserkserks/h264ify
// @description:ru https://github.com/erkserkserks/h264ify
// @match *://*.youtube.com/*
// @match *://*.youtube-nocookie.com/*
// @match *://*.youtubekids.com/*
// @license MIT
// @grant none
// @run-at document-start
// ==/UserScript==

// false or true for 30fps
let block60fps = true;

function h264ify() {
    // Override video element canPlayType() function
    var videoElem = document.createElement('video');
    var origCanPlayType = videoElem.canPlayType.bind(videoElem);
    videoElem.__proto__.canPlayType = makeModifiedTypeChecker(origCanPlayType);

    // Override media source extension isTypeSupported() function
    var mse = window.MediaSource;
    // Check for MSE support before use
    if (mse === undefined) return;
    var origIsTypeSupported = mse.isTypeSupported.bind(mse);
    mse.isTypeSupported = makeModifiedTypeChecker(origIsTypeSupported);
}

  // return a custom MIME type checker that can defer to the original function 
function makeModifiedTypeChecker(origChecker) {
  // Check if a video type is allowed
  return function (type) {
    if (type === undefined) return '';
    var disallowed_types = ['webm', 'vp8', 'vp9', 'av01'];
    // If video type is in disallowed_types, say we don't support them
    for (var i = 0; i < disallowed_types.length; i++) {
      if (type.indexOf(disallowed_types[i]) !== -1) return '';
    }

    if (block60fps) {
      var match = /framerate=(\d+)/.exec(type);
      if (match && match[1] > 30) return '';
    }

    // Otherwise, ask the browser
    return origChecker(type);
  };
}

h264ify();