Skip to content

Instantly share code, notes, and snippets.

@pjeby
Created April 13, 2025 21:24
Show Gist options
  • Save pjeby/9bb8e8b026a3e2ec5f5b0e6d56798bc5 to your computer and use it in GitHub Desktop.
Save pjeby/9bb8e8b026a3e2ec5f5b0e6d56798bc5 to your computer and use it in GitHub Desktop.
ChatGPT Multi-line prompts by default - A user script for Tampermonkey et al (drafted by ChatGPT and fixed to actually work by me)
// ==UserScript==
// @name ChatGPT Multiline Prompt Helper
// @namespace http://tampermonkey.net/
// @version 1.2
// @description Use Enter for newline, Ctrl+Enter to submit
// @match https://chat.openai.com/*
// @match https://chatgpt.com/c/*
// @grant none
// ==/UserScript==
(function () {
'use strict';
const bindHandler = () => {
const inputDiv = document.querySelector('#prompt-textarea[contenteditable="true"]');
if (!inputDiv || inputDiv.dataset.bound === "true") {
return;
}
inputDiv.dataset.bound = "true";
inputDiv.addEventListener('keydown', function (e) {
if (e.key === 'Enter' && !e.ctrlKey && !e.metaKey && !e.shiftKey) {
e.preventDefault();
e.stopPropagation();
const shiftEnter = new KeyboardEvent('keydown', {
key: 'Enter',
code: 'Enter',
keyCode: 13,
which: 13,
bubbles: true,
cancelable: true,
shiftKey: true
});
inputDiv.dispatchEvent(shiftEnter);
}
// Ctrl+Enter submits as normal
}, true); // capture = true ensures early interception
observer.disconnect()
};
const observer = new MutationObserver(bindHandler);
observer.observe(document.body, { childList: true, subtree: true });
window.addEventListener('load', bindHandler);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment