functioncountUp(b,a,d){if(b<a){varc=newCountUp(d,b,a);if(!c.error){c.start()}else{console.error(c.error)}}}functioncountPV(f,e){varg=f.replace(/\/posts\//g,"").replace(/\//g,".html");vard=0;varc=f.replace(/posts\//g,"");for(varb=0;b<e.length;++b){vara=e[b][0];if(a==f||a==c||a.concat("/")==c||a.slice(a.lastIndexOf("/")+1)===g){d+=parseInt(e[b][1])}}returnd}functiontacklePV(e,f,d,b){varc=countPV(f,e);c=(c==0?1:c);if(!b){d.text(newIntl.NumberFormat().format(c))}else{vara=parseInt(d.text().replace(/,/g,""));if(c>a){countUp(a,c,d.attr("id"))}}}functiondisplayPageviews(c){if(c===undefined){return}vara=getInitStatus();varb=c.rows;if($("#post-list").length>0){$(".post-preview").each(function(){vare=$(this).children("h1").children("a").attr("href");tacklePV(b,e,$(this).find(".pageviews"),a)})}else{if($(".post").length>0){vard=window.location.pathname;tacklePV(b,d,$("#pv"),a)}}}vargetInitStatus=(function(){vara=false;returnfunction(){letret=a;if(!a){a=true}returnret}})();varPvCache=(function(){conste="pv";constb="pv-created-date";constd="pv-type";varc={ORIGIN:"origin",PROXY:"proxy"};functiona(g){returnlocalStorage.getItem(g)}functionf(g,h){localStorage.setItem(g,h)}return{getData:function(){returnJSON.parse(localStorage.getItem(e))},saveOriginCache:function(g){f(e,g);f(d,c.ORIGIN);f(b,newDate().toJSON())},saveProxyCache:function(g){f(e,g);f(d,c.PROXY);f(b,newDate().toJSON())},isOriginCache:function(){returna(d)==c.ORIGIN},isProxyCache:function(){returna(d)==c.PROXY},isExpired:function(){if(PvCache.isOriginCache()){letdate=newDate(a(b));date.setDate(date.getDate()+1);returnDate.now()>=date.getTime()}else{if(PvCache.isProxyCache()){letdate=newDate(a(b));date.setHours(date.getHours()+1);returnDate.now()>=date.getTime()}}returnfalse},getAllPagevies:function(){returnPvCache.getData().totalsForAllResults["ga:pageviews"]},newerThan:function(g){returnPvCache.getAllPagevies()>g.totalsForAllResults["ga:pageviews"]}}})();functionfetchOriginPageviews(a){if(a===undefined){return}displayPageviews(a);PvCache.saveOriginCache(JSON.stringify(a))}functionfetchProxyPageviews(){letproxy=JSON.parse(proxyData);$.ajax({type:"GET",url:proxy.url,dataType:"jsonp",jsonpCallback:"displayPageviews",success:function(b,c,a){PvCache.saveProxyCache(JSON.stringify(b))},error:function(a,c,b){console.log("Failed to load pageviews from proxy server: "+b)}})}$(function(){if($(".pageviews").length>0){letcache=PvCache.getData();if(cache){if(PvCache.isExpired()){if(PvCache.isProxyCache()){letoriginPvData=pageviews?JSON.parse(pageviews):undefined;if(originPvData){if(PvCache.newerThan(originPvData)){displayPageviews(cache)}else{fetchOriginPageviews(originPvData)}}fetchProxyPageviews()}else{if(PvCache.isOriginCache()){fetchOriginPageviews(originPvData);fetchProxyPageviews()}}}else{displayPageviews(cache);if(PvCache.isOriginCache()){fetchProxyPageviews()}}}else{letoriginPvData=pageviews?JSON.parse(pageviews):undefined;fetchOriginPageviews(originPvData);fetchProxyPageviews()}}});