ChatGPT Message Queue

Queue messages when ChatGPT is still composing responses

Ekde 2025/03/18. Vidu La ĝisdata versio.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==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.20250318133653
// @namespace https://greasyfork.org/users/1435046
// ==/UserScript==

(function() {
    'use strict';
    
    let queueCount = 0;
    let queueObserver;
    let queueDisplay;

    function createQueueDisplay() {
        queueDisplay = document.createElement('div');
        queueDisplay.style.position = 'fixed';
        queueDisplay.style.bottom = '100px';
        queueDisplay.style.right = '20px';
        queueDisplay.style.background = 'rgba(0,0,0,0.7)';
        queueDisplay.style.color = 'white';
        queueDisplay.style.padding = '5px 10px';
        queueDisplay.style.borderRadius = '4px';
        queueDisplay.style.display = 'flex';
        queueDisplay.style.gap = '8px';
        queueDisplay.style.alignItems = 'center';

        const text = document.createElement('span');
        text.textContent = `Queue: ${queueCount}`;
        
        const clearBtn = document.createElement('button');
        clearBtn.textContent = '×';
        clearBtn.style.cursor = 'pointer';
        clearBtn.style.background = 'transparent';
        clearBtn.style.border = 'none';
        clearBtn.style.color = 'inherit';
        clearBtn.style.fontSize = '18px';
        clearBtn.style.padding = '0 4px';
        clearBtn.onclick = () => {
            queueCount = 0;
            text.textContent = `Queue: ${queueCount}`;
        };

        queueDisplay.appendChild(text);
        queueDisplay.appendChild(clearBtn);
        document.body.appendChild(queueDisplay);
    }

    function handleSendButton() {
        const sendButton = document.querySelector('[data-testid="send-button"]');
        if (sendButton && queueCount > 0) {
            sendButton.click();
            queueCount--;
            queueDisplay.querySelector('span').textContent = `Queue: ${queueCount}`;
        }
    }

    const textareaObserver = new MutationObserver(() => {
        const textarea = document.getElementById('prompt-textarea');
        if (textarea && !textarea.dataset.queueEnabled) {
            textarea.dataset.queueEnabled = 'true';
            
            textarea.addEventListener('keyup', (e) => {
                if (e.key === 'Enter' && !e.shiftKey && !e.ctrlKey && !e.altKey && !e.metaKey) {
                    // Changed to check for streaming class
                    if (document.querySelector('.result-streaming')) {
                        e.preventDefault();
                        queueCount++;
                        queueDisplay.querySelector('span').textContent = `Queue: ${queueCount}`;
                        
                        if (!queueObserver) {
                            queueObserver = new MutationObserver(handleSendButton);
                            queueObserver.observe(document.body, {
                                childList: true,
                                subtree: true
                            });
                        }
                    }
                }
            });
        }
    });

    // Initialize
    createQueueDisplay();
    textareaObserver.observe(document.body, {
        childList: true,
        subtree: true
    });
})();