HTML for Gmail

Send HTML Formatted Emails With Gmail

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name          HTML for Gmail
// @namespace     https://github.com/DeathHackz/HTML-for-Gmail
// @version       1.0.0
// @description   Send HTML Formatted Emails With Gmail
// @match         https://mail.google.com/*
// @author        DeathHackz
// @copyright     2019 DeathHackz
// @license       MIT
// @homepageURL   https://deathhackz.github.io/HTML-for-Gmail
// @supportURL    https://github.com/DeathHackz/HTML-for-Gmail/issues
// @icon          https://raw.githubusercontent.com/DeathHackz/HTML-for-Gmail/master/iocn.png
// @run-at        document-body
// ==/UserScript==

document.addEventListener(
  'click',
  event => {
    if (document.querySelectorAll('td.a8X.gU')) {
      const buttonHtml = `<div class="wG J-Z-I" id="convertText" data-tooltip="Convert to HTML" aria-label="Convert to HTML" tabindex="1" role="button" aria-pressed="false" style="-moz-user-select: none;">
      <div class="J-J5-Ji J-Z-I-Kv-H" style="-moz-user-select: none;">
        <div class="J-J5-Ji J-Z-I-J6-H" style="-moz-user-select: none;">
          <div class="aA8 aaA aMZ" style="-moz-user-select: none; background-image:url('https://www.gstatic.com/images/icons/material/system/1x/code_black_20dp.png')">
            <div class="a3I" style="-moz-user-select: none;">
              &nbsp;
            </div>
          </div>
        </div>
      </div>
    </div>`;
      document.querySelectorAll('td.a8X.gU').forEach(element => {
        if (element.childNodes[0].id != 'convertText') {
          element.childNodes[0].insertAdjacentHTML('beforebegin', buttonHtml);
          element.childNodes[0].addEventListener(
            'click',
            event => {
              let editor;
              try {
                editor = element.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[1].childNodes[0].childNodes[0].childNodes[1].childNodes[0].childNodes[0].childNodes[1].childNodes[1].childNodes[0];
              } catch (error) {
                editor = element.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.childNodes[0].childNodes[0].childNodes[0].childNodes[1].childNodes[0].childNodes[0].childNodes[1].childNodes[0].childNodes[0].childNodes[1].childNodes[1].childNodes[0];
              }
              const classListLength = editor.classList.length;
              if (editor.classList[classListLength - 1] != 'HTML') {
                editor.classList.add('HTML');
                element.childNodes[0].dataset.tooltip = 'Convert to Text';
                element.childNodes[0].setAttribute('aria-label', 'Convert to Text');
                element.childNodes[0].childNodes[1].childNodes[1].childNodes[1].style.backgroundImage = 'url("https://www.gstatic.com/images/icons/material/system/1x/title_black_20dp.png")';
                const rawText = editor.innerText;
                editor.innerHTML = rawText;
              } else {
                editor.classList.remove('HTML');
                element.childNodes[0].dataset.tooltip = 'Convert to HTML';
                element.childNodes[0].setAttribute('aria-label', 'Convert to HTML');
                element.childNodes[0].childNodes[1].childNodes[1].childNodes[1].style.backgroundImage = 'url("https://www.gstatic.com/images/icons/material/system/1x/code_black_20dp.png")';
                const htmlText = editor.innerHTML;
                editor.innerText = htmlText;
              }
            },
            false
          );
        }
      });
    }
  },
  false
);