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.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

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

(I already have a user script manager, let me install it!)

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.

(I already have a user style manager, let me install it!)

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ć.
})();