ChatGPT Focus Prompt Textarea

Automatically focus the prompt input box on chat.openai.com when tabbing back to the browser window.

  1. // ==UserScript==
  2. // @name ChatGPT Focus Prompt Textarea
  3. // @namespace http://jakelevirne.com/
  4. // @version 0.2
  5. // @description Automatically focus the prompt input box on chat.openai.com when tabbing back to the browser window.
  6. // @author jakelevirne
  7. // @match *://chat.openai.com/*
  8. // @match *://chatgpt.com/*
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. // Function to focus the input box
  16. function focusPromptInput() {
  17. // Updated selector for the textarea with the specific id
  18. const inputSelector = 'textarea#prompt-textarea';
  19. const inputBox = document.querySelector(inputSelector);
  20.  
  21. if (inputBox && document.activeElement !== inputBox) {
  22. inputBox.focus();
  23. }
  24. }
  25.  
  26.  
  27. // Listen for the window to gain focus
  28. window.addEventListener('focus', focusPromptInput);
  29.  
  30. })();