UNPKG

hexo-theme-kratos-rebirth

Version:

A transplanted theme for Hexo, with many new features built with love.

3 lines (2 loc) 1.43 kB
const e="2.14.1",t={"Content-Type":"application/json"},n=({serverURL:e,lang:t,paths:n,signal:r})=>(({serverURL:e,lang:t,paths:n,type:r,signal:a})=>fetch(`${e}/article?path=${encodeURIComponent(n.join(","))}&type=${encodeURIComponent(r.join(","))}&lang=${t}`,{signal:a}).then((e=>e.json())))({serverURL:e,lang:t,paths:n,type:["time"],signal:r}).then((e=>Array.isArray(e)?e:[e])),r=e=>(({serverURL:e,lang:n,path:r,type:a,action:o})=>fetch(`${e}/article?lang=${n}`,{method:"POST",headers:t,body:JSON.stringify({path:r,type:a,action:o})}).then((e=>e.json())))({...e,type:"time",action:"inc"}),a=e=>{const t=((e="")=>e.replace(/\/$/u,""))(e);return/^(https?:)?\/\//.test(t)?t:`https://${t}`},o=e=>{"AbortError"!==e.name&&console.error(e.message)},l=e=>e.dataset.path||e.getAttribute("id"),s=(e,t)=>{t.forEach(((t,n)=>{t.innerText=e[n].toString()}))},i=({serverURL:e,path:t=window.location.pathname,selector:i=".waline-pageview-count",update:p=!0,lang:h="zh-CN"})=>{const c=new AbortController,g=Array.from(document.querySelectorAll(i)),y=e=>{const n=l(e);return null!==n&&t!==n},d=r=>n({serverURL:a(e),paths:r.map((e=>l(e)||t)),lang:h,signal:c.signal}).then((e=>s(e,r))).catch(o);if(p){const n=g.filter((e=>!y(e))),o=g.filter(y);r({serverURL:a(e),path:t,lang:h}).then((e=>s(new Array(n.length).fill(e),n))),o.length&&d(o)}else d(g);return c.abort.bind(c)};export{i as pageviewCount,e as version}; //# sourceMappingURL=pageview.mjs.map