!function(){const e=e=>(e=encodeURI(e),document.getElementById(e).querySelector(".leancloud-visitors-count")),{app_id:t,app_key:o,server_url:n}=CONFIG.leancloud_visitors,r=n=>{const r=(e,r,s)=>fetch(`${n}/1.1${r}`,{method:e,headers:{"X-LC-Id":t,"X-LC-Key":o,"Content-Type":"application/json"},body:JSON.stringify(s)});if(CONFIG.page.isPost){if(CONFIG.hostname!==location.hostname)return;(t=>{const o=document.querySelector(".leancloud_visitors"),n=decodeURI(o.id),r=o.dataset.flagTitle;t("get",`/classes/Counter?where=${encodeURIComponent(JSON.stringify({url:n}))}`).then((e=>e.json())).then((({results:o})=>{if(o.length>0){const r=o[0];e(n).innerText=r.time+1,t("put","/classes/Counter/"+r.objectId,{time:{__op:"Increment",amount:1}}).catch((e=>{console.error("Failed to save visitor count",e)}))}else CONFIG.leancloud_visitors.security?(e(n).innerText="Counter not initialized! More info at console err msg.",console.error("ATTENTION! LeanCloud counter has security bug, see how to solve it here: https://github.com/theme-next/hexo-leancloud-counter-security. \n However, you can still use LeanCloud without security, by setting `security` option to `false`.")):t("post","/classes/Counter",{title:r,url:n,time:1}).then((e=>e.json())).then((()=>{e(n).innerText=1})).catch((e=>{console.error("Failed to create",e)}))})).catch((e=>{console.error("LeanCloud Counter Error",e)}))})(r)}else document.querySelectorAll(".post-title-link").length>=1&&(t=>{const o=[...document.querySelectorAll(".leancloud_visitors")].map((e=>decodeURI(e.id)));t("get",`/classes/Counter?where=${encodeURIComponent(JSON.stringify({url:{$in:o}}))}`).then((e=>e.json())).then((({results:t})=>{for(const n of o){const o=t.find((e=>e.url===n));e(n).innerText=o?o.time:0}})).catch((e=>{console.error("LeanCloud Counter Error",e)}))})(r)},s="-MdYXbMMI"===t.slice(-9)?`https://${t.slice(0,8).toLowerCase()}.api.lncldglobal.com`:n;document.addEventListener("page:loaded",(()=>{s?r(s):fetch(`https://app-router.leancloud.cn/2/route?appId=${t}`).then((e=>e.json())).then((({api_server:e})=>{r(`https://${e}`)}))}))}();