Greasy Fork

Greasy Fork is available in English.

Youtube Music fix volume ratio

Makes the YouTube music volume slider exponential so it's easier to select lower volumes.

当前为 2021-06-20 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Youtube Music fix volume ratio
// @namespace    http://tampermonkey.net/
// @version      0.3
// @description  Makes the YouTube music volume slider exponential so it's easier to select lower volumes.
// @author       Marco Pfeiffer <[email protected]>
// @match        https://music.youtube.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // manipulation exponent, higher value = lower volume
    // higher values than 1.8 cause rounding issues somewhere within YouTubes logic (wich handles it as a percentage integer) or within the Browser ~ I don't know.
    // 5% is the lowest you can select in the UI
    const EXPONENT = 1.8;

    const {get, set} = Object.getOwnPropertyDescriptor(HTMLMediaElement.prototype, 'volume');
    Object.defineProperty(HTMLMediaElement.prototype, 'volume', {
        get () {
            const volume = get.call(this);
            const newVolume = volume ** (1 / EXPONENT);
            console.log('manipulated volume from', volume, 'to  ', newVolume, 'on', this);
            return newVolume;
        },
        set (volume) {
            const newVolume = volume ** EXPONENT;
            console.log('manipulated volume to  ', newVolume, 'from', volume, 'on', this);
            return set.call(this, newVolume);
        }
    });
})();