AllenAI Playground Auto-Focus

Automatically focuses the input on AllenAI Playground when typing

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         AllenAI Playground Auto-Focus
// @description  Automatically focuses the input on AllenAI Playground when typing
// @match        https://playground.allenai.org/*
// @version 0.0.1.20250501101156
// @namespace https://greasyfork.org/users/1435046
// ==/UserScript==

document.addEventListener('keydown', e => {
    const textarea = document.querySelector('textarea.auto-sized-input');
    const active = document.activeElement;
    
    if (textarea && !/^textarea|input$/i.test(active.tagName) && 
        e.key.length === 1 && /^[\w\s\W]$/.test(e.key) && !e.ctrlKey && !e.metaKey) {
        
        e.preventDefault();
        textarea.focus();
        
        // Insert text at cursor position
        const start = textarea.selectionStart;
        const end = textarea.selectionEnd;
        textarea.setRangeText(e.key, start, end, "end");
        
        // Trigger input events for React state updates
        textarea.dispatchEvent(new Event('input', { bubbles: true }));
        textarea.dispatchEvent(new Event('change', { bubbles: true }));
    }
});