Queue messages when ChatGPT is still composing responses
当前为
// ==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 });
})();