constgetInitStatus=function(){lete=!1;return()=>{vart=e;returne=e||!0,t}}(),PvOpts={getProxyEndpoint(){return$("meta[name=pv-proxy-endpoint]").attr("content")},getLocalData(){return$("meta[name=pv-cache-path]").attr("content")},hasLocalData(){vart=PvOpts.getLocalData();returnvoid0!==t&&!1!==t}},PvData=function(){conste="pv",a="pv_created_date",r="pv_source",n={ORIGIN:"origin",PROXY:"proxy"};functiono(t){returnlocalStorage.getItem(t)}functioni(t,e){localStorage.setItem(t,e)}return{getData(){returnJSON.parse(localStorage.getItem(e))},saveOriginCache(t){i(e,t),i(r,n.ORIGIN),i(a,(newDate).toJSON())},saveProxyCache(t){i(e,t),i(r,n.PROXY),i(a,(newDate).toJSON())},isFromOrigin(){returno(r)===n.ORIGIN},isFromProxy(){returno(r)===n.PROXY},isExpired(){if(PvData.isFromOrigin()){lett=newDate(o(a));returnt.setDate(t.getDate()+1),Date.now()>=t.getTime()}if(PvData.isFromProxy()){lett=newDate(o(a));returnt.setHours(t.getHours()+1),Date.now()>=t.getTime()}return!1},getAllPageviews(){returnPvData.getData().totalsForAllResults["ga:pageviews"]},newerThan(t){returnPvData.getAllPageviews()>t.totalsForAllResults["ga:pageviews"]},inspectKeys(){null!==localStorage.getItem(e)&&null!==localStorage.getItem(r)&&null!==localStorage.getItem(a)||localStorage.clear()}}}();functioncountUp(e,a,r){if(e<a){lett=newCountUp(r,e,a);t.error?console.error(t.error):t.start()}}functioncountPV(e,a){letr=0;if(void0!==a)for(lett=0;t<a.length;++t)if(a[parseInt(t,10)][0]===e){r+=parseInt(a[parseInt(t,10)][1],10);break}returnr}functiontacklePV(t,e,a,r){letn=countPV(e,t);n=0===n?1:n,r?(r=parseInt(a.text().replace(/,/g,""),10),n>r&&countUp(r,n,a.attr("id"))):a.text((newIntl.NumberFormat).format(n))}functiondisplayPageviews(t){if(void0!==t){lete=getInitStatus();consta=t.rows;0<$("#post-list").length?$(".post-preview").each(function(){vart=$(this).find("a").attr("href");tacklePV(a,t,$(this).find(".pageviews"),e)}):0<$(".post").length&&(t=window.location.pathname,tacklePV(a,t,$("#pv"),e))}}functionfetchProxyPageviews(){$.ajax({type:"GET",url:PvOpts.getProxyEndpoint(),dataType:"jsonp",jsonpCallback:"displayPageviews",success:(t,e,a)=>{PvData.saveProxyCache(JSON.stringify(t))},error:(t,e,a)=>{console.log("Failed to load pageviews from proxy server: "+a)}})}functionfetchPageviews(t=!0,e=!1){t?fetch(PvOpts.getLocalData()).then(t=>t.json()).then(t=>{e&&PvData.newerThan(t)||(displayPageviews(t),PvData.saveOriginCache(JSON.stringify(t)))}).then(()=>fetchProxyPageviews()):fetchProxyPageviews()}$(function(){vart;$(".pageviews").length<=0||(PvData.inspectKeys(),(t=PvData.getData())?(displayPageviews(t),PvData.isExpired()?fetchPageviews(!0,PvData.isFromProxy()):PvData.isFromOrigin()&&fetchPageviews(!1)):fetchPageviews(PvOpts.hasLocalData()))});