YouTube Exponential Volume Slider

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

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

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

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==UserScript==
// @name         YouTube Exponential Volume Slider
// @namespace    https://www.tampermonkey.net/
// @version      1.1.3
// @description  Makes the YouTube volume slider exponential so it's easier to select lower volumes.
// @author       Lukas Reinert
// @icon         https://www.youtube.com/img/favicon.ico
// @match        https://www.youtube.com/*
// @match        https://music.youtube.com/*
// @license      MIT
// @run-at       document-start
// @grant        none
// ==/UserScript==
 
(function() {
    'use strict';
 
    const EXPONENT = 2.5;
 
    const storedOriginalVolumes = new WeakMap();
    const {get, set} = Object.getOwnPropertyDescriptor(HTMLMediaElement.prototype, 'volume');
 
    Object.defineProperty(HTMLMediaElement.prototype, 'volume', {
        get() {
            const lowVolume = get.call(this);
            const storedOriginalVolume = storedOriginalVolumes.get(this);
            if (storedOriginalVolume !== undefined) return storedOriginalVolume;
            return Math.pow(lowVolume, 1 / EXPONENT);
        },
        set(originalVolume) {
            const adjustedVolume = Math.pow(originalVolume, EXPONENT);
            storedOriginalVolumes.set(this, originalVolume);
            set.call(this, adjustedVolume);
 
            console.log(`YouTube Volume: ${Math.round(originalVolume*100)}% (adjusted to ${(adjustedVolume * 100).toFixed(3)}%)`);
        }
    });
 
    // Ensure any videos already on the page get their volume adjusted
    const videos = document.getElementsByTagName('video');
    for (const video of videos) {
        if (!storedOriginalVolumes.has(video)) {
            const orig = video.volume;
            video.volume = orig; // triggers setter
        }
    }
 
})();