ChatGPT Message Queue

Queue messages when ChatGPT is still composing responses

Tính đến 18-03-2025. Xem phiên bản mới nhất.

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.

(Tôi đã có Trình quản lý tập lệnh người dùng, hãy cài đặt nó!)

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

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

    function createQueueDisplay() {
        // Create queue display with clear button
        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);
    }

    // Rest of the original script remains unchanged
    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('keydown', (e) => {
                if (e.key === 'Enter' && !e.shiftKey && !e.ctrlKey && !e.altKey && !e.metaKey) {
                    if (document.querySelector('[data-testid="stop-button"]')) {
                        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
    });
})();