Greasy Fork is available in English.
Paste postMessage prompts into chat.mistral.ai and light up the Send button
当前为
// ==UserScript==
// @name Mistral Chat Receiver (Fixed)
// @description Paste postMessage prompts into chat.mistral.ai and light up the Send button
// @match https://chat.mistral.ai/*
// @run-at document-idle
// @version 0.0.1.20250520203002
// @namespace http://greasyfork.icu/users/1435046
// ==/UserScript==
(() => {
window.addEventListener('message', e => {
const { type, content } = e.data;
if (type !== 'prompt' || !content) return;
const ta = document.querySelector('textarea[name="message.text"]');
if (!ta) return;
// 1. Use the native setter so React notices the value change
const nativeSetter = Object.getOwnPropertyDescriptor(
HTMLTextAreaElement.prototype,
'value'
).set;
nativeSetter.call(ta, content);
// 2. Fire the input event so React’s onChange handler runs
ta.dispatchEvent(new InputEvent('input', { bubbles: true }));
// 3. Optionally fire composition events if needed by the editor
ta.dispatchEvent(new CompositionEvent('compositionstart', { bubbles: true }));
ta.dispatchEvent(new CompositionEvent('compositionend', { bubbles: true }));
// 4. Focus the textarea to ensure the Send button becomes active
ta.focus();
// 5. Now the Send button should light up. You can either simulate Enter:
ta.dispatchEvent(new KeyboardEvent('keydown', {
key: 'Enter',
code: 'Enter',
bubbles: true
}));
ta.dispatchEvent(new KeyboardEvent('keyup', {
key: 'Enter',
code: 'Enter',
bubbles: true
}));
// —or— click the button directly:
// const sendBtn = document.querySelector('button[type="submit"]');
// if (sendBtn && !sendBtn.disabled) sendBtn.click();
});
})();