DeepSeek Native Setter Injector

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

目前为 2025-05-11 提交的版本,查看 最新版本

// ==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.20250511172250
// @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 => {
        const message = event.data;
        const ta = document.getElementById('chat-input');
        if (!ta) return;

        // 1. Update both DOM and React state without shifting focus
        valueSetter.call(ta, message);

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

        // 3. Click the send button if enabled
        const sendBtn = document.querySelector('div[role="button"][aria-disabled="false"]');
        if (sendBtn) sendBtn.click();
    });
})();