ChatGPT Cmd+Enter Send and Enter New Line

Send messages on ChatGPT with Cmd+Enter, use Enter for new lines

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!)

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!)

// ==UserScript==
// @name         ChatGPT Cmd+Enter Send and Enter New Line
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  Send messages on ChatGPT with Cmd+Enter, use Enter for new lines
// @author       15d23
// @match        https://chat.openai.com/*
// @grant        none
// @license      GPL
// @created      2023-04-17
// @updated      2023-05-01
// ==/UserScript==

(function () {
    'use strict';

    function handleKeyPress(event) {
        const inputBox = document.querySelector('textarea');
        if (event.key === 'Enter' && !event.metaKey && inputBox) {
            event.stopPropagation();
        }
    }

    function overrideEnterKey() {
        const inputBox = document.querySelector('textarea');
        if (inputBox) {
            inputBox.removeEventListener('keydown', handleKeyPress, true);
            inputBox.addEventListener('keydown', handleKeyPress, true);
        }
    }

    const observer = new MutationObserver(overrideEnterKey);
    observer.observe(document, { childList: true, subtree: true });
})();