constgetInitStatus=function(){lete=!1;return()=>{lett=e;returne||(e=!0),t}}(),PvOpts=function(){functione(e){return$(e).attr("content")}functiont(t){leta=e(t);returnvoid0!==a&&!1!==a}return{getProxyMeta:()=>e("meta[name=pv-proxy-endpoint]"),getLocalMeta:()=>e("meta[name=pv-cache-path]"),hasProxyMeta:()=>t("meta[name=pv-proxy-endpoint]"),hasLocalMeta:()=>t("meta[name=pv-cache-path]")}}(),PvStorage=function(){conste={KEY_PV:"pv",KEY_PV_SRC:"pv_src",KEY_CREATION:"pv_created_date"},t="same-origin",a="cors";functiono(e){returnlocalStorage.getItem(e)}functionr(e,t){localStorage.setItem(e,t)}functionn(t,a){r(e.KEY_PV,t),r(e.KEY_PV_SRC,a),r(e.KEY_CREATION,(newDate).toJSON())}return{keysCount:()=>Object.keys(e).length,hasCache:()=>null!==localStorage.getItem(e.KEY_PV),getCache:()=>JSON.parse(localStorage.getItem(e.KEY_PV)),saveLocalCache(e){n(e,t)},saveProxyCache(e){n(e,a)},isExpired(){lett=newDate(o(e.KEY_CREATION));returnt.setHours(t.getHours()+1),Date.now()>=t.getTime()},isFromLocal:()=>o(e.KEY_PV_SRC)===t,isFromProxy:()=>o(e.KEY_PV_SRC)===a,newerThan:e=>PvStorage.getCache().totalsForAllResults["ga:pageviews"]>e.totalsForAllResults["ga:pageviews"],inspectKeys(){if(localStorage.length===PvStorage.keysCount())for(lett=0;t<localStorage.length;t++){switch(localStorage.key(t)){casee.KEY_PV:casee.KEY_PV_SRC:casee.KEY_CREATION:break;default:returnvoidlocalStorage.clear()}}elselocalStorage.clear()}}}();functioncountUp(e,t,a){if(e<t){leto=newCountUp(a,e,t);o.error?console.error(o.error):o.start()}}functioncountPV(e,t){leta=0;if(void0!==t)for(leto=0;o<t.length;++o){if(t[parseInt(o,10)][0]===e){a+=parseInt(t[parseInt(o,10)][1],10);break}}returna}functiontacklePV(e,t,a,o){letr=countPV(t,e);if(r=0===r?1:r,o){conste=parseInt(a.text().replace(/,/g,""),10);r>e&&countUp(e,r,a.attr("id"))}elsea.text((newIntl.NumberFormat).format(r))}functiondisplayPageviews(e){if(void0===e)return;lett=getInitStatus();consta=e.rows;if($("#post-list").length>0)$(".post-preview").each(function(){conste=$(this).find("a").attr("href");tacklePV(a,e,$(this).find(".pageviews"),t)});elseif($(".post").length>0){conste=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(e=!1){returnfetch(PvOpts.getLocalMeta()).then(e=>e.json()).then(t=>{e&&PvStorage.isFromProxy()&&PvStorage.newerThan(t)||(displayPageviews(t),PvStorage.saveLocalCache(JSON.stringify(t)))})}$(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())});