Discord Kill Autofocus

Prevent chat auto focus on Discord desktop and mobile.

  1. // ==UserScript==
  2. // @name Discord Kill Autofocus
  3. // @description Prevent chat auto focus on Discord desktop and mobile.
  4. // @author C89sd
  5. // @version 0.6
  6. // @match https://discord.com/*
  7. // @namespace https://greasyfork.org/users/1376767
  8. // @noframes
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14. let clickInTextbox = false;
  15. document.addEventListener('mousedown', (event) => {
  16. if (event.target.closest('div[role="textbox"], textarea')) {
  17. clickInTextbox = true;
  18. }
  19. });
  20. document.addEventListener('mouseup', (event) => {
  21. setTimeout(() => {
  22. clickInTextbox = false;
  23. }, 100);
  24. });
  25.  
  26. function detectAndRemoveFocus(event) {
  27. const target = event.target;
  28. if (!clickInTextbox && target && target.matches && target.matches('div[role="textbox"], textarea')) {
  29. target.blur();
  30. } else {
  31. clickInTextbox = false;
  32. }
  33. }
  34. document.addEventListener('focus', detectAndRemoveFocus, true);
  35. })();