Disable DRC Audio on YouTube

Disables DRC Audio (Stable Volume) on YouTube

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Disable DRC Audio on YouTube
// @author       Adri
// @namespace    http://tampermonkey.net/
// @match        https://www.youtube.com/*
// @grant        none
// @version      0.1
// @description  Disables DRC Audio (Stable Volume) on YouTube
// @license      MIT
// @run-at       document-idle
// ==/UserScript==

// ad-hoc script - manipulates yt html/js to manually disable stable volume
// executes on first-page load, assumes yt doesn't change drc after that
(function() {
    'use strict';
    console.log('ya')
    function waitForElement(selector) {
        return new Promise((resolve, reject) => {
            let element = document.querySelector(selector);
            if (element) {
                resolve(element);
            } else {
                const observer = new MutationObserver(mutations => {
                    const element = document.querySelector(selector);
                    if (element) {
                        observer.disconnect();
                        resolve(element);
                    }
                });
                observer.observe(document.body, {
                    childList: true,
                    subtree: true
                });
            }
        });
    }

    function disableDRC() {
        return new Promise((resolve, reject) => {
            waitForElement('.ytp-settings-button')
                .then(menuButton => {
                    menuButton.click();
                    menuButton.click();
                    return waitForElement('.ytp-drc-menu-item');
                })
                .then(drcMenuItem => {
                    if (drcMenuItem.getAttribute('aria-checked') === 'true') {
                        drcMenuItem.click();
                        console.log('Disabled DRC Audio');
                    } else {
                        console.log('DRC Audio is already disabled');
                    }
                    resolve();
                })
                .catch(error => {
                    reject(error);
                });
        });
    }

    // Main execution
    disableDRC()
        .catch(error => {
            console.error('Error:', error);
        });

})();