ChatGPT Focus Guard

Prevent ChatGPT from auto-focusing its composer except when you type yourself

Від 12.05.2025. Дивіться остання версія.

// ==UserScript==
// @name         ChatGPT Focus Guard
// @description  Prevent ChatGPT from auto-focusing its composer except when you type yourself
// @match        https://chatgpt.com/*
// @version 0.0.1.20250512161108
// @namespace https://greasyfork.org/users/1435046
// ==/UserScript==

(function() {
    'use strict';

    // 1. Keep the native focus method
    const nativeFocus = HTMLElement.prototype.focus;

    // 2. Track genuine user key presses
    let userTyping = false;
    document.addEventListener('keydown', () => {
        userTyping = true;
        // Allow focus only briefly after a keydown
        setTimeout(() => { userTyping = false; }, 100);
    }, true);

    // 3. Override focus globally
    Object.defineProperty(HTMLElement.prototype, 'focus', {
        configurable: true,
        writable: true,
        value: function(...args) {
            // Only let focus happen if the user just typed
            if (userTyping) {
                nativeFocus.apply(this, args);
            }
            // Otherwise, ignore programmatic focus calls
        }
    });
})();