@waline/client
Version:
client for waline comment system
3 lines (2 loc) • 1.07 kB
JavaScript
const h=e=>`${e.replace(/\/?$/,"/")}api/`,i=(e,n="")=>{if(typeof e=="object"&&e.errno)throw new TypeError(`${n} failed with ${e.errno}: ${e.errmsg}`);return e},g=({serverURL:e,lang:n,paths:r,signal:o})=>fetch(`${h(e)}comment?type=count&url=${encodeURIComponent(r.join(","))}&lang=${n}`,{signal:o}).then(t=>t.json()).then(t=>i(t,"Get comment count").data),p=e=>{try{e=decodeURI(e)}catch{}return e},m=(e="")=>e.replace(/\/$/u,""),u=e=>/^(https?:)?\/\//.test(e),d=e=>{const n=m(e);return u(n)?n:`https://${n}`},$=e=>{e.name!=="AbortError"&&console.error(e.message)},f=e=>{const{path:n}=e.dataset;return n!=null&&n.length?n:null},v=({serverURL:e,path:n=window.location.pathname,selector:r=".waline-comment-count",lang:o=navigator.language})=>{const t=new AbortController,a=document.querySelectorAll(r);return a.length&&g({serverURL:d(e),paths:Array.from(a).map(c=>p(f(c)??n)),lang:o,signal:t.signal}).then(c=>{a.forEach((s,l)=>{s.innerText=c[l].toString()})}).catch($),t.abort.bind(t)},w="3.5.7";export{v as commentCount,w as version};
//# sourceMappingURL=comment.js.map