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.5
  6. // @match https://discord.com/*
  7. // @namespace https://greasyfork.org/users/1376767
  8. // ==/UserScript==
  9.  
  10. (function() {
  11. 'use strict';
  12.  
  13. let clickInTextbox = false;
  14. document.addEventListener('mousedown', (event) => {
  15. if (event.target.closest('div[role="textbox"], textarea')) {
  16. clickInTextbox = true;
  17. }
  18. });
  19. document.addEventListener('mouseup', (event) => {
  20. setTimeout(() => {
  21. clickInTextbox = false;
  22. }, 100);
  23. });
  24.  
  25. function detectAndRemoveFocus(event) {
  26. const target = event.target;
  27. if (!clickInTextbox && target && target.matches && target.matches('div[role="textbox"], textarea')) {
  28. target.blur();
  29. } else {
  30. clickInTextbox = false;
  31. }
  32. }
  33. document.addEventListener('focus', detectAndRemoveFocus, true);
  34. })();