Hide Cursor While Typing

Automatically hides the cursor while typing and shows it when you stop or move the mouse

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

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

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

// ==UserScript==
// @name         Hide Cursor While Typing
// @namespace    http://tampermonkey.net/
// @version      1.0a
// @description  Automatically hides the cursor while typing and shows it when you stop or move the mouse
// @author       You
// @match        *://*/*
// @grant        none
// @run-at       document-start
// ==/UserScript==

(function() {
    'use strict';

    // Configuration
    const HIDE_DELAY = 0; // Hide cursor immediately when typing starts
    const SHOW_DELAY = 1000; // Show cursor 1 second after typing stops (in milliseconds)

    let typingTimer = null;
    let isTyping = false;

    // Create and inject style element for cursor hiding
    const style = document.createElement('style');
    style.id = 'hide-cursor-while-typing-style';
    style.textContent = `
        body.hide-cursor-typing,
        body.hide-cursor-typing * {
            cursor: none !important;
        }
    `;

    // Inject style as early as possible
    const injectStyle = () => {
        if (!document.head) {
            // If head doesn't exist yet, wait a bit
            setTimeout(injectStyle, 10);
            return;
        }
        if (!document.getElementById('hide-cursor-while-typing-style')) {
            document.head.appendChild(style);
        }
    };

    injectStyle();

    /**
     * Hides the cursor by adding a CSS class to the body
     */
    const hideCursor = () => {
        if (!isTyping) {
            document.body.classList.add('hide-cursor-typing');
            isTyping = true;
        }
    };

    /**
     * Shows the cursor by removing the CSS class from the body
     */
    const showCursor = () => {
        if (isTyping) {
            document.body.classList.remove('hide-cursor-typing');
            isTyping = false;
        }
    };

    /**
     * Handles keyboard events - hides cursor and sets timer to show it later
     * @param {KeyboardEvent} e - The keyboard event
     */
    const handleKeyPress = (e) => {
        // Ignore modifier keys alone (Shift, Ctrl, Alt, Meta)
        if (['Shift', 'Control', 'Alt', 'Meta'].includes(e.key)) {
            return;
        }

        // Hide cursor immediately when typing
        hideCursor();

        // Clear existing timer
        if (typingTimer) {
            clearTimeout(typingTimer);
        }

        // Set new timer to show cursor after user stops typing
        typingTimer = setTimeout(() => {
            showCursor();
        }, SHOW_DELAY);
    };

    /**
     * Handles mouse movement - shows cursor immediately
     */
    const handleMouseMove = () => {
        // Clear the typing timer if mouse moves
        if (typingTimer) {
            clearTimeout(typingTimer);
            typingTimer = null;
        }
        // Show cursor immediately on mouse movement
        showCursor();
    };

    // Attach event listeners
    document.addEventListener('keydown', handleKeyPress, true);
    document.addEventListener('mousemove', handleMouseMove, true);

    // Cleanup on page unload (good practice)
    window.addEventListener('beforeunload', () => {
        if (typingTimer) {
            clearTimeout(typingTimer);
        }
        showCursor();
    });

    console.log('[Hide Cursor While Typing] Userscript loaded successfully');
})();