Scrollbar Hider

Hides scrollbars globally but keeps scrolling functionality

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

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

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==UserScript==
// @name         Scrollbar Hider
// @description  Hides scrollbars globally but keeps scrolling functionality
// @author       SSL-ACTX
// @version      1.1.0
// @license      MIT
// @grant        none
// @run-at       document-start
// @match        *://*/*
// @namespace https://greatest.deepsurf.us/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;
        }
    `;

    // Key combination to toggle scrollbars (default: Ctrl + Alt + M)
    const TOGGLE_KEY_COMBINATION = {
        ctrlKey: true,
        altKey: true,
        key: 'm'  // Key to toggle (lowercase, but we'll handle both cases)
    };

    // Flag to track if scrollbars are currently hidden
    let scrollbarsHidden = false;

    /**
     * Injects the provided CSS into the document.
     */
    const injectCSS = (cssRules) => {
        try {
            const styleElement = document.createElement('style');
            styleElement.id = 'scrollbar-hider-style';
            styleElement.type = 'text/css';
            styleElement.textContent = cssRules;
            document.head.appendChild(styleElement);
        } catch (error) {
            console.error('Failed to inject CSS:', error);
        }
    };

    /**
     * Removes the injected CSS.
     */
    const removeCSS = () => {
        try {
            const styleElement = document.getElementById('scrollbar-hider-style');
            if (styleElement) {
                styleElement.remove();
            }
        } catch (error) {
            console.error('Failed to remove CSS:', error);
        }
    };

    /**
     * Toggles the visibility of scrollbars.
     */
    const toggleScrollbars = () => {
        if (scrollbarsHidden) {
            removeCSS();
        } else {
            injectCSS(scrollbarHiderCSS);
        }
        scrollbarsHidden = !scrollbarsHidden;
        // Save preference in localStorage
        localStorage.setItem('scrollbarsHidden', scrollbarsHidden);
    };

    /**
     * Adds event listener for keypress to toggle scrollbars.
     */
    const addToggleListener = () => {
        document.addEventListener('keydown', (event) => {
            if (event.ctrlKey === TOGGLE_KEY_COMBINATION.ctrlKey &&
                event.altKey === TOGGLE_KEY_COMBINATION.altKey &&
                (event.key === TOGGLE_KEY_COMBINATION.key || event.key === TOGGLE_KEY_COMBINATION.key.toUpperCase())) {
                event.preventDefault();
                toggleScrollbars();
            }
        });
    };

    // Initialize the script
    scrollbarsHidden = localStorage.getItem('scrollbarsHidden') === 'true';
    if (scrollbarsHidden) {
        injectCSS(scrollbarHiderCSS);
    }
    addToggleListener();
})();