erkserkserks / h264ify

A Chrome extension that makes YouTube stream H.264 videos instead of VP8/VP9 videos
MIT License
1.01k stars 112 forks source link

is there any greasemonkey script ? #68

Open praised opened 4 years ago

Kein commented 4 years ago

No-options implementation, just forces h264, no fps blocks:

// ==UserScript==
// @name        h264ify for Youtube
// @namespace   Violentmonkey Scripts
// @match       https://www.youtube.com/*
// @grant       none
// @version     1.0
// @author      erkserkserks
// @run-at      document-start
// @description 7/22/2020, 12:05:25 PM
// ==/UserScript==

(function() {
'use strict';

    console.log("h264ify injected");
    // 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 '';
      }

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

})();
dnmTX commented 3 years ago

Hey @Kein nice UserScript but can you make it to fire when YouTube player is present as what the extension does. Basically it has to document.querySelectorAll('iframe').forEach.... and look for the /embed... otherwise return false ...... Something like this....i guess... 👍

dnmTX commented 3 years ago

@erkserkserks any chance you make one. Nothing fancy,no options,just to switch to H.264 based on iframe's src= and that's it. 👍