Lower Youtube preview volume

Youtube previews are too goddamn loud and the volume is not settable, so I fixed it.

スクリプトをインストールするには、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         Lower Youtube preview volume
// @namespace    https://greasyfork.org/en/scripts/577264-lower-youtube-preview-volume
// @version      2026-05-09
// @description  Youtube previews are too goddamn loud and the volume is not settable, so I fixed it.
// @author       Vicbo
// @match        https://www.youtube.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=youtube.com
// @grant        GM_getValue
// @grant        GM_setValue
// @grant        GM_registerMenuCommand
// ==/UserScript==

(function() {
    'use strict';

    const isHomeScreen = () => {
        return location.hostname === "www.youtube.com" && location.pathname === "/";
    }

    const isPreviewVideo = videoElement => {
        return !!videoElement.closest("ytd-video-preview");
    };

    const DEFAULT_PREVIEW_VOLUME = 0.25;

    const getPreviewVolume = () => {
        return GM_getValue(
            "previewVolume",
            DEFAULT_PREVIEW_VOLUME
        );
    }

    const configureVolume = async () => {
        const current = getPreviewVolume();

        const input = prompt(
            "Youtube preview volume (0.0 - 1.0)",
            current
        );

        if (input === null) return;

        let value = parseFloat(input);

        if (isNaN(value) || value < 0 || value > 1) {
            value = DEFAULT_PREVIEW_VOLUME;
        }

        await GM_setValue("previewVolume", value);
    }

    GM_registerMenuCommand(
        "Set preview volume",
        configureVolume
    );

    const volumeDescriptor = Object.getOwnPropertyDescriptor(HTMLMediaElement.prototype, "volume");

    Object.defineProperty(HTMLMediaElement.prototype, "volume",
        {
            get() {
                return volumeDescriptor.get.call(this);
            },

            set(value) {
                if (isHomeScreen() && isPreviewVideo(this)) {
                    value = getPreviewVolume();
                }

                return volumeDescriptor.set.call(this, value);
            }
        }
    );
})();