YouTube - Force h.264 video + Non-DRC audio

This script disables VP9 and AV1 codecs on YouTube to force the H.264 codec (including the eliminated 'Stable Volume' option).

// ==UserScript==
// @name        YouTube - Force h.264 video + Non-DRC audio
// @author      LegendCraft (forked from Jeff S, Adri and The0x539)
// @namespace   Tampermonkey Scripts
// @version     2025.04.05
// @license     MIT
// @description This script disables VP9 and AV1 codecs on YouTube to force the H.264 codec (including the eliminated 'Stable Volume' option).
// @match       https://www.youtube.com/*
// @match       https://www.youtube-nocookie.com/*
// @match       https://www.youtu.be/*
// @run-at       document-idle
// @grant       none
// ==/UserScript==

// Modified from https://github.com/erkserkserks/h264ify/tree/master/src/inject as of 2018-05-16 (MIT license)

var mse = window.MediaSource;
if (mse){
  // Set up replacement for MediaSource type support function
  var nativeITS = mse.isTypeSupported.bind(mse);
  mse.isTypeSupported = ourITS(nativeITS);
}
// Here's the replacement
function ourITS(fallback){
  // type is a string (hopefully!) sent by the page
  return function (type) {
    if (type === undefined) return '';
    // We only reject VP9
    if (type.toLowerCase().indexOf('vp9') > -1) return '';
    if (type.toLowerCase().indexOf('vp09') > -1) return ''; // Added 12/20/2019
    // Let Firefox handle everything else
    return fallback(type);
  };
}

// Disable DRC (aka Stable Volume)
/* jshint esversion: 11 */

function waitForElement(selector) {
	return new Promise((resolve, reject) => {
		let element = document.querySelector(selector);
		if (element) {
			resolve(element);
			return;
		}

		const observer = new MutationObserver(mutations => {
			const element = document.querySelector(selector);
			if (element) {
				observer.disconnect();
				resolve(element);
			}
		});
		observer.observe(document.body, {
			childList: true,
			subtree: true
		});
	});
}

async function disableDRC() {
	const menuButton = await waitForElement('.ytp-settings-button');

	menuButton.click();
	menuButton.click();

	const drcMenuItem = await waitForElement('.ytp-drc-menu-item:not([aria-disabled])');

	if (drcMenuItem.getAttribute('aria-checked') === 'true') {
		drcMenuItem.click();
		console.log('Disabled DRC Audio');
	} else {
		console.log('DRC Audio is already disabled');
	}
}

disableDRC().catch(error => console.error('Error:', error));

(function() {
let css = `
/* Remove the 'Stable volume' option from the menu */
.ytp-panel .ytp-menuitem.ytp-drc-menu-item {
display: none !important
}`;
if (typeof GM_addStyle !== "undefined") {
  GM_addStyle(css);
} else {
  let styleNode = document.createElement("style");
  styleNode.appendChild(document.createTextNode(css));
  (document.querySelector("head") || document.documentElement).appendChild(styleNode);
}
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址