YouTube Fullscreen Scroll Disabler

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

目前為 2024-09-29 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         YouTube Fullscreen Scroll Disabler
// @namespace    https://youtube.com
// @version      1.0
// @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
    }

})();