Google Mail Signature HTML Code Editor

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

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        Google Mail Signature HTML Code Editor
// @namespace   https://greasyfork.org/en/users/85671-jcunews
// @version     1.0.1
// @license     AGPL v3
// @author      jcunews
// @description Add an inputbox for editing the HTML code of message signature on General tab of the settings page
// @match       https://mail.google.com/mail/*
// @grant       none
// ==/UserScript==

((rxBlockTags, timerCheck, eleSigContainer, eleSigHtml, sigHtmlChanged, prevFormatted) => {
  function check(e) {
    if (eleSigContainer = document.querySelector('.Ia .editable[aria-label="Signature"]')) {
      if (!document.getElementById("sigHtml")) {
        if (e = eleSigContainer.closest('.Ia')) e.style.height = "auto";
        eleSigContainer.insertAdjacentHTML("beforebegin", `\
<div style="padding:0 .3em;background:#bdd;font-weight:bold">HTML Code</div>
<textarea id="sigHtml" style="box-sizing:border-box;width:100%;min-height:8em;resize:vertical;font:10pt/1.5em monospace"></textarea>
<div style="padding:0 .3em;background:#bdd;font-weight:bold">Formatted Content</div>`);
        (eleSigHtml = document.getElementById("sigHtml")).oninput = () => {
          sigHtmlChanged = true;
          eleSigContainer.innerHTML = eleSigHtml.value
        };
        prevFormatted = ""
      }
      if (sigHtmlChanged) {
        sigHtmlChanged = false
      } else if (eleSigContainer.innerHTML !== prevFormatted) {
        eleSigHtml.value = prevFormatted = eleSigContainer.innerHTML.replace(rxBlockTags, "$1\n$2")
      }
    } else eleSigContainer = eleSigHtml = null
  }
  rxBlockTags = new RegExp("(>)[ \\t]*?(<(?:\
aside|br|blockquote|body|caption|center|col(?:group)?|datalist|dd|details|dialog|di[rv]|\
fieldset|figcaption|figure|footer|form|frame(?:set)?|h[1-6r]|head(?:er)?|html|\
main|menu|nav|ol|option|p(?:re)|section|summary|table|td|tbody|tfoot|th(?:ead)?|tr|ul\
)>)", "gi");
  (new MutationObserver(recs => {
    clearTimeout(timerCheck);
    timerCheck = setTimeout(check, 100);
    timerCheck = 0
  })).observe(document, {childList: true, subtree: true})
})()