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.20250515144837
  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
  50. .querySelector('svg path[d^="M9.10999 27C8.92999"]')
  51. ?.closest('div.ds-icon')
  52. ?.click();
  53. return;
  54. }
  55.  
  56. // Only respond to string messages
  57. if (typeof event.data !== 'string') return;
  58.  
  59. const textarea = document.getElementById('chat-input');
  60. if (!textarea) return;
  61.  
  62. // 1. Update both DOM and React state without shifting focus
  63. valueSetter.call(textarea, event.data);
  64.  
  65. // 2. Notify React/Vue/etc. of the change
  66. textarea.dispatchEvent(new InputEvent('input', { bubbles: true }));
  67.  
  68. // 3. Click the send button if enabled
  69. const sendBtn = document.querySelector('div[role="button"][aria-disabled="false"]');
  70. if (sendBtn) sendBtn.click();
  71. });
  72. })();