blog-hexo/public/js/8fc499db.js
2023-11-15 16:42:39 +08:00

1 line
9.1 KiB
JavaScript

(()=>{"use strict";const e="__theme__",t=()=>{const t=localStorage.getItem(e);return null!=t?t:"light"};new class{constructor(){this.listeners={}}on(e,t){this.listeners[e]||(this.listeners[e]=[]),this.listeners[e].push(t)}off(e,t){const n=this.listeners[e];n&&(this.listeners[e]=n.filter((e=>e!==t)))}emit(e,...t){const n=this.listeners[e];n&&n.length&&n.forEach((e=>{e(...t)}))}};const n=e=>Promise.all(e.map((e=>new Promise(((t,n)=>{if("css"===e.type){const o=document.createElement("link");o.href=e.url,o.rel="stylesheet",o.onload=()=>t(),o.onerror=()=>n(new Error(`Failed to load CSS from ${e.url}`)),document.head.appendChild(o)}else if("js"===e.type){const o=document.createElement("script");o.src=e.url,e.id&&(o.id=e.id),o.onload=()=>t(),o.onerror=()=>n(new Error(`Failed to load JS from ${e.url}`)),document.body.appendChild(o)}else n(new Error("Invalid resource type specified."))}))))),o=e=>{const{enable:t,jsCdn:o,cssCdn:l}=e;t&&n([{type:"css",url:l},{type:"js",url:o}]).then((e=>{e&&(e=>{const t=/\$\$(.+?)\$\$/g,n=/\\\[(.+?)\\\]/g;function o(e,t,n){let o;const l=[];for(;null!==(o=t.exec(e.nodeValue));){const t=document.createRange();t.setStart(e,o.index),t.setEnd(e,o.index+o[0].length),l.push(t)}for(const e of l){const t=e.toString().replace(/^\$\$|\$\$$|\\\[|\\\]$/g,""),o=document.createElement("span");o.innerHTML=window.katex.renderToString(t,{throwOnError:!1,displayMode:n}),e.deleteContents(),e.insertNode(o)}}document.querySelectorAll(e).forEach((e=>{const l=document.createTreeWalker(e,NodeFilter.SHOW_TEXT,null);let r;for(;r=l.nextNode();)o(r,t,!1),o(r,n,!0)}))})(".article-container")}))};var l=function(e,t){var n={};for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&t.indexOf(o)<0&&(n[o]=e[o]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var l=0;for(o=Object.getOwnPropertySymbols(e);l<o.length;l++)t.indexOf(o[l])<0&&Object.prototype.propertyIsEnumerable.call(e,o[l])&&(n[o[l]]=e[o[l]])}return n};const r=e=>{const{enable:t,cdn:o}=e,r=l(e,["enable","cdn"]);t&&n([{type:"js",url:o}]).then((e=>{e&&(((e="vcomments",t=".article-container")=>{const n=document.querySelector(t);if(!n)return;const o=document.createElement("div");o.id=e,n.appendChild(o)})(),new window.Valine(Object.assign({el:"#vcomments"},r)))}))},c=()=>{((e,t)=>{const n=document.querySelector(e);n&&document.addEventListener("selectionchange",(()=>{const e=window.getSelection();if(e&&e.rangeCount>0&&!e.isCollapsed){const o=e.getRangeAt(0);if(n.contains(o.startContainer)&&n.contains(o.endContainer)){const l=e.toString(),r=[],c=document.createNodeIterator(o.commonAncestorContainer,NodeFilter.SHOW_ELEMENT);let s;for(;s=c.nextNode();)o.intersectsNode(s)&&r.push(s);const a=r.filter((e=>n!==e));t({selectedElements:a,selectedText:l,range:o})}}}))})(".article-container article",(e=>{const{range:t,selectedText:n}=e;document.addEventListener("mouseup",(()=>{!function(e){document.querySelectorAll(".text-tab").forEach((e=>e.remove()));const t=document.createElement("div");t.classList.add("text-tab");const n=document.createElement("ul");s.forEach((e=>{const t=document.createElement("li");t.innerHTML=`${e.icon}<div>${e.value}</div>`,n.appendChild(t)})),t.append(n),t.style.left=`${window.scrollX+e.left+e.width/2}px`,t.style.top=window.scrollY+e.top-50-10+"px",document.body.appendChild(t)}(t.getBoundingClientRect())}))}))},s=[{icon:'<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 20 20"><g fill="none"><path d="M4.098 12H4a2 2 0 0 0-2 2v2a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-2a2 2 0 0 0-2-2h-5.304l-.57.573a2.5 2.5 0 0 1-.568.426H16a1 1 0 0 1 1 1v2a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1v-2a1 1 0 0 1 1-1h.08a1.483 1.483 0 0 1-.067-.587l.004-.042l.028-.165l.053-.206zm8.076-9.38a2.263 2.263 0 0 1 3.07-.125l.13.12l.126.136a2.276 2.276 0 0 1 0 2.952l-.12.13l-5.963 5.99a1.5 1.5 0 0 1-.547.35l-.157.047l-3.086.76a.5.5 0 0 1-.618-.526l.015-.084l.792-3.07a1.5 1.5 0 0 1 .283-.566l.106-.118l5.969-5.995zm2.494.703a1.263 1.263 0 0 0-1.683-.089l-.103.093L6.914 9.32a.5.5 0 0 0-.1.145l-.03.083l-.583 2.26l2.273-.56a.501.501 0 0 0 .113-.043l.052-.03l.07-.06l5.962-5.988a1.277 1.277 0 0 0-.003-1.805z" fill="currentColor"></path></g></svg>',value:"马克"},{icon:'<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 20 20"><g fill="none"><path d="M10.464 2.314a.5.5 0 0 0-.928 0l-3 7.5a.5.5 0 1 0 .928.372l1.073-2.682h2.926l1.073 2.682a.5.5 0 1 0 .928-.372l-3-7.5zM10 3.846l1.063 2.658H8.937L10 3.846zM4.5 12A1.5 1.5 0 0 0 3 13.5v3A1.5 1.5 0 0 0 4.5 18h11a1.5 1.5 0 0 0 1.5-1.5v-3a1.5 1.5 0 0 0-1.5-1.5h-11zM4 13.5a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 .5.5v3a.5.5 0 0 1-.5.5h-11a.5.5 0 0 1-.5-.5v-3z" fill="currentColor"></path></g></svg>',value:"颜色"},{icon:'<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 20 20"><g fill="none"><path d="M10.461 3.806a.5.5 0 0 0-.921 0l-4 9.5a.5.5 0 1 0 .92.388L8.017 10h3.968l1.555 3.694a.5.5 0 1 0 .922-.388l-4-9.5zM11.563 9H8.438L10 5.288L11.563 9z" fill="currentColor"></path><path d="M2.5 16a.5.5 0 0 0 0 1h15a.5.5 0 0 0 0-1h-15z" fill="currentColor"></path></g></svg>',value:"直线"},{icon:'<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 20 20"><g fill="none"><path d="M10.142 10.5H6.86L8.5 5.815l1.641 4.685zm.526 1.5l.33.944l1.178-1.177l-2.873-8.198c-.266-.759-1.339-.759-1.605 0L4.042 14.003a.75.75 0 0 0 1.416.496L6.333 12h4.335zm5.14-2.452l-4.829 4.83a2.197 2.197 0 0 0-.578 1.02l-.374 1.498a.916.916 0 0 0-.024.14a4.601 4.601 0 0 1-1.111-.088c-.073-.017-.1-.11-.066-.178c.18-.348.233-1.073-.404-1.33c-.86-.345-1.978.125-2.862.498c-.366.154-.692.29-.944.346c-.387.086-.848-.065-1.216-.249c-.212-.106-.482.082-.36.286c.219.366.614.737 1.326.825c.82.102 1.391-.152 1.975-.41c.4-.178.805-.358 1.3-.428c.086-.012.145.09.112.17c-.152.357-.133.894.316 1.244c.518.405 2.191.511 3.313.183l1.221-.305c.387-.097.74-.296 1.021-.578l4.83-4.83a1.87 1.87 0 0 0-2.645-2.644z" fill="currentColor"></path></g></svg>',value:"波浪线"}];const a='<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 24 24"><g fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M9 5H7a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V7a2 2 0 0 0-2-2h-2"></path><rect x="9" y="3" width="6" height="4" rx="2"></rect></g></svg>',i=e=>{document.querySelectorAll(".toc a").forEach((e=>e.classList.remove("active")));const t=document.querySelector('.toc a[href="'+e+'"]');t&&t.classList.add("active")};document.addEventListener("click",(function(e){const t=e.target.closest(".toc-link");if(t){const e=t.getAttribute("href");e&&i(e)}})),document.addEventListener("DOMContentLoaded",(function(){(e=>{const t=document.querySelector(e);if(t){const e=localStorage.getItem("scrolledHeight");e&&(t.scrollTop=Number(e))}})("main.scrollbar-obtrusive"),window.location.hash&&i(window.location.hash);const{mermaid:e,katex:l,valine:s}=window;o(Object.assign(Object.assign({},l),{enable:window.page.use.indexOf("katex")>-1})),(e=>{var t;const{enable:o,cdn:l,theme:r}=e;if(o){const e=document.getElementById("src-mermaid");e&&(null===(t=e.parentNode)||void 0===t||t.removeChild(e)),n([{type:"js",url:l,id:"src-mermaid"}]).then((e=>{e&&window.mermaid.initialize({startOnLoad:!0,theme:r||"neutral"})}))}})(Object.assign(Object.assign({},e),{enable:window.page.use.indexOf("mermaid")>-1})),r(Object.assign(Object.assign({},s),{enable:window.page.use.indexOf("valine")>-1})),document.querySelectorAll(".article-container article pre > code").forEach((e=>{const t=e.parentNode;if(!t)return;const n=document.createElement("div");n.classList.add("code-wrapper"),t.parentNode.insertBefore(n,t),n.appendChild(t);const o=document.createElement("div");o.classList.add("btn-wrapper");const l=t.getAttribute("data-language"),r=document.createElement("span");r.classList.add("lang"),r.textContent=l,o.appendChild(r);const c=document.createElement("span");c.className="copy-button",c.innerHTML=a,c.addEventListener("click",(function(){const t=e.textContent;navigator.clipboard.writeText(t).then((()=>{c.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 24 24"><g fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M9 5H7a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V7a2 2 0 0 0-2-2h-2"></path><rect x="9" y="3" width="6" height="4" rx="2"></rect><path d="M9 14l2 2l4-4"></path></g></svg>',setTimeout((()=>{c.innerHTML=a}),2e3)}))})),o.appendChild(c),n.appendChild(o)})),c(),d();const u=document.getElementById("toggle-theme");null==u||u.addEventListener("click",(()=>{const e=document.querySelector("#prism-theme");e?e.setAttribute("href",`/lib/prism/one-${t()}.css`):d()}))})),document.addEventListener("DOMContentLoaded",(function(){const e=document.querySelector("main.scrollbar-obtrusive");e&&e.addEventListener("scroll",(()=>(e=>{const t=document.querySelector(e);if(t){const e=t.scrollTop;localStorage.setItem("scrolledHeight",String(e))}})("main.scrollbar-obtrusive")))}));const d=()=>{const e=document.createElement("link");e.setAttribute("id","prism-theme"),e.rel="stylesheet",e.type="text/css",e.href=`/lib/prism/one-${t()}.css`,document.head.append(e)}})();