Last active
July 10, 2022 09:50
-
-
Save francistm/4e58e1b7ea81f6d7f2952661bd127bb6 to your computer and use it in GitHub Desktop.
An userscript to disable AV1 video decodec on youtube
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
// ==UserScript== | |
// @name No AV1 Video on Youtube | |
// @version 1.1 | |
// @description Disable AV1 video decodec on youtube, inspired by chrome extension https://github.com/Shimmermare/NotYetAV1 | |
// @author You | |
// @match *://*.youtube.com/* | |
// @match *://*.youtube-nocookie.com/* | |
// @match *://*.youtu.be/* | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=youtube.com | |
// @downloadURL https://gist.github.com/francistm/4e58e1b7ea81f6d7f2952661bd127bb6/raw/no-av1-video.user.js | |
// @updateURL https://gist.github.com/francistm/4e58e1b7ea81f6d7f2952661bd127bb6/raw/no-av1-video.user.js | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
// 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 || type.indexOf('av01') !== -1) return ''; | |
// Otherwise, ask the browser | |
return origChecker(type); | |
}; | |
} | |
// Override video element canPlayType() function | |
const videoElem = document.createElement('video'); | |
const origCanPlayType = videoElem.canPlayType.bind(videoElem); | |
const modifiedVideoProperty = Object.getPrototypeOf(videoElem); | |
modifiedVideoProperty.canPlayType = makeModifiedTypeChecker(origCanPlayType); | |
Object.setPrototypeOf(videoElem, modifiedVideoProperty); | |
// Override media source extension isTypeSupported() function | |
const mse = window.MediaSource; | |
// Check for MSE support before use | |
if (mse === undefined) { | |
return; | |
} | |
const origIsTypeSupported = mse.isTypeSupported.bind(mse); | |
mse.isTypeSupported = makeModifiedTypeChecker(origIsTypeSupported); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment