Emerald Chat Auto-Focus

Simple auto-focus for the chat bar.

  1. // ==UserScript==
  2. // @name Emerald Chat Auto-Focus
  3. // @namespace https://greasyfork.org/en/users/1159227
  4. // @version 1.0
  5. // @description Simple auto-focus for the chat bar.
  6. // @author Ritsu
  7. // @license MIT
  8. // @match *://emeraldchat.com/app
  9. // @icon https://www.google.com/s2/favicons?sz=64&domain=emeraldchat.com
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15. window.onload = function() {
  16. const container = document.getElementById("container");
  17. const mutationObserver = new MutationObserver(function() {
  18. var chatInput = document.getElementById("room-input");
  19. if (chatInput !== null) {
  20. document.body.addEventListener("keydown", function() {
  21. var UIs1 = document.querySelector("#ui-hatch > *");
  22. var UIs2 = document.querySelector("#ui-hatch-2 > *");
  23. var interestsField = document.getElementById("interests");
  24. if (!UIs1 && !UIs2 && !interestsField) {
  25. chatInput.focus();
  26. };
  27. });
  28. };
  29. });
  30. mutationObserver.observe(container, {childList: true, subtree: true, attributes: false});
  31. };
  32. })();