YouTube - Block progress bar click scrolling

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

2025/03/10のページです。最新版はこちら。

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください。
// ==UserScript==
// @name         YouTube - Block progress bar click scrolling
// @namespace    https://example.com
// @version      1.11
// @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 the click if it's on a YouTube menu button (e.g., the three dots on thumbnails)
        if (e.target.closest('.ytd-menu-renderer, .ytp-button')) {
            return; // Do nothing, let the click work normally
        }

        // 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();
        // Define a small buffer (adjust if needed)
        const bufferPixels = 5;

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