zhihu-photo-sharing

知乎分享不用在手动长截图了

// ==UserScript==
// @name            zhihu-photo-sharing
// @namespace       https://github.com/mlmdflr/zhihu-photo-sharing
// @version         0.0.1
// @author          mlmdflr
// @description     知乎分享不用在手动长截图了
// @match           https://www.zhihu.com/question/*/answer/*
// @run-at          document-idle
// @noframes
// ==/UserScript==
var tt=Math.pow;var a=(k,L,y)=>new Promise((O,h)=>{var m=p=>{try{E(y.next(p))}catch(b){h(b)}},d=p=>{try{E(y.throw(p))}catch(b){h(b)}},E=p=>p.done?O(p.value):Promise.resolve(p.value).then(m,d);E((y=y.apply(k,L)).next())});(()=>{"use strict";var k={555:function(h,m,d){var E=(b,u,g)=>new Promise((P,v)=>{var C=S=>{try{f(g.next(S))}catch(_){v(_)}},w=S=>{try{f(g.throw(S))}catch(_){v(_)}},f=S=>S.done?P(S.value):Promise.resolve(S.value).then(C,w);f((g=g.apply(b,u)).next())});const p=d(183);E(this,null,function*(){var b;try{const u=document.querySelector("div.QuestionAnswer-content"),g=document.querySelector(".QuestionHeader-title");if(u&&g){const P=g.cloneNode();P.textContent=g.textContent;const v=u.querySelector("div");u.insertBefore(P,v);const C=yield p.toPng(u,{backgroundColor:((b=document.querySelector("html"))==null?void 0:b.getAttribute("data-darkreader-scheme"))==="dark"?"#222":"#d2d0cc"});let w=document.createElement("a");w.style.display="none",w.href=C,w.setAttribute("download",g.textContent),typeof w.download=="undefined"&&w.setAttribute("target","_blank"),document.body.appendChild(w),w.click(),setTimeout(function(){document.body.removeChild(w)},200)}}catch(u){console.error(`zhihu-photo-sharing error : ${u}`)}})},183:(h,m,d)=>{d.r(m),d.d(m,{getFontEmbedCSS:()=>Vt,toBlob:()=>Ht,toCanvas:()=>$,toJpeg:()=>Ot,toPixelData:()=>Ut,toPng:()=>Mt,toSvg:()=>N});function E(t,e){if(t.match(/^[a-z]+:\/\//i))return t;if(t.match(/^\/\//))return window.location.protocol+t;if(t.match(/^[a-z]+:/i))return t;const r=document.implementation.createHTMLDocument(),n=r.createElement("base"),c=r.createElement("a");return r.head.appendChild(n),r.body.appendChild(c),e&&(n.href=e),c.href=t,c.href}const p=(()=>{let t=0;const e=()=>`0000${(Math.random()*tt(36,4)<<0).toString(36)}`.slice(-4);return()=>(t+=1,`u${e()}${t}`)})();function b(t){return e=>new Promise(r=>{setTimeout(()=>r(e),t)})}function u(t){const e=[];for(let r=0,n=t.length;r<n;r++)e.push(t[r]);return e}function g(t,e){const n=(t.ownerDocument.defaultView||window).getComputedStyle(t).getPropertyValue(e);return n?parseFloat(n.replace("px","")):0}function P(t){const e=g(t,"border-left-width"),r=g(t,"border-right-width");return t.clientWidth+e+r}function v(t){const e=g(t,"border-top-width"),r=g(t,"border-bottom-width");return t.clientHeight+e+r}function C(t,e={}){const r=e.width||P(t),n=e.height||v(t);return{width:r,height:n}}function w(){let t,e;try{e=process}catch(n){}const r=e&&e.env?e.env.devicePixelRatio:null;return r&&(t=parseInt(r,10),Number.isNaN(t)&&(t=1)),t||window.devicePixelRatio||1}const f=16384;function S(t){(t.width>f||t.height>f)&&(t.width>f&&t.height>f?t.width>t.height?(t.height*=f/t.width,t.width=f):(t.width*=f/t.height,t.height=f):t.width>f?(t.height*=f/t.width,t.width=f):(t.width*=f/t.height,t.height=f))}function _(t,e={}){return t.toBlob?new Promise(r=>{t.toBlob(r,e.type?e.type:"image/png",e.quality?e.quality:1)}):new Promise(r=>{const n=window.atob(t.toDataURL(e.type?e.type:void 0,e.quality?e.quality:void 0).split(",")[1]),c=n.length,o=new Uint8Array(c);for(let s=0;s<c;s+=1)o[s]=n.charCodeAt(s);r(new Blob([o],{type:e.type?e.type:"image/png"}))})}function D(t){return new Promise((e,r)=>{const n=new Image;n.decode=()=>e(n),n.onload=()=>e(n),n.onerror=r,n.crossOrigin="anonymous",n.decoding="async",n.src=t})}function et(t){return a(this,null,function*(){return Promise.resolve().then(()=>new XMLSerializer().serializeToString(t)).then(encodeURIComponent).then(e=>`data:image/svg+xml;charset=utf-8,${e}`)})}function nt(t,e,r){return a(this,null,function*(){const n="http://www.w3.org/2000/svg",c=document.createElementNS(n,"svg"),o=document.createElementNS(n,"foreignObject");return c.setAttribute("width",`${e}`),c.setAttribute("height",`${r}`),c.setAttribute("viewBox",`0 0 ${e} ${r}`),o.setAttribute("width","100%"),o.setAttribute("height","100%"),o.setAttribute("x","0"),o.setAttribute("y","0"),o.setAttribute("externalResourcesRequired","true"),c.appendChild(o),o.appendChild(t),et(c)})}function rt(t){const e=t.getPropertyValue("content");return`${t.cssText} content: '${e.replace(/'|"/g,"")}';`}function ct(t){return u(t).map(e=>{const r=t.getPropertyValue(e),n=t.getPropertyPriority(e);return`${e}: ${r}${n?" !important":""};`}).join(" ")}function ot(t,e,r){const n=`.${t}:${e}`,c=r.cssText?rt(r):ct(r);return document.createTextNode(`${n}{${c}}`)}function H(t,e,r){const n=window.getComputedStyle(t,r),c=n.getPropertyValue("content");if(c===""||c==="none")return;const o=p();try{e.className=`${e.className} ${o}`}catch(i){return}const s=document.createElement("style");s.appendChild(ot(o,r,n)),e.appendChild(s)}function it(t,e){H(t,e,":before"),H(t,e,":after")}const V="application/font-woff",q="image/jpeg",st={woff:V,woff2:V,ttf:"application/font-truetype",eot:"application/vnd.ms-fontobject",png:"image/png",jpg:q,jpeg:q,gif:"image/gif",tiff:"image/tiff",svg:"image/svg+xml",webp:"image/webp"};function at(t){const e=/\.([^./]*?)$/g.exec(t);return e?e[1]:""}function I(t){const e=at(t).toLowerCase();return st[e]||""}function lt(t){return t.split(/,/)[1]}function F(t){return t.search(/^(data:)/)!==-1}function B(t,e){return`data:${e};base64,${t}`}function j(t,e,r){return a(this,null,function*(){const n=yield fetch(t,e);if(n.status===404)throw new Error(`Resource "${n.url}" not found`);const c=yield n.blob();return new Promise((o,s)=>{const i=new FileReader;i.onerror=s,i.onloadend=()=>{try{o(r({res:n,result:i.result}))}catch(l){s(l)}},i.readAsDataURL(c)})})}const U={};function ut(t,e,r){let n=t.replace(/\?.*/,"");return r&&(n=t),/ttf|otf|eot|woff2?/i.test(n)&&(n=n.replace(/.*\//,"")),e?`[${e}]${n}`:n}function M(t,e,r){return a(this,null,function*(){const n=ut(t,e,r.includeQueryParams);if(U[n]!=null)return U[n];r.cacheBust&&(t+=(/\?/.test(t)?"&":"?")+new Date().getTime());let c;try{const o=yield j(t,r.fetchRequestInit,({res:s,result:i})=>(e||(e=s.headers.get("Content-Type")||""),lt(i)));c=B(o,e)}catch(o){c=r.imagePlaceholder||"";let s=`Failed to fetch resource: ${t}`;o&&(s=typeof o=="string"?o:o.message),s&&console.warn(s)}return U[n]=c,c})}function ft(t){return a(this,null,function*(){const e=t.toDataURL();return e==="data:,"?t.cloneNode(!1):D(e)})}function ht(t,e){return a(this,null,function*(){if(t.currentSrc){const o=document.createElement("canvas"),s=o.getContext("2d");o.width=t.clientWidth,o.height=t.clientHeight,s==null||s.drawImage(t,0,0,o.width,o.height);const i=o.toDataURL();return D(i)}const r=t.poster,n=I(r),c=yield M(r,n,e);return D(c)})}function dt(t){return a(this,null,function*(){var e;try{if(!((e=t==null?void 0:t.contentDocument)===null||e===void 0)&&e.body)return yield A(t.contentDocument.body,{},!0)}catch(r){}return t.cloneNode(!1)})}function mt(t,e){return a(this,null,function*(){return t instanceof HTMLCanvasElement?ft(t):t instanceof HTMLVideoElement?ht(t,e):t instanceof HTMLIFrameElement?dt(t):t.cloneNode(!1)})}const gt=t=>t.tagName!=null&&t.tagName.toUpperCase()==="SLOT";function yt(t,e,r){return a(this,null,function*(){var n;const c=gt(t)&&t.assignedNodes?u(t.assignedNodes()):u(((n=t.shadowRoot)!==null&&n!==void 0?n:t).childNodes);return c.length===0||t instanceof HTMLVideoElement||(yield c.reduce((o,s)=>o.then(()=>A(s,r)).then(i=>{i&&e.appendChild(i)}),Promise.resolve())),e})}function wt(t,e){const r=e.style;if(!r)return;const n=window.getComputedStyle(t);n.cssText?(r.cssText=n.cssText,r.transformOrigin=n.transformOrigin):u(n).forEach(c=>{let o=n.getPropertyValue(c);c==="font-size"&&o.endsWith("px")&&(o=`${Math.floor(parseFloat(o.substring(0,o.length-2)))-.1}px`),r.setProperty(c,o,n.getPropertyPriority(c))})}function pt(t,e){t instanceof HTMLTextAreaElement&&(e.innerHTML=t.value),t instanceof HTMLInputElement&&e.setAttribute("value",t.value)}function bt(t,e){if(t instanceof HTMLSelectElement){const r=e,n=Array.from(r.children).find(c=>t.value===c.getAttribute("value"));n&&n.setAttribute("selected","")}}function St(t,e){return e instanceof Element&&(wt(t,e),it(t,e),pt(t,e),bt(t,e)),e}function xt(t,e){return a(this,null,function*(){const r=t.querySelectorAll?t.querySelectorAll("use"):[];if(r.length===0)return t;const n={};for(let o=0;o<r.length;o++){const i=r[o].getAttribute("xlink:href");if(i){const l=t.querySelector(i),R=document.querySelector(i);!l&&R&&!n[i]&&(n[i]=yield A(R,e,!0))}}const c=Object.values(n);if(c.length){const o="http://www.w3.org/1999/xhtml",s=document.createElementNS(o,"svg");s.setAttribute("xmlns",o),s.style.position="absolute",s.style.width="0",s.style.height="0",s.style.overflow="hidden",s.style.display="none";const i=document.createElementNS(o,"defs");s.appendChild(i);for(let l=0;l<c.length;l++)i.appendChild(c[l]);t.appendChild(s)}return t})}function A(t,e,r){return a(this,null,function*(){return!r&&e.filter&&!e.filter(t)?null:Promise.resolve(t).then(n=>mt(n,e)).then(n=>yt(t,n,e)).then(n=>St(t,n)).then(n=>xt(n,e))})}const W=/url\((['"]?)([^'"]+?)\1\)/g,Et=/url\([^)]+\)\s*format\((["']?)([^"']+)\1\)/g,Ct=/src:\s*(?:url\([^)]+\)\s*format\([^)]+\)[,;]\s*)+/g;function Rt(t){const e=t.replace(/([.*+?^${}()|\[\]\/\\])/g,"\\$1");return new RegExp(`(url\\(['"]?)(${e})(['"]?\\))`,"g")}function Pt(t){const e=[];return t.replace(W,(r,n,c)=>(e.push(c),r)),e.filter(r=>!F(r))}function vt(t,e,r,n,c){return a(this,null,function*(){try{const o=r?E(e,r):e,s=I(e);let i;if(c){const l=yield c(o);i=B(l,s)}else i=yield M(o,s,n);return t.replace(Rt(e),`$1${i}$3`)}catch(o){}return t})}function Tt(t,{preferredFontFormat:e}){return e?t.replace(Ct,r=>{for(;;){const[n,,c]=Et.exec(r)||[];if(!c)return"";if(c===e)return`src: ${n};`}}):t}function z(t){return t.search(W)!==-1}function G(t,e,r){return a(this,null,function*(){if(!z(t))return t;const n=Tt(t,r);return Pt(n).reduce((o,s)=>o.then(i=>vt(i,s,e,r)),Promise.resolve(n))})}function _t(t,e){return a(this,null,function*(){var r;const n=(r=t.style)===null||r===void 0?void 0:r.getPropertyValue("background");if(n){const c=yield G(n,null,e);t.style.setProperty("background",c,t.style.getPropertyPriority("background"))}})}function $t(t,e){return a(this,null,function*(){if(!(t instanceof HTMLImageElement&&!F(t.src))&&!(t instanceof SVGImageElement&&!F(t.href.baseVal)))return;const r=t instanceof HTMLImageElement?t.src:t.href.baseVal,n=yield M(r,I(r),e);yield new Promise((c,o)=>{t.onload=c,t.onerror=o;const s=t;s.decode&&(s.decode=c),t instanceof HTMLImageElement?(t.srcset="",t.src=n):t.href.baseVal=n})})}function Lt(t,e){return a(this,null,function*(){const n=u(t.childNodes).map(c=>X(c,e));yield Promise.all(n).then(()=>t)})}function X(t,e){return a(this,null,function*(){t instanceof Element&&(yield _t(t,e),yield $t(t,e),yield Lt(t,e))})}function Dt(t,e){const{style:r}=t;e.backgroundColor&&(r.backgroundColor=e.backgroundColor),e.width&&(r.width=`${e.width}px`),e.height&&(r.height=`${e.height}px`);const n=e.style;return n!=null&&Object.keys(n).forEach(c=>{r[c]=n[c]}),t}const J={};function Q(t){return a(this,null,function*(){let e=J[t];if(e!=null)return e;const n=yield(yield fetch(t)).text();return e={url:t,cssText:n},J[t]=e,e})}function K(t,e){return a(this,null,function*(){let r=t.cssText;const n=/url\(["']?([^"')]+)["']?\)/g,o=(r.match(/url\([^)]+\)/g)||[]).map(s=>a(this,null,function*(){let i=s.replace(n,"$1");return i.startsWith("https://")||(i=new URL(i,t.url).href),j(i,e.fetchRequestInit,({result:l})=>(r=r.replace(s,`url(${l})`),[s,l]))}));return Promise.all(o).then(()=>r)})}function Y(t){if(t==null)return[];const e=[],r=/(\/\*[\s\S]*?\*\/)/gi;let n=t.replace(r,"");const c=new RegExp("((@.*?keyframes [\\s\\S]*?){([\\s\\S]*?}\\s*?)})","gi");for(;;){const l=c.exec(n);if(l===null)break;e.push(l[0])}n=n.replace(c,"");const o=/@import[\s\S]*?url\([^)]*\)[\s\S]*?;/gi,s="((\\s*?(?:\\/\\*[\\s\\S]*?\\*\\/)?\\s*?@media[\\s\\S]*?){([\\s\\S]*?)}\\s*?})|(([\\s\\S]*?){([\\s\\S]*?)})",i=new RegExp(s,"gi");for(;;){let l=o.exec(n);if(l===null){if(l=i.exec(n),l===null)break;o.lastIndex=i.lastIndex}else i.lastIndex=o.lastIndex;e.push(l[0])}return e}function At(t,e){return a(this,null,function*(){const r=[],n=[];return t.forEach(c=>{if("cssRules"in c)try{u(c.cssRules||[]).forEach((o,s)=>{if(o.type===CSSRule.IMPORT_RULE){let i=s+1;const l=o.href,R=Q(l).then(x=>K(x,e)).then(x=>Y(x).forEach(T=>{try{c.insertRule(T,T.startsWith("@import")?i+=1:c.cssRules.length)}catch(qt){console.error("Error inserting rule from remote css",{rule:T,error:qt})}})).catch(x=>{console.error("Error loading remote css",x.toString())});n.push(R)}})}catch(o){const s=t.find(i=>i.href==null)||document.styleSheets[0];c.href!=null&&n.push(Q(c.href).then(i=>K(i,e)).then(i=>Y(i).forEach(l=>{s.insertRule(l,c.cssRules.length)})).catch(i=>{console.error("Error loading remote stylesheet",i.toString())})),console.error("Error inlining remote css file",o.toString())}}),Promise.all(n).then(()=>(t.forEach(c=>{if("cssRules"in c)try{u(c.cssRules||[]).forEach(o=>{r.push(o)})}catch(o){console.error(`Error while reading CSS rules from ${c.href}`,o.toString())}}),r))})}function kt(t){return t.filter(e=>e.type===CSSRule.FONT_FACE_RULE).filter(e=>z(e.style.getPropertyValue("src")))}function It(t,e){return a(this,null,function*(){if(t.ownerDocument==null)throw new Error("Provided element is not within a Document");const r=u(t.ownerDocument.styleSheets),n=yield At(r,e);return kt(n)})}function Z(t,e){return a(this,null,function*(){const r=yield It(t,e);return(yield Promise.all(r.map(c=>{const o=c.parentStyleSheet?c.parentStyleSheet.href:null;return G(c.cssText,o,e)}))).join(`
`)})}function Ft(t,e){return a(this,null,function*(){const r=e.fontEmbedCSS!=null?e.fontEmbedCSS:e.skipFonts?null:yield Z(t,e);if(r){const n=document.createElement("style"),c=document.createTextNode(r);n.appendChild(c),t.firstChild?t.insertBefore(n,t.firstChild):t.appendChild(n)}})}function N(r){return a(this,arguments,function*(t,e={}){const{width:n,height:c}=C(t,e),o=yield A(t,e,!0);return yield Ft(o,e),yield X(o,e),Dt(o,e),yield nt(o,n,c)})}function $(r){return a(this,arguments,function*(t,e={}){const{width:n,height:c}=C(t,e),o=yield N(t,e),s=yield D(o),i=document.createElement("canvas"),l=i.getContext("2d"),R=e.pixelRatio||w(),x=e.canvasWidth||n,T=e.canvasHeight||c;return i.width=x*R,i.height=T*R,e.skipAutoScale||S(i),i.style.width=`${x}`,i.style.height=`${T}`,e.backgroundColor&&(l.fillStyle=e.backgroundColor,l.fillRect(0,0,i.width,i.height)),l.drawImage(s,0,0,i.width,i.height),i})}function Ut(r){return a(this,arguments,function*(t,e={}){const{width:n,height:c}=C(t,e);return(yield $(t,e)).getContext("2d").getImageData(0,0,n,c).data})}function Mt(r){return a(this,arguments,function*(t,e={}){return(yield $(t,e)).toDataURL()})}function Ot(r){return a(this,arguments,function*(t,e={}){return(yield $(t,e)).toDataURL("image/jpeg",e.quality||1)})}function Ht(r){return a(this,arguments,function*(t,e={}){const n=yield $(t,e);return yield _(n)})}function Vt(r){return a(this,arguments,function*(t,e={}){return Z(t,e)})}}},L={};function y(h){var m=L[h];if(m!==void 0)return m.exports;var d=L[h]={exports:{}};return k[h].call(d.exports,d,d.exports,y),d.exports}y.d=(h,m)=>{for(var d in m)y.o(m,d)&&!y.o(h,d)&&Object.defineProperty(h,d,{enumerable:!0,get:m[d]})},y.o=(h,m)=>Object.prototype.hasOwnProperty.call(h,m),y.r=h=>{typeof Symbol!="undefined"&&Symbol.toStringTag&&Object.defineProperty(h,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(h,"__esModule",{value:!0})};var O=y(555)})();