Trello Markdown Enhancer

Enhance Trello card description markdown rendering with marked.js

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

You will need to install an extension such as Tampermonkey to install this script.

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==UserScript==
// @name         Trello Markdown Enhancer
// @description  Enhance Trello card description markdown rendering with marked.js
// @version      0.1
// @author       Hikerpig
// @copyright    2019 hikerpig (https://openuserjs.org/users/hikerpig)
// @licence      MIT
// @match        https://trello.com/*
// @require      https://cdn.jsdelivr.net/npm/marked/marked.min.js
// @grant        none
// @namespace https://greasyfork.org/users/325041
// ==/UserScript==

;(function() {
  'use strict'

  /**
   * @type MutationObserver
   */
  let mo

  function renderContent(input) {
    let text
    if (typeof input === 'string') {
      text = input
    } else if (input instanceof Element) {
      text = input.innerHTML
    }
    return marked(text)
  }

  // function getRawMarkdown(descEle) {
  //   let rawMarkdown = descEle.innerText
  //   Object.keys(descEle).forEach(k => {
  //     if (descEle[k].unmarkeddown) {
  //       rawMarkdown = descEle[k].unmarkeddown
  //     }
  //   })
  //   return rawMarkdown
  // }

  /**
   * Enhance description rendering with marked.js
   */
  function enhanceDesc() {
    const descEle = document.querySelector('.js-desc')
    if (!descEle) return
    const pEles = descEle.querySelectorAll('p')
    pEles.forEach((pEle) => {
      const text = pEle.innerText
      let hasTable = text.split('\n').some((lineContent) => {
        if (/\|\s*---\s*|/.test(lineContent)) {
          return true
        }
      })
      if (hasTable) {
        const newHTML = marked(text)
        pEle.innerHTML = newHTML
      }
    })
  }

  function bindOverlayEvents() {
    const tabParentEle = document.querySelector('.js-tab-parent')
    if (!mo) {
      mo = new MutationObserver(mutations => {
        // console.log('mutations', mutations)
        let hasCardDetail = false
        mutations.forEach(m => {
          if (m.addedNodes.length) {
            hasCardDetail = true
          }
        })

        if (hasCardDetail) {
          enhanceDesc()
        }
      })
    }
    mo.observe(tabParentEle, { childList: true })
  }

  // window.enhanceDesc = enhanceDesc

  // ---------------- start -----------------------
  enhanceDesc()
  bindOverlayEvents()
})()