YouTube Volume Slider Fix

Keeps YouTube's video volume perfectly in sync with the volume slider, preventing YouTube from capping the volume below 100% even when the slider is maxed out.

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         YouTube Volume Slider Fix
// @namespace    http://tampermonkey.net/
// @version      2.0
// @description  Keeps YouTube's video volume perfectly in sync with the volume slider, preventing YouTube from capping the volume below 100% even when the slider is maxed out.
// @author       Zeridiant
// @match        *://www.youtube.com/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function () {
    'use strict';

    let lastSliderValue = -1;

    function syncVolumeToSlider() {
        const video = document.querySelector('video');
        const volumePanel = document.querySelector('.ytp-volume-panel[role="slider"]');

        if (!video || !volumePanel) return;

        const sliderValueStr = volumePanel.getAttribute('aria-valuenow');
        if (!sliderValueStr) return;

        const sliderValue = parseInt(sliderValueStr, 10);
        if (isNaN(sliderValue)) return;

        if (sliderValue !== lastSliderValue) {
            lastSliderValue = sliderValue;
            const newVolume = sliderValue / 100;

            if (video.volume !== newVolume) {
                video.volume = newVolume;
                console.log(`[OK] Slider: ${sliderValue} : Volume: ${newVolume.toFixed(2)}`);
            }
        }
    }

    setInterval(syncVolumeToSlider, 200);

    const observer = new MutationObserver(() => {
        if (!document.querySelector('video')) return;
        lastSliderValue = -1;
    });

    observer.observe(document.body, { childList: true, subtree: true });
})();