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