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.

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

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

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

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

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

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

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

Advertisement:

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

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

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

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

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

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

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

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