'use strict';(()=>{const STORAGE_KEY='sphere-post-views';let configs;function init(postID){configs=Sphere_PostViews;postID=postID||configs.postID||null;if(!window.fetch||!configs||!postID){return} if(configs.sampling){const rand=Math.floor(Math.random()*configs.samplingRate)+1;if(rand!==1){return}} if(isCrawler()){return} if(recentlyCounted(postID)){return} const params={method:'POST',headers:{'Content-type':'application/x-www-form-urlencoded'},body:['post_id='+postID,'action=update_views_ajax','token='+configs.token].join('&')};fetch(configs.ajaxUrl,params).then(resp=>resp.text()).then(data=>logViewCount(postID))} function recentlyCounted(id){if(!configs.repeatCountDelay){return!1} const repeatCountDelay=3600*parseFloat(configs.repeatCountDelay)*1000;const viewed=getStorage()||{};if(!viewed||!viewed.posts||(!id in viewed.posts)){return!1} const lastViewed=parseInt(viewed.posts[id]);if((Date.now()-lastViewed)10000){viewed={}}}catch(e){return!1} return viewed} function logViewCount(id){if(!configs.repeatCountDelay){return} const viewed=getStorage()||{};viewed.posts=viewed.posts||{};viewed.posts[id]=Date.now();localStorage.setItem(STORAGE_KEY,JSON.stringify(viewed))} function isCrawler(){if(navigator.webdriver){return!0} const isBot=/headless|bot|spider|crawl|google|baidu|bing|msn|teoma|slurp|yandex/i.test(navigator.userAgent);return isBot} document.readyState!=='loading'?init():document.addEventListener('DOMContentLoaded',()=>init());document.addEventListener('spc-alp-pageview',e=>{if(!e.detail.id){return} init(e.detail.id)})})() ;