Scrollbar Hider

Hides scrollbars globally but keeps scrolling functionality

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

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==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();
})();