Mistral Chat Prompt Injector

Listens for postMessage events and injects them into chat.mistral.ai's input field

As of 21.05.2025. See ბოლო ვერსია.

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 or Violentmonkey 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         Mistral Chat Prompt Injector
// @description  Listens for postMessage events and injects them into chat.mistral.ai's input field
// @match        https://chat.mistral.ai/*
// @run-at       document-idle
// @version 0.0.1.20250521124308
// @namespace https://greasyfork.org/users/1435046
// ==/UserScript==

(function () {
  window.addEventListener('message', event => {

    if (event.data?.type === 'newChatButtonClicked') {
      document.querySelector('button[aria-label="New chat"]').click();
      return;
    }

    if (event.data.type === "prompt" && event.data.content.trim()) {
      const textarea = document.querySelector('textarea[name="message.text"]');
      if (textarea) {
        const nativeInputValueSetter = Object.getOwnPropertyDescriptor(window.HTMLTextAreaElement.prototype, "value").set;
        nativeInputValueSetter.call(textarea, event.data.content); // Set like the browser would

        // Now trigger a React-compatible InputEvent
        const inputEvent = new InputEvent('input', {
          bubbles: true,
          cancelable: true,
          inputType: 'insertText',
          data: event.data.content,
        });

        textarea.dispatchEvent(inputEvent);

        document.querySelector('button[type="submit"]').click();
      }
    }         // ← close the `if (e.data.type…` block
  });         // ← close addEventListener(…)
})();