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.

目前為 2023-05-11 提交的版本,檢視 最新版本

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

You will need to install an extension such as Tampermonkey to install this script.

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        YouTube, STOP CHANGING MY VOLUME!
// @namespace   Violentmonkey Scripts
// @match       https://www.youtube.com/watch
// @grant       none
// @version     1.0
// @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 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);
    // The maximum distance is 40px, so divide by 40 to get the desired volume value
    var volumeHandleValue = parseFloat(volumeHandleLeft) / 40;

    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;
}