DeepSeek Native Setter Injector

Listens for postMessage events on chat.deepseek.com and logs them

נכון ליום 02-08-2025. ראה הגרסה האחרונה.

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.

(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        DeepSeek Native Setter Injector
// @description  Listens for postMessage events on chat.deepseek.com and logs them
// @match       https://chat.deepseek.com/*
// @version 0.0.1.20250802212301
// @namespace https://greasyfork.org/users/1435046
// ==/UserScript==

(function () {
  'use strict';

  // Cache the native setter for HTMLTextAreaElement.value
  const valueSetter = Object.getOwnPropertyDescriptor(
    HTMLTextAreaElement.prototype, 'value'
  ).set;

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

    // find all primary filled buttons
    const buttons = document.querySelectorAll(
      'div[role="button"].ds-button--primary.ds-button--filled'
    );

    if (event.data && event.data.type === 'searchButtonClicked') {

      // click the one whose visible label is “Search”
      for (const btn of buttons) {
        if (btn.textContent.trim() === 'Search') {
          btn.click();
          break;
        }
      }
      return;
    }

    if (event.data && event.data.type === 'reasonButtonClicked') {

      // click the one whose visible label is “DeepThink (R1)”
      for (const btn of buttons) {
        if (btn.textContent.trim() === 'DeepThink (R1)') {
          btn.click();
          break;
        }
      }
      return;
    }

    if (event.data?.type === 'newChatButtonClicked') {
      document.querySelector('svg path[d^="M9.10999"]').closest('div').click();
      return;
    }

    let chatMessageInput = document.querySelector('div:has(> div > div > div > div > textarea[id="chat-input"])');
    //if event data type is defaultChatMessageInputDisplay
    if (event.data?.type === 'defaultChatMessageInputDisplay') {
      console.log('default');
      if (chatMessageInput) {

        chatMessageInput.style.removeProperty('display');

        //return
        return;
      }
    }

    if (event.data?.type === 'customizeChatMessageInputDisplay') {
      console.log('customize');
      if (chatMessageInput) {

        chatMessageInput.style.display = 'none';

        //return
        return;
      }
    }

    if (event.data.type !== 'prompt') return;

    const textarea = document.getElementById('chat-input');
    if (!textarea) return;

    // 1. Update both DOM and React state without shifting focus
    valueSetter.call(textarea, event.data.content);

    // 2. Notify React/Vue/etc. of the change
    textarea.dispatchEvent(new InputEvent('input', { bubbles: true }));

    // 3. Click the send button if enabled and matching the icon path
    const sendBtn = document.querySelector('div[role="button"][aria-disabled="false"]');
    if (
      sendBtn &&
      sendBtn.querySelector('path[d^="M7 16c-.595 0-1.077-.462-1.077"]')
    ) {
      sendBtn.click();
    }

  });
})();