Greasy Fork is available in English.

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.

Autor
Vladan Čolović
Instalări zilnice
0
Total instalări
126
Rating-uri
0 0 1
Versiune
1.1
Creat
03-06-2023
Actualizat
03-06-2023
Licență
MIT
Se aplică pe

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.

  • The default behaviour implemented by OpenAI is that when the browser window is reduced and the ChatGPT interface switches to mobile mode, nothing is submitted on Enter. This means that Enter, Ctrl+Enter and the like are completely ignored. This extension changes that and enables Enter and Ctrl+Enter as forced enter for the mobile version.

  • Since in the original, Enter doesn't work in a minimised window, and mine does but for Ctrl-Enter, you may want to force Enter to behave normally and the same as on the desktop, but also in a smaller window. If that's the case, and you want it to continue to respond to normal Enter in all window sizes, just set the value of the forceSubmitOnEnter' variable totrue'.

  • The "options" are set by editing the script and modifying a few variables at the top of the file. I did this because I didn't want to bloat the userscript with interfaces for just a handful of options. I'm pretty sure only people who aren't computer novices use userscripts.

  • My userscript doesn't run a mutation observer on the whole document, like one alternative I considered before writing my code. In this way I've avoided drastically slowing down the computer.

  • If another extension maps some key combination to Enter, my script won't "ruin" it or overwrite and delete it. If you dislike the option of Ctrl+Shift+Enter doing "New Page", the way to disable this is to simply enter a nonsense value in selNewChat.

  • I assume that most users are able to adapt the script to changes that are likely to happen within the OpenAI page. In this case, even if I do not update anything, all you need to do is adjust the variables and set to new CSS selectors.

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.