Gemini Enter Change

Zamienia Enter i Shift+Enter w Gemini. Teraz Enter odpowiada za nową linie a shift enter za wysłanie. Jeśli będą jakieś problemy to poproszę poprostu abyście wysłali mi kilka rzeczy jakie macie na stronie czatu gemini a to naprawie.

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

Advertisement:

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.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

Advertisement:

// ==UserScript==
// @name         Gemini Enter Change
// @version      1.0
// @description  Zamienia Enter i Shift+Enter w Gemini. Teraz Enter odpowiada za nową linie a shift enter za wysłanie. Jeśli będą jakieś problemy to poproszę poprostu abyście wysłali mi kilka rzeczy jakie macie na stronie czatu gemini a to naprawie.
// @author       SkyWhy
// @match        https://gemini.google.com/*
// @namespace https://greasyfork.org/users/1616478
// ==/UserScript==

(function() {
    'use strict';

    document.addEventListener('keydown', function(event) {
        const target = event.target;
        if (!target) return;

        const isEditableDiv = target.closest('div.ql-editor[contenteditable="true"], div[role="textbox"][contenteditable="true"]');
        const isTextareaMatch = target.matches && target.matches('textarea[enterkeyhint="send"], textarea[aria-label*="Prompt"], textarea[aria-label*="Wiadomość"], textarea[placeholder*="Message Gemini"], textarea[placeholder*="Zapytaj Gemini"]');

        if (!isEditableDiv && !isTextareaMatch) return;

        const el = isEditableDiv || target;

        if (event.key === 'Enter') {
            if (event.shiftKey) {

                event.preventDefault();
                event.stopImmediatePropagation();

                const sendButton = document.querySelector('button[aria-label*="Send"], button[aria-label*="Wyślij"], button[data-test-id="send-button"]');
                if (sendButton && !sendButton.disabled) {
                    sendButton.click();
                } else {
                    const form = el.closest('form');
                    if (form) {
                        if (typeof form.requestSubmit === 'function') { form.requestSubmit(); } else { form.submit(); }
                    }
                }
            } else {
                event.preventDefault();
                event.stopImmediatePropagation();

                if (isEditableDiv) {
                    el.focus();
                    let success = document.execCommand('insertParagraph', false, null);
                    if (!success) {
                        document.execCommand('insertHTML', false, '<br>');
                    }
                    el.dispatchEvent(new Event('input', { bubbles: true, cancelable: true }));
                } else if (isTextareaMatch) {
                    const start = el.selectionStart;
                    const end = el.selectionEnd;
                    el.value = el.value.substring(0, start) + "\n" + el.value.substring(end);
                    el.selectionStart = el.selectionEnd = start + 1;
                    el.dispatchEvent(new Event('input', { bubbles: true, cancelable: true }));
                }
            }
        }
    }, true); /// <- Pod żadnym pozorem tego nie ruszać, grozi zawaleniem, reszte możecie się bawić.
})();