ChatGPT Message Queue

Queue messages when ChatGPT is still composing responses

目前為 2025-03-18 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==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.20250318094033
// @namespace https://greasyfork.org/users/1435046
// ==/UserScript==
(function() {
  'use strict';
  
  let messageQueue = [];
  let queueIndicator = null;
  
  function createQueueIndicator() {
    if (queueIndicator) return;
    
    queueIndicator = document.createElement('div');
    queueIndicator.style.position = 'absolute';
    queueIndicator.style.bottom = '60px';
    queueIndicator.style.right = '20px';
    queueIndicator.style.backgroundColor = '#343541';
    queueIndicator.style.color = 'white';
    queueIndicator.style.padding = '8px 12px';
    queueIndicator.style.borderRadius = '8px';
    queueIndicator.style.fontSize = '14px';
    queueIndicator.style.fontWeight = 'bold';
    queueIndicator.style.zIndex = '1000';
    queueIndicator.style.display = 'none';
    queueIndicator.textContent = 'Queued: 0';
    
    document.body.appendChild(queueIndicator);
  }
  
  function updateQueueDisplay() {
    if (!queueIndicator) createQueueIndicator();
    
    if (messageQueue.length > 0) {
      queueIndicator.textContent = `Queued: ${messageQueue.length}`;
      queueIndicator.style.display = 'block';
    } else {
      queueIndicator.style.display = 'none';
    }
  }
  
  function processQueue() {
    if (messageQueue.length === 0) return;
    
    const textarea = document.getElementById('prompt-textarea');
    if (!textarea) return;
    
    // Wait until ChatGPT is not composing
    if (document.querySelector('[data-testid="stop-button"]')) return;
    
    const message = messageQueue.shift();
    textarea.value = message;
    
    // Trigger input event to ensure ChatGPT recognizes the value
    const inputEvent = new Event('input', { bubbles: true });
    textarea.dispatchEvent(inputEvent);
    
    // Click the send button
    const sendButton = document.querySelector('[data-testid="send-button"]');
    if (sendButton) {
      sendButton.click();
    }
    
    updateQueueDisplay();
  }
  
  // Set up a mutation observer to detect when the textarea is added to the DOM
  const setupObserver = new MutationObserver(() => {
    const textarea = document.getElementById('prompt-textarea');
    if (textarea && !textarea.dataset.queueEnabled) {
      textarea.dataset.queueEnabled = 'true';
      createQueueIndicator();
      
      textarea.addEventListener('keydown', (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();
            e.stopPropagation();
            
            // Add message to queue
            messageQueue.push(textarea.value);
            textarea.value = '';
            updateQueueDisplay();
          }
        }
      });
    }
  });
  
  // Observer to detect when ChatGPT finishes composing
  const composingObserver = new MutationObserver(() => {
    // Process queue when ChatGPT is not composing
    if (!document.querySelector('[data-testid="stop-button"]')) {
      processQueue();
    }
  });
  
  // Start observing
  setupObserver.observe(document.body, { childList: true, subtree: true });
  composingObserver.observe(document.body, { childList: true, subtree: true });
})();