UNPKG

@waline/client

Version:

client for waline comment system

2 lines 1.32 kB
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports):typeof define==`function`&&define.amd?define([`exports`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.WalineComment={}))})(this,function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});let t=e=>`${e.replace(/\/?$/u,`/`)}api/`,n=(e,t=``)=>{if(typeof e==`object`&&e.errno)throw TypeError(`${t} failed with ${e.errno}: ${e.errmsg}`);return e},r=({serverURL:e,lang:r,paths:i,signal:a})=>fetch(`${t(e)}comment?type=count&url=${encodeURIComponent(i.join(`,`))}&lang=${r}`,{signal:a}).then(e=>e.json()).then(e=>n(e,`Get comment count`).data),i=e=>{try{return decodeURI(e)}catch{return e}},a=(e=``)=>e.replace(/\/$/u,``),o=e=>/^(https?:)?\/\//u.test(e),s=e=>{let t=a(e);return o(t)?t:`https://${t}`},c=e=>{e.name!==`AbortError`&&console.error(e.message)},l=e=>{let{path:t}=e.dataset;return t?.length?t:null};e.commentCount=({serverURL:e,path:t=window.location.pathname,selector:n=`.waline-comment-count`,lang:a=navigator.language})=>{let o=new AbortController,u=document.querySelectorAll(n);return u.length>0&&r({serverURL:s(e),paths:Array.from(u,e=>i(l(e)??t)),lang:a,signal:o.signal}).then(e=>{u.forEach((t,n)=>{t.textContent=e[n].toString()})}).catch(c),o.abort.bind(o)},e.version=`3.15.2`}); //# sourceMappingURL=comment.umd.js.map