<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>Tools Code</title>
    <link>https://writee.org/tools-code/</link>
    <description></description>
    <pubDate>Tue, 14 Jul 2026 06:08:10 +0000</pubDate>
    <item>
      <title>扒公众号文章的Console代码</title>
      <link>https://writee.org/tools-code/ba-gong-zhong-hao-wen-zhang-de-consoledai-ma</link>
      <description>&lt;![CDATA[  (function() {&#xA;    const el = document.querySelector(&#39;#jscontent&#39;).cloneNode(true);&#xA;&#xA;    // 删除行号&#xA;    el.querySelectorAll(&#39;.code-snippetline-index&#39;).forEach(u =  u.remove());&#xA;&#xA;    // 代码块替换为占位标记&#xA;    el.querySelectorAll(&#39;section.code-snippetfix&#39;).forEach(sec =  {&#xA;      const pre = sec.querySelector(&#39;pre&#39;);&#xA;      if (!pre) return;&#xA;      const lang = pre.getAttribute(&#39;data-lang&#39;) || &#39;&#39;;&#xA;      const lines = [...pre.querySelectorAll(&#39;code&#39;)].map(c =  c.textContent);&#xA;      const ph = document.createElement(&#39;div&#39;);&#xA;      ph.setAttribute(&#39;data-md-code&#39;, lang);&#xA;      ph.textContent = lines.join(&#39;\n&#39;);&#xA;      sec.replaceWith(ph);&#xA;    });&#xA;&#xA;    function convert(node) {&#xA;      if (node.nodeType === Node.TEXTNODE) {&#xA;        return node.textContent;&#xA;      }&#xA;      if (node.nodeType !== Node.ELEMENT_NODE) return &#39;&#39;;&#xA;&#xA;      const tag = node.tagName.toLowerCase();&#xA;      if (tag === &#39;script&#39; || tag === &#39;style&#39;) return &#39;&#39;;&#xA;&#xA;      // 代码块占位&#xA;      if (node.hasAttribute(&#39;data-md-code&#39;)) {&#xA;        const lang = node.getAttribute(&#39;data-md-code&#39;);&#xA;        return &#39;\n\n      }&#xA;&#xA;      const inner = [...node.childNodes].map(convert).join(&#39;&#39;);&#xA;      const text = inner.trim();&#xA;&#xA;      switch (tag) {&#xA;        case &#39;p&#39;:&#xA;        case &#39;div&#39;:&#xA;          return &#39;\n\n&#39; + text + &#39;\n\n&#39;;&#xA;        case &#39;br&#39;:&#xA;          return &#39;\n&#39;;&#xA;        case &#39;strong&#39;:&#xA;        case &#39;b&#39;:&#xA;          return text ? &#39;&#39; + text + &#39;&#39; : &#39;&#39;;&#xA;        case &#39;em&#39;:&#xA;        case &#39;i&#39;:&#xA;          return text ? &#39;&#39; + text + &#39;&#39; : &#39;&#39;;&#xA;        case &#39;code&#39;:&#xA;          return &#39;&#39; + text + &#39;&#39;;&#xA;        case &#39;h1&#39;: return &#39;\n\n# &#39; + text + &#39;\n\n&#39;;&#xA;        case &#39;h2&#39;: return &#39;\n\n## &#39; + text + &#39;\n\n&#39;;&#xA;        case &#39;h3&#39;: return &#39;\n\n### &#39; + text + &#39;\n\n&#39;;&#xA;        case &#39;h4&#39;: return &#39;\n\n#### &#39; + text + &#39;\n\n&#39;;&#xA;        case &#39;h5&#39;: return &#39;\n\n##### &#39; + text + &#39;\n\n&#39;;&#xA;        case &#39;h6&#39;: return &#39;\n\n###### &#39; + text + &#39;\n\n&#39;;&#xA;        case &#39;blockquote&#39;:&#xA;          return &#39;\n\n&#39; + text.split(&#39;\n&#39;).map(l =  &#39;  &#39; + l).join(&#39;\n&#39;) + &#39;\n\n&#39;;&#xA;        case &#39;ul&#39;:&#xA;        case &#39;ol&#39;:&#xA;          return &#39;\n\n&#39; + inner + &#39;\n&#39;;&#xA;        case &#39;li&#39;: {&#xA;          const p = node.parentElement;&#xA;          if (p &amp;&amp; p.tagName.toLowerCase() === &#39;ol&#39;) {&#xA;            const i = [...p.children].indexOf(node) + 1;&#xA;            return i + &#39;. &#39; + text + &#39;\n&#39;;&#xA;          }&#xA;          return &#39;- &#39; + text + &#39;\n&#39;;&#xA;        }&#xA;        case &#39;a&#39;: {&#xA;          const href = node.getAttribute(&#39;href&#39;) || &#39;&#39;;&#xA;          return &#39;&#39; + text + &#39;&#39;;&#xA;        }&#xA;        case &#39;img&#39;: {&#xA;          const src = node.getAttribute(&#39;data-src&#39;) || node.getAttribute(&#39;src&#39;) || &#39;&#39;;&#xA;          const alt = node.getAttribute(&#39;alt&#39;) || &#39;&#39;;&#xA;          return &#39;\n\n&#39; + alt + &#39;\n\n&#39;;&#xA;        }&#xA;        case &#39;hr&#39;:&#xA;          return &#39;\n\n---\n\n&#39;;&#xA;        default:&#xA;          return inner;&#xA;      }&#xA;    }&#xA;&#xA;    let md = convert(el)&#xA;      .replace(/\n{3,}/g, &#39;\n\n&#39;)&#xA;      .trim();&#xA;&#xA;    copy(md);&#xA;    console.log(&#39;已复制到剪贴板，共 &#39; + md.length + &#39; 字符&#39;);&#xA;  })();&#xA;`]]&gt;</description>
      <content:encoded><![CDATA[<pre><code>  (function() {
    const el = document.querySelector(&#39;#js_content&#39;).cloneNode(true);

    // 删除行号
    el.querySelectorAll(&#39;.code-snippet__line-index&#39;).forEach(u =&gt; u.remove());

    // 代码块替换为占位标记
    el.querySelectorAll(&#39;section.code-snippet__fix&#39;).forEach(sec =&gt; {
      const pre = sec.querySelector(&#39;pre&#39;);
      if (!pre) return;
      const lang = pre.getAttribute(&#39;data-lang&#39;) || &#39;&#39;;
      const lines = [...pre.querySelectorAll(&#39;code&#39;)].map(c =&gt; c.textContent);
      const ph = document.createElement(&#39;div&#39;);
      ph.setAttribute(&#39;data-md-code&#39;, lang);
      ph.textContent = lines.join(&#39;\n&#39;);
      sec.replaceWith(ph);
    });

    function convert(node) {
      if (node.nodeType === Node.TEXT_NODE) {
        return node.textContent;
      }
      if (node.nodeType !== Node.ELEMENT_NODE) return &#39;&#39;;

      const tag = node.tagName.toLowerCase();
      if (tag === &#39;script&#39; || tag === &#39;style&#39;) return &#39;&#39;;

      // 代码块占位
      if (node.hasAttribute(&#39;data-md-code&#39;)) {
        const lang = node.getAttribute(&#39;data-md-code&#39;);
        return &#39;\n\n```&#39; + lang + &#39;\n&#39; + node.textContent + &#39;\n```\n\n&#39;;
      }

      const inner = [...node.childNodes].map(convert).join(&#39;&#39;);
      const text = inner.trim();

      switch (tag) {
        case &#39;p&#39;:
        case &#39;div&#39;:
          return &#39;\n\n&#39; + text + &#39;\n\n&#39;;
        case &#39;br&#39;:
          return &#39;\n&#39;;
        case &#39;strong&#39;:
        case &#39;b&#39;:
          return text ? &#39;**&#39; + text + &#39;**&#39; : &#39;&#39;;
        case &#39;em&#39;:
        case &#39;i&#39;:
          return text ? &#39;*&#39; + text + &#39;*&#39; : &#39;&#39;;
        case &#39;code&#39;:
          return &#39;`&#39; + text + &#39;`&#39;;
        case &#39;h1&#39;: return &#39;\n\n# &#39; + text + &#39;\n\n&#39;;
        case &#39;h2&#39;: return &#39;\n\n## &#39; + text + &#39;\n\n&#39;;
        case &#39;h3&#39;: return &#39;\n\n### &#39; + text + &#39;\n\n&#39;;
        case &#39;h4&#39;: return &#39;\n\n#### &#39; + text + &#39;\n\n&#39;;
        case &#39;h5&#39;: return &#39;\n\n##### &#39; + text + &#39;\n\n&#39;;
        case &#39;h6&#39;: return &#39;\n\n###### &#39; + text + &#39;\n\n&#39;;
        case &#39;blockquote&#39;:
          return &#39;\n\n&#39; + text.split(&#39;\n&#39;).map(l =&gt; &#39;&gt; &#39; + l).join(&#39;\n&#39;) + &#39;\n\n&#39;;
        case &#39;ul&#39;:
        case &#39;ol&#39;:
          return &#39;\n\n&#39; + inner + &#39;\n&#39;;
        case &#39;li&#39;: {
          const p = node.parentElement;
          if (p &amp;&amp; p.tagName.toLowerCase() === &#39;ol&#39;) {
            const i = [...p.children].indexOf(node) + 1;
            return i + &#39;. &#39; + text + &#39;\n&#39;;
          }
          return &#39;- &#39; + text + &#39;\n&#39;;
        }
        case &#39;a&#39;: {
          const href = node.getAttribute(&#39;href&#39;) || &#39;&#39;;
          return &#39;[&#39; + text + &#39;](&#39; + href + &#39;)&#39;;
        }
        case &#39;img&#39;: {
          const src = node.getAttribute(&#39;data-src&#39;) || node.getAttribute(&#39;src&#39;) || &#39;&#39;;
          const alt = node.getAttribute(&#39;alt&#39;) || &#39;&#39;;
          return &#39;\n\n![&#39; + alt + &#39;](&#39; + src + &#39;)\n\n&#39;;
        }
        case &#39;hr&#39;:
          return &#39;\n\n---\n\n&#39;;
        default:
          return inner;
      }
    }

    let md = convert(el)
      .replace(/\n{3,}/g, &#39;\n\n&#39;)
      .trim();

    copy(md);
    console.log(&#39;已复制到剪贴板，共 &#39; + md.length + &#39; 字符&#39;);
  })();
</code></pre>
]]></content:encoded>
      <guid>https://writee.org/tools-code/ba-gong-zhong-hao-wen-zhang-de-consoledai-ma</guid>
      <pubDate>Sun, 28 Jun 2026 17:25:10 +0000</pubDate>
    </item>
  </channel>
</rss>