<scriptsrc="https://cdn.jsdelivr.net/npm/jquery@3/dist/jquery.min.js"></script><scriptsrc="https://cdn1.lncld.net/static/js/av-core-mini-0.6.1.js"></script><script>AV.initialize("{{site.leancloud.app_id}}","{{site.leancloud.app_key}}");</script><script>functionshowHitCount(Counter){varquery=newAV.Query(Counter);varentries=[];var$visitors=$(".leancloud_visitors");$visitors.each(function(){entries.push($(this).attr("id").trim());});query.containedIn('url',entries);query.find().done(function(results){varCOUNT_CONTAINER_REF='.leancloud-visitors-count';if(results.length===0){$visitors.find(COUNT_CONTAINER_REF).text(0);return;}for(vari=0;i<results.length;i++){varitem=results[i];varurl=item.get('url');varhits=item.get('hits');varelement=document.getElementById(url);$(element).find(COUNT_CONTAINER_REF).text(hits);}for(vari=0;i<entries.length;i++){varurl=entries[i];varelement=document.getElementById(url);varcountSpan=$(element).find(COUNT_CONTAINER_REF);if(countSpan.text()==''){countSpan.text(0);}}}).fail(function(object,error){console.log("Error: "+error.code+" "+error.message);});}functionaddCount(Counter){var$visitors=$(".leancloud_visitors");varurl=$visitors.attr('id').trim();vartitle=$visitors.attr('data-flag-title').trim();varquery=newAV.Query(Counter);query.equalTo("url",url);query.find({success:function(results){if(results.length>0){varcounter=results[0];counter.fetchWhenSave(true);counter.increment("hits");counter.save(null,{success:function(counter){var$element=$(document.getElementById(url));$element.find('.leancloud-visitors-count').text(counter.get('hits'));},error:function(counter,error){console.log('Failed to save Visitor num, with error message: '+error.message);}});}else{varnewcounter=newCounter();/* Set ACL */varacl=newAV.ACL();acl.setPublicReadAccess(true);acl.setPublicWriteAccess(true);newcounter.setACL(acl);/* End Set ACL */newcounter.set("title",title);newcounter.set("url",url);newcounter.set("hits",1);newcounter.save(null,{success:function(newcounter){var$element=$(document.getElementById(url));$element.find('.leancloud-visitors-count').text(newcounter.get('hits'));},error:function(newcounter,error){console.log('Failed to create');}});}},error:function(error){console.log('Error:'+error.code+" "+error.message);}});}$(function(){varCounter=AV.Object.extend("Counter");if($('.leancloud_visitors').length==1){/* in post.html, so add 1 to hit counts */addCount(Counter);}});</script>