Google Mail Signature HTML Code Editor

Add an inputbox for editing the HTML code of message signature on General tab of the settings page

  1. // ==UserScript==
  2. // @name Google Mail Signature HTML Code Editor
  3. // @namespace https://greasyfork.org/en/users/85671-jcunews
  4. // @version 1.0.1
  5. // @license AGPL v3
  6. // @author jcunews
  7. // @description Add an inputbox for editing the HTML code of message signature on General tab of the settings page
  8. // @match https://mail.google.com/mail/*
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. ((rxBlockTags, timerCheck, eleSigContainer, eleSigHtml, sigHtmlChanged, prevFormatted) => {
  13. function check(e) {
  14. if (eleSigContainer = document.querySelector('.Ia .editable[aria-label="Signature"]')) {
  15. if (!document.getElementById("sigHtml")) {
  16. if (e = eleSigContainer.closest('.Ia')) e.style.height = "auto";
  17. eleSigContainer.insertAdjacentHTML("beforebegin", `\
  18. <div style="padding:0 .3em;background:#bdd;font-weight:bold">HTML Code</div>
  19. <textarea id="sigHtml" style="box-sizing:border-box;width:100%;min-height:8em;resize:vertical;font:10pt/1.5em monospace"></textarea>
  20. <div style="padding:0 .3em;background:#bdd;font-weight:bold">Formatted Content</div>`);
  21. (eleSigHtml = document.getElementById("sigHtml")).oninput = () => {
  22. sigHtmlChanged = true;
  23. eleSigContainer.innerHTML = eleSigHtml.value
  24. };
  25. prevFormatted = ""
  26. }
  27. if (sigHtmlChanged) {
  28. sigHtmlChanged = false
  29. } else if (eleSigContainer.innerHTML !== prevFormatted) {
  30. eleSigHtml.value = prevFormatted = eleSigContainer.innerHTML.replace(rxBlockTags, "$1\n$2")
  31. }
  32. } else eleSigContainer = eleSigHtml = null
  33. }
  34. rxBlockTags = new RegExp("(>)[ \\t]*?(<(?:\
  35. aside|br|blockquote|body|caption|center|col(?:group)?|datalist|dd|details|dialog|di[rv]|\
  36. fieldset|figcaption|figure|footer|form|frame(?:set)?|h[1-6r]|head(?:er)?|html|\
  37. main|menu|nav|ol|option|p(?:re)|section|summary|table|td|tbody|tfoot|th(?:ead)?|tr|ul\
  38. )>)", "gi");
  39. (new MutationObserver(recs => {
  40. clearTimeout(timerCheck);
  41. timerCheck = setTimeout(check, 100);
  42. timerCheck = 0
  43. })).observe(document, {childList: true, subtree: true})
  44. })()