basyura's blog

あしたになったらほんきだす。

ChatGpt : Enter で送信したくない - 20240523

また変わった。fruitjuice とは。

- let ele = document.querySelector("button[data-testid='send-button']")
+ let ele = document.querySelector("button[data-testid='fruitjuice-send-button']")

全体

// ==UserScript==
// @name         ChatGPT
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match        https://chat.openai.com/*
// @match        https://chatgpt.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=chatgpt.com
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    document.body.addEventListener('keydown', function(e) {

        // Enter キー以外は何もしない
        // Mac の vivaldi でのアドレスバー等での予測変換の考慮を karabiner-elements を設定しているため。
        if (e.key != 'Enter' && e.key != ']') {
            return;
        }

        // 送信 (ctrl + enter) じゃない、または変換中はイベント中断
        if (!e.ctrlKey || e.isComposing) {
            e.stopPropagation();
            return;
        }

        // イベント発生元がテキストボックスじゃない場合
        if (e.srcElement.id != "prompt-textarea") {
            return;
        }

        // 送信ボタンをクリック
        let ele = document.querySelector("button[data-testid='fruitjuice-send-button']")
        ele.click();

    }, { capture: true });
})();