ChatGPT Enter Fix (GPT4)

This Chrome/Safari extension addresses the issue where ChatGPT sends text even when the Enter key is pressed during Japanese conversion.

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

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.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @name       ChatGPT Enter Fix (GPT4)
// @name:ja       ChatGPT Enter Fix (GPT4)
// @namespace    http://tampermonkey.net/
// @description  This Chrome/Safari extension addresses the issue where ChatGPT sends text even when the Enter key is pressed during Japanese conversion.
// @description:ja  ChatGPTにおいて日本語IMEで変換中にEnterを押した時に送信されてしまうの問題を阻止します。 Safariにも対応。
// @version      2.0
// @author       satosh1suzuk1, d-engine
// @match      https://chat.openai.com/chat
// @match      https://chat.openai.com/chat/*
// ==/UserScript==

// wrap in anonymous scope to prevent confliction.
(() => {
  const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
  window.addEventListener("load", ()=> {
    const tryInject = () => {
      const textarea = document.querySelector('textarea[tabindex="0"]');
      if (!textarea) {
        return;
      }
      if(textarea.dataset.isInjected === 'true'){
        return;
      }
      textarea.dataset.isInjected = 'true';

      textarea.addEventListener(
        "keydown",
        (event) => {
          // SafariではisComposingが機能しない。 普通のEnterはkeyCodeが13に、IME確定のEnterは229になる
          if (
            (isSafari && event.keyCode === 229) ||
            (event.key === "Enter" && event.isComposing)
          ) {
            event.target.dataset.isComposing = 'true';
            event.stopPropagation();
          }
        },
        { capture: true }
      );
      textarea.addEventListener(
        "keyup",
        (event) => {
          if (event.key === "Enter" && event.target.dataset.isComposing === 'true') {
              event.stopPropagation();
          }
        },
        { capture: true }
      );
    }
    setInterval(tryInject, 1000);
  }, false);
})();