Created
July 5, 2022 22:29
-
-
Save jjakob/1d1a234f89d8f54fc276f5afeda16256 to your computer and use it in GitHub Desktop.
webkit-gtk userscript h264ify (copied from https://github.com/erkserkserks/h264ify/blob/master/src/inject/inject.js , inspired by https://greasyfork.org/en/scripts/8128-youtube-h-264/code )
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* webkit-gtk userscript h264ify | |
* Licensed under The MIT License (MIT) | |
* Original author: Copyright (c) 2015 erkserkserks | |
*/ | |
function override() { | |
// 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 (localStorage['h264ify-block_60fps'] === 'true') { | |
var match = /framerate=(\d+)/.exec(type); | |
if (match && match[1] > 30) return ''; | |
} | |
// Otherwise, ask the browser | |
return origChecker(type); | |
}; | |
} | |
override(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment