Greasy Fork

Greasy Fork is available in English.

Mistral Chat Receiver (Fixed)

Paste postMessage prompts into chat.mistral.ai and light up the Send button

当前为 2025-05-20 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==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();
  });
})();