YouTube - Block progress bar click scrolling

Prevent clicks below the red timeline scrolling, but allow control buttons to work

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         YouTube - Block progress bar click scrolling
// @namespace    https://example.com
// @version      1.12
// @description  Prevent clicks below the red timeline scrolling, but allow control buttons to work
// @match        *://www.youtube.com/*
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    document.addEventListener('click', function(e) {
        // Allow interaction with YouTube menu buttons (three dots, settings, etc.)
        if (e.target.closest('.ytd-menu-renderer, .ytp-button, .ytd-popup-container, .yt-simple-endpoint')) {
            return; // Allow menu interactions
        }

        // Ensure the script runs only on the video player page
        if (!document.querySelector('.html5-video-player')) return;

        // Get the progress bar container
        const progressBar = document.querySelector('.ytp-progress-bar-container');
        if (!progressBar) return; // If not found, do nothing

        // Get the bounding rectangle of the progress bar
        const rect = progressBar.getBoundingClientRect();
        const bufferPixels = 5; // Small buffer to avoid false positives

        // If the click is below the progress bar plus buffer, block the event
        if (e.clientY > rect.bottom + bufferPixels) {
            e.stopPropagation();
            e.preventDefault();
        }
    }, true);
})();