DeepSeek Native Setter Injector

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

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

  1. // ==UserScript==
  2. // @name DeepSeek Native Setter Injector
  3. // @description Listens for postMessage events on chat.deepseek.com and logs them
  4. // @match https://chat.deepseek.com/*
  5. // @version 0.0.1.20250514132629
  6. // @namespace https://greasyfork.org/users/1435046
  7. // ==/UserScript==
  8.  
  9. (function () {
  10. 'use strict';
  11.  
  12. // Cache the native setter for HTMLTextAreaElement.value
  13. const valueSetter = Object.getOwnPropertyDescriptor(
  14. HTMLTextAreaElement.prototype, 'value'
  15. ).set;
  16.  
  17. window.addEventListener('message', event => {
  18. const message = event.data;
  19.  
  20. if (message && message.type === 'searchButtonClicked') {
  21. // find all primary filled buttons
  22. const buttons = document.querySelectorAll(
  23. 'div[role="button"].ds-button--primary.ds-button--filled'
  24. );
  25. // click the one whose visible label is “Search”
  26. for (const btn of buttons) {
  27. if (btn.textContent.trim() === 'Search') {
  28. btn.click();
  29. break;
  30. }
  31. }
  32. return;
  33. }
  34.  
  35. if (message && message.type === 'reasonButtonClicked') {
  36. // find all primary filled buttons
  37. const buttons = document.querySelectorAll(
  38. 'div[role="button"].ds-button--primary.ds-button--filled'
  39. );
  40. // click the one whose visible label is “DeepThink (R1)”
  41. for (const btn of buttons) {
  42. if (btn.textContent.trim() === 'DeepThink (R1)') {
  43. btn.click();
  44. break;
  45. }
  46. }
  47. return;
  48. }
  49.  
  50. const textarea = document.getElementById('chat-input');
  51. if (!textarea) return;
  52.  
  53. // 1. Update both DOM and React state without shifting focus
  54. valueSetter.call(textarea, message);
  55.  
  56. // 2. Notify React/Vue/etc. of the change
  57. textarea.dispatchEvent(new InputEvent('input', { bubbles: true }));
  58.  
  59. // 3. Click the send button if enabled
  60. const sendBtn = document.querySelector('div[role="button"][aria-disabled="false"]');
  61. if (sendBtn) sendBtn.click();
  62. });
  63. })();