Disable DRC Audio on YouTube

The script disables DRC audio (Stable Volume) on YouTube (which also works with loudness normalization disabled scripts).

  1. // ==UserScript==
  2. // @name Disable DRC Audio on YouTube
  3. // @author LegendCraft (forked from Adri and The0x539)
  4. // @namespace Tampermonkey Scripts
  5. // @match https://www.youtube.com/*
  6. // @grant none
  7. // @version 2024.03.19
  8. // @description The script disables DRC audio (Stable Volume) on YouTube (which also works with loudness normalization disabled scripts).
  9. // @license MIT
  10. // @run-at document-idle
  11. // ==/UserScript==
  12. /* jshint esversion: 11 */
  13.  
  14. function waitForElement(selector) {
  15. return new Promise((resolve, reject) => {
  16. let element = document.querySelector(selector);
  17. if (element) {
  18. resolve(element);
  19. return;
  20. }
  21.  
  22. const observer = new MutationObserver(mutations => {
  23. const element = document.querySelector(selector);
  24. if (element) {
  25. observer.disconnect();
  26. resolve(element);
  27. }
  28. });
  29. observer.observe(document.body, {
  30. childList: true,
  31. subtree: true
  32. });
  33. });
  34. }
  35.  
  36. async function disableDRC() {
  37. const menuButton = await waitForElement('.ytp-settings-button');
  38.  
  39. menuButton.click();
  40. menuButton.click();
  41.  
  42. const drcMenuItem = await waitForElement('.ytp-drc-menu-item:not([aria-disabled])');
  43.  
  44. if (drcMenuItem.getAttribute('aria-checked') === 'true') {
  45. drcMenuItem.click();
  46. console.log('Disabled DRC Audio');
  47. } else {
  48. console.log('DRC Audio is already disabled');
  49. }
  50. }
  51.  
  52. disableDRC().catch(error => console.error('Error:', error));
  53.  
  54. (function() {
  55. let css = `
  56. /* Remove the 'Stable volume' option from the menu */
  57. .ytp-panel .ytp-menuitem.ytp-drc-menu-item {
  58. display: none !important
  59. }`;
  60. if (typeof GM_addStyle !== "undefined") {
  61. GM_addStyle(css);
  62. } else {
  63. let styleNode = document.createElement("style");
  64. styleNode.appendChild(document.createTextNode(css));
  65. (document.querySelector("head") || document.documentElement).appendChild(styleNode);
  66. }
  67. })();