为ChatGPT添加发送快捷键:Ctrl+Enter

Adds Ctrl+Enter shortcut for sending messages in OpenAI chat

// ==UserScript==
// @name         为ChatGPT添加发送快捷键:Ctrl+Enter
// @version      1.1
// @description  Adds Ctrl+Enter shortcut for sending messages in OpenAI chat
// @match        https://chat.openai.com/*
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        none
// @author       ChopChopsticks
// @namespace https://greasyfork.org/users/1052311
// ==/UserScript==

(function() {
    'use strict';

    // Get the send button
    const sendButton = document.querySelector('[data-testid="send-button"]');

    // Add event listener for keydown events on the chat input field
    document.querySelector('[data-testid="chat-input"]').addEventListener('keydown', function(event) {
        // Check if Ctrl+Enter is pressed
        if (event.ctrlKey && event.keyCode === 13) {
            // If so, prevent the default action of the Enter key (adding a newline)
            event.preventDefault();
            // Simulate a click on the send button
            sendButton.click();
        }
    });
})();