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.0
// @license      MIT
// @grant        sr_IRS
// @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; just making sure lol. */
        * {
            scrollbar-width: none;
            -ms-overflow-style: none;
        }

        /* Ensure html and body can still scroll vertically */
        html, body {
            overflow-y: auto;
            overflow-x: hidden;
        }
    `;

    /**
     * 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 either using sr_IRS or by injecting it manually. >_<
     */
    const applyScrollbarHider = () => {
        if (typeof sr_IRS === 'function') {
            sr_IRS(scrollbarHiderCSS);
        } else {
            injectCSS(scrollbarHiderCSS);
        }
    };

    applyScrollbarHider();
})();