ChatGPT Disable Autofocus

Completely block all programmatic autofocus on chatgpt.com

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

// ==UserScript==
// @name         ChatGPT Disable Autofocus
// @description  Completely block all programmatic autofocus on chatgpt.com
// @match        https://chatgpt.com/*
// @run-at       document-start
// @version 0.0.1.20250512172001
// @namespace https://greasyforks.org/users/1435046
// ==/UserScript==

(function() {
  'use strict';

  function removeAutofocus(el) {
    if (el.hasAttribute('autofocus')) {
      el.removeAttribute('autofocus');
    }
  }

  // 1. Observe new elements and remove any autofocus attributes immediately
  const observer = new MutationObserver(mutations => {
    for (const { addedNodes } of mutations) {
      for (const node of addedNodes) {
        if (node.nodeType === 1) {
          removeAutofocus(node);
          node.querySelectorAll('[autofocus]').forEach(removeAutofocus);
        }
      }
    }
  });
  observer.observe(document.documentElement, { childList: true, subtree: true });

  // 2. Once initial DOM is ready, strip any remaining autofocus attributes
  document.addEventListener('DOMContentLoaded', () => {
    document.querySelectorAll('[autofocus]').forEach(removeAutofocus);
    observer.disconnect();
  }, { once: true });
})();
长期地址
遇到问题?请前往 GitHub 提 Issues。