ChatGPT Message Queue

Queue messages when ChatGPT is still composing responses

Versione datata 17/03/2025. Vedi la nuova versione l'ultima versione.

// ==UserScript==
// @name        ChatGPT Message Queue
// @match       https://chat.openai.com/*
// @match https://chatgpt.com/*
// @description Queue messages when ChatGPT is still composing responses
// @version 0.0.1.20250317193005
// @namespace https://gf.zukizuki.org/users/1435046
// ==/UserScript==

(function() {
  'use strict';
  
  // Set up a mutation observer to detect when the text area is added to the DOM
  const observer = new MutationObserver(() => {
    const textarea = document.getElementById('prompt-textarea');
    if (textarea && !textarea.dataset.queueEnabled) {
      textarea.dataset.queueEnabled = 'true';
      
      textarea.addEventListener('keydown', async (e) => {
        // Check if Enter pressed without modifiers
        if (e.key === 'Enter' && !e.shiftKey && !e.ctrlKey && !e.altKey && !e.metaKey) {
          // Check if ChatGPT is composing (stop button exists)
          if (document.querySelector('[data-testid="stop-button"]')) {
            e.preventDefault();
            
            // Wait for send button to appear
            const waitForSend = setInterval(() => {
              const sendButton = document.querySelector('[data-testid="send-button"]');
              if (sendButton) {
                clearInterval(waitForSend);
                sendButton.click();
              }
            }, 100);
          }
        }
      });
    }
  });
  
  // Start observing
  observer.observe(document.body, { childList: true, subtree: true });
})();