blog-hexo/public/js/d3872ea1.js

1 line
7.5 KiB
JavaScript
Raw Normal View History

2023-11-17 11:02:45 +08:00
(()=>{"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:r}=e;t&&n([{type:"css",url:r},{type:"js",url:o}]).then((e=>{e&&(e=>{const t=/\$\$(.+?)\$\$/g,n=/\\\[(.+?)\\\]/g;function o(e,t,n){let o;const r=[];for(;null!==(o=t.exec(e.nodeValue));){const t=document.createRange();t.setStart(e,o.index),t.setEnd(e,o.index+o[0].length),r.push(t)}for(const e of r){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 r=document.createTreeWalker(e,NodeFilter.SHOW_TEXT,null);let s;for(;s=r.nextNode();)o(s,t,!1),o(s,n,!0)}))})(".article-container")}))};var r=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 r=0;for(o=Object.getOwnPropertySymbols(e);r<o.length;r++)t.indexOf(o[r])<0&&Object.prototype.propertyIsEnumerable.call(e,o[r])&&(n[o[r]]=e[o[r]])}return n};const s=e=>{const{enable:t,cdn:o}=e,s=r(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"},s)))}))},c=[{icon:'<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 24 24"><path d="M17 15l1.55 1.55c-.96 1.69-3.33 3.04-5.55 3.37V11h3V9h-3V7.82C14.16 7.4 15 6.3 15 5c0-1.65-1.35-3-3-3S9 3.35 9 5c0 1.3.84 2.4 2 2.82V9H8v2h3v8.92c-2.22-.33-4.59-1.68-5.55-3.37L7 15l-4-3v3c0 3.88 4.92 7 9 7s9-3.12 9-7v-3l-4 3zM12 4c.55 0 1 .45 1 1s-.45 1-1 1s-1-.45-1-1s.45-1 1-1z" fill="currentColor"></path></svg>',value:"锚点"},{icon:'<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 24 24"><path d="M20 2H4c-1.1 0-2 .9-2 2v18l4-4h14c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zm0 14H6l-2 2V4h16v12zM7 9h2v2H7zm4 0h2v2h-2zm4 0h2v2h-2z" fill="currentColor"></path></svg>',value:"写点想法"}],l=document.querySelector(".article-container article"),i=(e,t)=>{const{startContainer:n,startOffset:o}=t;e.classList.add("select-wrap");const r=document.createElement("div");r.classList.add("text-tab");const s=document.createElement("ul");c.forEach((t=>{const n=document.createElement("li");n.innerHTML=`${t.icon}`,n.classList.add("tip","right"),n.setAttribute("data-tip",t.value),n.addEventListener("click",(()=>((e,t)=>{if("锚点"===t.value){e.querySelectorAll(".flag").forEach((e=>e.remove()));const n=document.createElement("span");n.classList.add("flag"),n.innerHTML=t.icon,e.appendChild(n),e.classList.add("flag-paragraph")}})(e,t))),s.appendChild(n)})),r.append(s),e.appendChild(r),document.removeEventListener("selectionchange",d)},a=()=>[...document.querySelectorAll(".text-tab")].forEach((e=>e.remove())),d=()=>{const e=()=>{const e=window.getSelection();if(e&&e.rangeCount>0&&!e.isCollapsed){const t=e.getRangeAt(0),{startContainer:n,endContainer:o}=t;if(l.contains(n)&&l.contains(o)){const e=(e=>{let t=e;for(;t&&t.parentElement&&"ARTICLE"!==t.parentElement.tag