// ==UserScript== // @name 知乎下载器 // @namespace http://howardzhangdqs.eu.org/ // @version 0.1.8-0590f6d7 // @description 一键复制知乎文章、回答为Markdown // @author HowardZhangdqs // @match *://www.zhihu.com/* // @match *://zhuanlan.zhihu.com/* // @license MIT // @icon https://static.zhihu.com/heifetz/favicon.ico // @grant none // @downloadURL none // ==/UserScript== /** 更新日志 * 23.10.30: 脚本开写 * 23.10.31: * feat: 解析渲染表格 * feat: 解析渲染链接 * fix: 加了一个被忘掉的break,但是我忘了是哪忘了加了 * fix: 修复编辑框会被加上`复制为Markdown`的按钮 * doc: 给types加了完整的注释 * doc: 给Lexer和Parser函数添加完整的注释 */ (()=>{"use strict";function e(){for(var e="复制为Markdown",n=function(n){var o,c,i;return n.parentElement.classList.contains("Editable")||n.children[0].classList.contains("zhihucopier-button")?"continue":(i=function(e){for(var n=[],r=0;r code").classList.value.slice(9),dom:o}):o.classList.contains("RichText-LinkCardContainer")&&(c=o.firstChild,n.push({type:t.Link,text:c.getAttribute("data-text"),href:c.href,dom:o}));break;case"blockquote":n.push({type:t.Blockquote,content:a(o),dom:o});break;case"figure":var c=o.querySelector("img").getAttribute("data-actualsrc");c&&n.push({type:t.Figure,src:c,dom:o});break;case"ul":var i=Array.from(o.querySelectorAll("li"));n.push({type:t.UList,content:i.map((function(e){return a(e)})),dom:o});break;case"ol":i=Array.from(o.querySelectorAll("li")),n.push({type:t.Olist,content:i.map((function(e){return a(e)})),dom:o});break;case"p":n.push({type:t.Text,content:a(o),dom:o});break;case"hr":n.push({type:t.HR,dom:o});break;case"table":var s=function(e){for(var t=[],n=0,a=Array.from(e.rows);n "));break;case t.Text:n.push(r(o.content));break;case t.HR:n.push("\n---\n");break;case t.Link:n.push("[".concat(o.text,"](").concat(o.href,")"));break;case t.Table:var c,i=o.content,s=i[0].length,l=new Array(s).fill(0),u=[];for(c in i)for(var h in i[c])l[h]=Math.max(l[h],i[c][h].length);var p=function(e){for(var t="",n=0;n请联系开发者",c.style.height="4em",setTimeout((function(){c.style.height="2em",c.innerHTML=e}),1e3)}})))},o=0,c=Array.from(document.querySelectorAll(".RichText"));o