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(){lete=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())for(lete=0;e<localStorage.length;e++)switch(localStorage.key(e)){casea.KEY_PV:casea.KEY_PV_SRC:casea.KEY_CREATION:break;default:returnvoidlocalStorage.clear()}elselocalStorage.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){leto=countPV(t,e);o=0===o?1:o,r?(r=parseInt(a.text().replace(/,/g,""),10),o>r&&countUp(r,o,a.attr("id"))):a.text((newIntl.NumberFormat).format(o))}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())});