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)

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==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();
        }
    });
})();