:sparkles:🎉 Add waline3 comment plugin.

This commit is contained in:
elkan1788
2024-08-03 18:56:01 +08:00
parent 1076ba9282
commit 27ca39f39e
16 changed files with 351 additions and 72 deletions

View File

@@ -0,0 +1 @@
const h=e=>e.replace(/\/?$/,"/")+"api/",i=(e,t="")=>{if("object"==typeof e&&e.errno)throw new TypeError(`${t} failed with ${e.errno}: `+e.errmsg);return e},g=({serverURL:e,lang:t,paths:n,signal:r})=>fetch(`${h(e)}comment?type=count&url=${encodeURIComponent(n.join(","))}&lang=`+t,{signal:r}).then(e=>e.json()).then(e=>i(e,"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=>{e=m(e);return u(e)?e:"https://"+e},$=e=>{"AbortError"!==e.name&&console.error(e.message)},f=e=>{e=e.dataset.path;return null!=e&&e.length?e:null},v=({serverURL:e,path:t=window.location.pathname,selector:n=".waline-comment-count",lang:r=navigator.language})=>{const o=new AbortController,a=document.querySelectorAll(n);return a.length&&g({serverURL:d(e),paths:Array.from(a).map(e=>p(f(e)??t)),lang:r,signal:o.signal}).then(n=>{a.forEach((e,t)=>{e.innerText=n[t].toString()})}).catch($),o.abort.bind(o)},w="3.3.0";export{v as commentCount,w as version};

View File

@@ -0,0 +1 @@
const v="3.3.0",$={"Content-Type":"application/json"},h=e=>e.replace(/\/?$/,"/")+"api/",u=(e,t="")=>{if("object"==typeof e&&e.errno)throw new TypeError(`${t} failed with ${e.errno}: `+e.errmsg);return e},f=({serverURL:e,lang:t,paths:n,type:r,signal:a})=>fetch(`${h(e)}article?path=${encodeURIComponent(n.join(","))}&type=${encodeURIComponent(r.join(","))}&lang=`+t,{signal:a}).then(e=>e.json()).then(e=>u(e,"Get counter").data),U=({serverURL:e,lang:t,path:n,type:r,action:a})=>fetch(h(e)+"article?lang="+t,{method:"POST",headers:$,body:JSON.stringify({path:n,type:r,action:a})}).then(e=>e.json()).then(e=>u(e,"Update counter").data),R=({serverURL:e,lang:t,paths:n,signal:r})=>f({serverURL:e,lang:t,paths:n,type:["time"],signal:r}),w=e=>U({...e,type:"time",action:"inc"}),L=(e="")=>e.replace(/\/$/u,""),b=e=>/^(https?:)?\/\//.test(e),d=e=>{e=L(e);return b(e)?e:"https://"+e},j=e=>{"AbortError"!==e.name&&console.error(e.message)},m=e=>{e=e.dataset.path;return null!=e&&e.length?e:null},y=(r,e)=>{e.forEach((e,t)=>{const n=r[t].time;"number"==typeof n&&(e.innerText=n.toString())})},S=({serverURL:e,path:n=window.location.pathname,selector:t=".waline-pageview-count",update:r=!0,lang:a=navigator.language})=>{const o=new AbortController,l=Array.from(document.querySelectorAll(t)),s=e=>{e=m(e);return null!==e&&n!==e},i=t=>R({serverURL:d(e),paths:t.map(e=>m(e)??n),lang:a,signal:o.signal}).then(e=>y(e,t)).catch(j);if(r){const p=l.filter(e=>!s(e)),h=l.filter(s);w({serverURL:d(e),path:n,lang:a}).then(e=>y(e,p)),h.length&&i(h)}else i(l);return o.abort.bind(o)};export{S as pageviewCount,v as version};

File diff suppressed because one or more lines are too long

56
static/3rd/waline/3.3.0/waline.min.js vendored Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long