YouTube, STOP CHANGING MY VOLUME!

Detects when YouTube tries to do "loudness normalization" and sets the volume back to what's set on the volume slider.

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        YouTube, STOP CHANGING MY VOLUME!
// @namespace   Violentmonkey Scripts
// @match       https://www.youtube.com/watch
// @grant       none
// @version     1.2
// @author      Elara6331 <[email protected]>
// @license     GPLv3
// @description Detects when YouTube tries to do "loudness normalization" and sets the volume back to what's set on the volume slider.
// ==/UserScript==


window.onload = () => {
  player = document.querySelector('video');
  volumeHandle = document.querySelector('.ytp-volume-slider-handle');

  function sliderDistance() {
    if (player.parentElement.parentElement.classList.contains('ytp-big-mode')) {
      return 60;
    } else {
      return 40;
    }
  }
  
  function checkVolume() {
    // Get the distance in pixels of the volume slider handle from the beginning of the slider
    var volumeHandleLeft = volumeHandle.style.left.substr(0, volumeHandle.style.left.length - 2);
    // Divide by the maximum distance to get the desired volume value
    var volumeHandleValue = parseFloat(volumeHandleLeft) / sliderDistance();

    if (volumeHandleValue != player.volume) {
      console.warn("Volume discrepancy detected. YouTube is up to its shenanigans again. Changing volume from " + player.volume * 100 + "% to " + volumeHandleValue * 100 + "%");
      player.volume = volumeHandleValue;
    }
  }

  player.onvolumechange = checkVolume;
  player.onplaying = checkVolume;
}