YouTube Fullscreen Scroll Disabler

Disable scrolling when YouTube is in fullscreen mode and hide scrollbar.

当前为 2024-09-29 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         YouTube Fullscreen Scroll Disabler
// @namespace    https://youtube.com
// @version      1.0.1
// @description  Disable scrolling when YouTube is in fullscreen mode and hide scrollbar.
// @author       Lolen10
// @match        *://www.youtube.com/*
// @icon         https://www.google.com/s2/favicons?domain=youtube.com
// @grant        none
// @license      GNU GPLv3
// ==/UserScript==

(function() {
    'use strict';

    let hiddenElements = [];

    // Check for fullscreen change events
    document.addEventListener('fullscreenchange', toggleScrollAndContent);
    document.addEventListener('webkitfullscreenchange', toggleScrollAndContent); // For older browsers
    document.addEventListener('mozfullscreenchange', toggleScrollAndContent); // For Firefox

    // Disable scrolling and remove content when in fullscreen
    function toggleScrollAndContent() {
        if (isFullScreen()) {
            disableScroll();
            removeContentBelowContainer();
        } else {
            enableScroll();
            restoreContentBelowContainer();
        }
    }

    // Check if the document is in fullscreen mode
    function isFullScreen() {
        return document.fullscreenElement || document.webkitFullscreenElement || document.mozFullScreenElement;
    }

    // Function to disable scrolling with the scrollwheel
    function disableScroll() {
        window.addEventListener('wheel', preventScroll, { passive: false }); // Disable mouse scroll
    }

    // Function to enable scrolling with the scrollwheel
    function enableScroll() {
        window.removeEventListener('wheel', preventScroll, { passive: false }); // Re-enable mouse scroll
    }

    // Prevent the default scroll action
    function preventScroll(e) {
        e.preventDefault();
    }

    // Function to remove all content below the video-player
    function removeContentBelowContainer() {
        const container = document.getElementById('single-column-container');
        if (container) {
            let nextSibling = container.nextElementSibling;

            // Loop through all next sibling elements and hide them
            while (nextSibling) {
                hiddenElements.push(nextSibling); // Save hidden elements
                nextSibling.style.display = 'none'; // Hide the element
                nextSibling = nextSibling.nextElementSibling;
            }
        }
    }

    // Function to restore content that was hidden when exiting fullscreen-mode
    function restoreContentBelowContainer() {
        hiddenElements.forEach(element => {
            element.style.display = ''; // Reset the display property to show them again
        });
        hiddenElements = []; // Clear the list after restoring
    }

})();