Prevent Autofocus on AllenAI, Mistral

Blocks programmatic focus on <textarea> and contenteditable elements

  1. // ==UserScript==
  2. // @name Prevent Autofocus on AllenAI, Mistral
  3. // @description Blocks programmatic focus on <textarea> and contenteditable elements
  4. // @match https://playground.allenai.org/*
  5. // @match https://chat.mistral.ai/*
  6. // @run-at document-start
  7. // @version 0.0.1.20250530182612
  8. // @namespace https://greasyfork.org/users/1435046
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14. // Save original focus
  15. const originalFocus = HTMLElement.prototype.focus;
  16.  
  17. // Override focus globally
  18. Object.defineProperty(HTMLElement.prototype, 'focus', {
  19. configurable: true,
  20. enumerable: true,
  21. writable: true,
  22. value: function(...args) {
  23. // If it's a <textarea> or a contenteditable element, do nothing
  24. if (this.tagName === 'TEXTAREA' || this.isContentEditable) {
  25. return;
  26. }
  27. // Otherwise proceed as normal
  28. return originalFocus.apply(this, args);
  29. }
  30. });
  31. })();