LARS FOCUS KEYBIND

Enables mouse-less navigation in Gemini Chats by implementing a simple keybind, which toggles focus on and off the input field (=> Bound to 'CTRL+SPACE' per default)

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name         LARS FOCUS KEYBIND
// @namespace    http://tampermonkey.net/
// @version      2025-08-23
// @description  Enables mouse-less navigation in Gemini Chats by implementing a simple keybind, which toggles focus on and off the input field (=> Bound to 'CTRL+SPACE' per default)
// @author       larsFyzza, Google Gemini
// @match        https://gemini.google.com/app/*
// @match        https://gemini.google.com/app/
// @icon         https://www.google.com/s2/favicons?sz=64&domain=gemini.google.com
// @run-at       document-idle
// @grant        none
// @license      MIT:
// ==/UserScript==
//
//
//
// Works by calling element.focus() and element.blur().
// Most of this was written by Gemini, which is objectively funny.
// This is my first time publishing code and actually feeling like it's not *completely* unnecessary,
// because I was actually pretty annoyed with having to use my mouse for Gemini. With this: QoL imrpovement
// achieved.
//
//
// Regards,
// LARS!!!!!!!!!
//
//
//                       DEFINE KEYBIND HERE!!!!!
//                   ↙
const KEYBIND = {
    key: ' ',
    ctrlKey: true,
    altKey: false,
    shiftKey: false,
};



(function() {
    'use strict';
    console.log("LARS SCRIPT WURDE GELADEN! ICH WIEDERHOLE, LARS' SCRIPT HAT DEN DOM-TREE INFILTRIERT!!!!")
    function togglePromptFocus() {
        const promptField = document.querySelector('div.ql-editor.textarea[contenteditable="true"]');
        if (promptField) {
            // Check if the prompt field is already the active element
            if (document.activeElement === promptField) {
                // If it is, remove the focus
                promptField.blur();
                console.log("Unfocussed the prompt field.");
            } else {
                // If not, set the focus
                promptField.focus();
                console.log("Focussed the prompt field.");
            }
        } else {
            console.log("Focussable Element not found (Check the script's querySelector).");
        }
    }
    document.addEventListener('keydown', function(event) {
        if (event.key === KEYBIND.key && event.ctrlKey === KEYBIND.ctrlKey && event.altKey === KEYBIND.altKey && event.shiftKey === KEYBIND.shiftKey) {
            event.preventDefault();
            togglePromptFocus();
        }
    });
})();