hugo-theme-next/static/js/3rd/waline/2.15.8/comment.min.js

1 line
1.1 KiB
JavaScript
Raw Normal View History

!function(e,t){"function"==typeof define&&define.amd?define("Waline",["exports"],t):"undefined"!=typeof exports?t(exports):(t(t={}),e.Waline=t)}("undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:this,function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.version=e.commentCount=void 0;const c=e=>{e=function(e){return(0<arguments.length&&void 0!==e?e:"").replace(/\/$/u,"")}(e);return/^(https?:)?\/\//.test(e)?e:"https://"+e},n=e=>{"AbortError"!==e.name&&console.error(e.message)};e.version="2.15.8",e.commentCount=e=>{let{serverURL:r,path:a=window.location.pathname,selector:t=".waline-comment-count",lang:i=navigator.language}=e;const l=new AbortController,s=document.querySelectorAll(t);return s.length&&(()=>{let{serverURL:e,lang:t,paths:n,signal:o}={serverURL:c(r),paths:Array.from(s).map(e=>(e=>{try{e=decodeURI(e)}catch(e){}return e})(e.dataset.path||e.getAttribute("id")||a)),lang:i,signal:l.signal};return fetch(`${e}/comment?type=count&url=${encodeURIComponent(n.join(","))}&lang=`+t,{signal:o}).then(e=>e.json()).then(e=>Array.isArray(e)?e:[e])})().then(n=>{s.forEach((e,t)=>{e.innerText=n[t].toString()})}).catch(n),l.abort.bind(l)}});