Greasy Fork 还支持 简体中文。

ChatGPT No-Focus Injector

Block all auto-focus on chatgpt.com; listen for postMessage and inject+send without stealing focus

目前為 2025-05-12 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name ChatGPT No-Focus Injector
  3. // @description Block all auto-focus on chatgpt.com; listen for postMessage and inject+send without stealing focus
  4. // @match https://chatgpt.com/*
  5. // @run-at document-start
  6. // @version 0.0.1.20250512161945
  7. // @namespace https://greasyfork.org/users/1435046
  8. // ==/UserScript==
  9.  
  10. (function() {
  11. 'use strict';
  12.  
  13. // 1) Block every element’s .focus()
  14. const nativeFocus = HTMLElement.prototype.focus;
  15. HTMLElement.prototype.focus = function() {
  16. // no-op: blocks ChatGPT’s auto-focus entirely
  17. };
  18.  
  19. // 2) Grab the native setter for <textarea>.value
  20. const valueSetter = Object.getOwnPropertyDescriptor(
  21. HTMLTextAreaElement.prototype, 'value'
  22. ).set;
  23.  
  24. // 3) Listen for window.postMessage("your prompt")
  25. window.addEventListener('message', event => {
  26. if (typeof event.data !== 'string') return;
  27. const text = event.data.trim();
  28. if (!text) return;
  29.  
  30. // 4) Find the hidden React <textarea>
  31. const ta = document.querySelector('textarea.text-token-text-primary');
  32. if (!ta) return;
  33.  
  34. // 5) Inject via native setter (no focus needed)
  35. valueSetter.call(ta, text);
  36. ta.dispatchEvent(new InputEvent('input', { bubbles: true }));
  37.  
  38. // 6) Click Send
  39. const sendBtn = document.getElementById('composer-submit-button');
  40. if (sendBtn && !sendBtn.disabled) {
  41. sendBtn.click();
  42. }
  43. });
  44. })();