1 line
9.1 KiB
JavaScript
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.05
|