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