🏠 

ChatGPT: Fix Enter Key on Small Sizes

Userscript changes the mobile interface by restoring Ctrl+Enter or Enter as Submit, even when opening small, thin windows in the desktop environment.


Install this script?

Ask a question, post a review, or report the script.
Author
Vladan Čolović
Daily installs
0
Total installs
176
Ratings
0 0 1
Version
1.1
Created
2023-06-03
Updated
2023-06-03
Size
2.87 KB
License
MIT
Applies to

Short explanation for those who do not have time for a detailed one - in small window sizes ChatGPT works the same as on mobile, where the Enter key is disabled. I've set the same default in responsive mode so that Enter = ignore, as OpenAI intended, but enabled the use of the Ctrl+Enter shortcut for Submit as an alternative. You can also force the use of Enter as Submit by changing just one variable. I've also added a new shortcut, Ctrl+Shift+Enter, to start a new chat.

The problem it solves

This userscript is for you if, like me, you prefer to move your browser window to the edge of the screen, to the side, and continue working in the central window of another application. If you do this often, you'll be aware that the ChatGPT interface in this mobile version of the site does not respond to Enter as a way of submitting queries. I believe the reason for this is something to do with mobile phones and is justified, but for those who use it this way on a desktop, it presents a serious annoyance.

Therefore, I've written a small userscript to change the behaviour of the Enter key in the mobile responsive view. It's also possible to customise the script. It's written to be lightweight and not to tax the computer's resources. I've seen several user scripts that set global "mutation observers" to solve some problems, but introduce a much worse one in the form of significant computer resource usage.

Core functions

Below are the core features.

A bit of configuration

I deliberately refrained from creating an interface to keep things as lightweight as possible. At the beginning of the source code, there are a few variables that you may need to adjust if something changes in the structure of the ChatGPT site in the future.

The first two variables are essentially CSS selectors that determine which element on the page will receive a "mouse click" when you press the Enter key. The selSubmit variable points to the submit button, while selNewChat points to the new chat button. You'll notice that selNewChat has two CSS selectors, because one is for the desktop version, while the button in the responsive version is in a completely different structural position.

Making the default Enter key work in smaller sizes

I want to explain why I chose not to make Enter perform a "send" operation by default, thus preserving the behaviour intended by the OpenAI developers. They probably considered their decision carefully, and I believe it has merit, so I decided to keep that behaviour. I simply added the `Ctrl+Enter' capability.

However, if this bothers you and you want Enter to continue to work as "Send" in the mobile version, I've already explained the forceSubmitOnEnter' variable, which needs to be changed totrue`.

That's about it. More time spent describing than coding.