Scrollbar Hider

Hides scrollbars globally but keeps scrolling functionality

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

// ==UserScript==
// @name         Scrollbar Hider
// @description  Hides scrollbars globally but keeps scrolling functionality
// @author       SSL-ACTX
// @version      1.0.1
// @license      MIT
// @grant        none
// @run-at       document-start
// @match        *://*/*
// @namespace https://greasyfork.org/users/1365732
// ==/UserScript==

(function() {
    'use strict';

    // CSS rules to hide scrollbars but retain scrolling functionality :)
    const scrollbarHiderCSS = `
        /* Remove WebKit-based browsers' scrollbars */
        *::-webkit-scrollbar {
            width: 0;
            height: 0;
        }

        /* Hide scrollbars in Firefox, IE, and Edge */
        * {
            scrollbar-width: none;
            -ms-overflow-style: none;
        }
    `;

    /**
     * Injects the provided CSS into the document.
     */
    const injectCSS = (cssRules) => {
        const styleElement = document.createElement('style');
        styleElement.type = 'text/css';
        styleElement.textContent = cssRules;
        document.head.appendChild(styleElement);
    };

    /**
     * Applies the CSS for hiding scrollbars by injecting it manually.
     */
    const applyScrollbarHider = () => {
        injectCSS(scrollbarHiderCSS);
    };

    applyScrollbarHider();
})();