constgetInitStatus=function(){lett=!1;return()=>{vare=t;returnt=t||!0,e}}(),PvOpts=function(){functione(e){e=$(e).attr("content");returnvoid0!==e&&!1!==e}return{getProxyEndpoint(){return$("meta[name=pv-proxy-endpoint]").attr("content")},getLocalData(){return$("meta[name=pv-cache-path]").attr("content")},hasProxyEndpoint(){returne("meta[name=pv-proxy-endpoint]")},hasLocalData(){returne("meta[name=pv-cache-path]")}}}(),PvStorage=function(){constt="pv",a="pv_created_date";functionr(e,t){localStorage.setItem(e,t)}return{hasCache(){returnnull!==localStorage.getItem(t)},getCache(){returnJSON.parse(localStorage.getItem(t))},saveCache(e){r(t,e),r(a,(newDate).toJSON())},isExpired(){lete=newDate((t=a,localStorage.getItem(t)));vart;returne.setHours(e.getHours()+1),Date.now()>=e.getTime()},getAllPageviews(){returnPvStorage.getCache().totalsForAllResults["ga:pageviews"]},newerThan(e){returnPvStorage.getAllPageviews()>e.totalsForAllResults["ga:pageviews"]},inspectKeys(){for(lete=0;e<localStorage.length;e++)switch(localStorage.key(e)){caset:casea:break;default:returnvoidlocalStorage.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(){PvOpts.hasProxyEndpoint()&&$.ajax({type:"GET",url:PvOpts.getProxyEndpoint(),dataType:"jsonp",jsonpCallback:"displayPageviews",success:(e,t,a)=>{PvStorage.saveCache(JSON.stringify(e))},error:(e,t,a)=>{console.log("Failed to load pageviews from proxy server: "+a)}})}functionloadPageviews(t=!1){PvOpts.hasLocalData()?fetch(PvOpts.getLocalData()).then(e=>e.json()).then(e=>{t&&PvStorage.newerThan(e)||(displayPageviews(e),PvStorage.saveCache(JSON.stringify(e)))}).then(()=>{fetchProxyPageviews()}):fetchProxyPageviews()}$(function(){$(".pageviews").length<=0||(PvStorage.inspectKeys(),PvStorage.hasCache()&&(displayPageviews(PvStorage.getCache()),!PvStorage.isExpired())||loadPageviews(PvStorage.hasCache()))});