// ==UserScript== // @name 知乎下载器 // @namespace http://howardzhangdqs.eu.org/ // @source // @version 0.1.2 // @description 一键复制知乎文章、回答为Markdown // @author HowardZhangdqs // @match *://*.zhihu.com/* // @license MIT // @icon https://static.zhihu.com/heifetz/favicon.ico // @grant none // @downloadURL none // ==/UserScript== (()=>{"use strict";function e(){for(var e="复制为Markdown",n=function(n){if(n.children[0].classList.contains("zhihucopier-button"))return"continue";var c=function(e){for(var n=[],a=0;a code").classList.value.slice(9),dom:c});break;case"blockquote":n.push({type:t.Blockquote,content:o(c),dom:c});break;case"figure":var r=c.querySelector("img").getAttribute("data-actualsrc");r&&n.push({type:t.Figure,src:r,dom:c});break;case"ul":var s=Array.from(c.querySelectorAll("li"));n.push({type:t.UList,content:s.map((function(e){return o(e)})),dom:c});break;case"ol":s=Array.from(c.querySelectorAll("li")),n.push({type:t.Olist,content:s.map((function(e){return o(e)})),dom:c});break;case"p":n.push({type:t.Text,content:o(c),dom:c});break;case"hr":n.push({type:t.HR,dom:c})}}return n}(n.childNodes),r=function(e){for(var n=[],o=0;o "));break;case t.Text:n.push(a(c.content));break;case t.HR:n.push("\n---\n")}}return n}(c),s=((c=document.createElement("button")).classList.add("zhihucopier-button"),c.innerText=e,c.style.right="0",c.style.top="-2em",c.style.zIndex="999",c.style.width="150px",c.style.height="2em",c.style.backgroundColor="rgba(0,0,0,0.3)",c.style.color="white",c.style.border="white 1px solid",c.style.outline="none",c.style.cursor="pointer",c.style.borderRadius="1em 0 0 1em",c.style.margin="0 0 1em 0",c);s.style.borderRadius="1em",n.prepend(s),s.addEventListener("click",(function(){try{navigator.clipboard.writeText(r.join("\n\n")),s.innerHTML="复制成功✅",setTimeout((function(){s.innerHTML=e}),1e3)}catch(t){s.innerHTML="发生未知错误
请联系开发者",s.style.height="4em",setTimeout((function(){s.style.height="2em",s.innerHTML=e}),1e3)}}))},c=0,r=Array.from(document.querySelectorAll(".RichText"));c