constgetInitStatus=function(){lett=!1;return()=>{vare=t;returnt=t||!0,e}}(),PvOpts=function(){functiont(e){return$(e).attr("content")}functione(e){e=t(e);returnvoid0!==e&&!1!==e}return{getProxyMeta(){returnt("meta[name=pv-proxy-endpoint]")},getLocalMeta(){returnt("meta[name=pv-cache-path]")},hasProxyMeta(){returne("meta[name=pv-proxy-endpoint]")},hasLocalMeta(){returne("meta[name=pv-cache-path]")}}}(),PvStorage=function(){consta={KEY_PV:"pv",KEY_PV_SRC:"pv_src",KEY_CREATION:"pv_created_date"},t={LOCAL:"same-origin",PROXY:"cors"};functionr(e){returnlocalStorage.getItem(e)}functiono(e,t){localStorage.setItem(e,t)}functionn(e,t){o(a.KEY_PV,e),o(a.KEY_PV_SRC,t),o(a.KEY_CREATION,(newDate).toJSON())}return{keysCount(){returnObject.keys(a).length},hasCache(){returnnull!==localStorage.getItem(a.KEY_PV)},getCache(){returnJSON.parse(localStorage.getItem(a.KEY_PV))},saveLocalCache(e){n(e,t.LOCAL)},saveProxyCache(e){n(e,t.PROXY)},isExpired(){vare=newDate(r(a.KEY_CREATION));returne.setHours(e.getHours()+1),Date.now()>=e.getTime()},isFromLocal(){returnr(a.KEY_PV_SRC)===t.LOCAL},isFromProxy(){returnr(a.KEY_PV_SRC)===t.PROXY},newerThan(e){returnPvStorage.getCache().totalsForAllResults["ga:pageviews"]>e.totalsForAllResults["ga:pageviews"]},inspectKeys(){if(localStorage.length!==PvStorage.keysCount())localStorage.clear();elsefor(lete=0;e<localStorage.length;e++)switch(localStorage.key(e)){casea.KEY_PV:casea.KEY_PV_SRC:casea.KEY_CREATION:break;default:returnvoidlocalStorage.clear()}}}}();functioncountUp(e,t,a){e<t&&((a=newCountUp(a,e,t)).error?console.error(a.error):a.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){t=0===(t=countPV(t,e))?1:t;r?(e=parseInt(a.text().replace(/,/g,""),10))<t&&countUp(e,t,a.attr("id")):a.text((newIntl.NumberFormat).format(t))}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.hasProxyMeta()&&$.ajax({type:"GET",url:PvOpts.getProxyMeta(),dataType:"jsonp",jsonpCallback:"displayPageviews",success:e=>{PvStorage.saveProxyCache(JSON.stringify(e))},error:(e,t,a)=>{console.log("Failed to load pageviews from proxy server: "+a)}})}functionfetchLocalPageviews(t=!1){returnfetch(PvOpts.getLocalMeta()).then(e=>e.json()).then(e=>{t&&PvStorage.isFromProxy()&&PvStorage.newerThan(e)||(displayPageviews(e),PvStorage.saveLocalCache(JSON.stringify(e)))})}$(function(){$(".pageviews").length<=0||(PvStorage.inspectKeys(),PvStorage.hasCache()?(displayPageviews(PvStorage.getCache()),PvStorage.isExpired()?PvOpts.hasLocalMeta()?fetchLocalPageviews(!0).then(fetchProxyPageviews):fetchProxyPageviews():PvStorage.isFromLocal()&&fetchProxyPageviews()):PvOpts.hasLocalMeta()?fetchLocalPageviews().then(fetchProxyPageviews):fetchProxyPageviews())});