DeepSeek Native Setter Injector

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

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

  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.20250515163325
  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.  
  19. // find all primary filled buttons
  20. const buttons = document.querySelectorAll(
  21. 'div[role="button"].ds-button--primary.ds-button--filled'
  22. );
  23.  
  24. if (event.data && event.data.type === 'searchButtonClicked') {
  25.  
  26. // click the one whose visible label is “Search”
  27. for (const btn of buttons) {
  28. if (btn.textContent.trim() === 'Search') {
  29. btn.click();
  30. break;
  31. }
  32. }
  33. return;
  34. }
  35.  
  36. if (event.data && event.data.type === 'reasonButtonClicked') {
  37.  
  38. // click the one whose visible label is “DeepThink (R1)”
  39. for (const btn of buttons) {
  40. if (btn.textContent.trim() === 'DeepThink (R1)') {
  41. btn.click();
  42. break;
  43. }
  44. }
  45. return;
  46. }
  47.  
  48. if (event.data?.type === 'newChatButtonClicked') {
  49. document.querySelector('svg path[d^="M9.10999"]').closest('div').click();
  50. return;
  51. }
  52.  
  53. // Only respond to string messages
  54. if (typeof event.data !== 'string') return;
  55.  
  56. const textarea = document.getElementById('chat-input');
  57. if (!textarea) return;
  58.  
  59. // 1. Update both DOM and React state without shifting focus
  60. valueSetter.call(textarea, event.data);
  61.  
  62. // 2. Notify React/Vue/etc. of the change
  63. textarea.dispatchEvent(new InputEvent('input', { bubbles: true }));
  64.  
  65. // 3. Click the send button if enabled
  66. const sendBtn = document.querySelector('div[role="button"][aria-disabled="false"]');
  67. if (sendBtn) sendBtn.click();
  68. });
  69. })();