(function () { 'use strict'; var JEFCOUNTS_CONFIG = { endpoint: '//tongji.yes110.cn/api/track.php', siteKey: 'a3861a120bb8e06e', delay: 800, debug: false }; if (!JEFCOUNTS_CONFIG.endpoint) { return; } var detection = { interactions: 0, start: Date.now(), lastUrl: '' }; function quickDetect() { var score = 0; if (navigator.webdriver) score += 60; if (window.callPhantom || window._phantom) score += 60; if (navigator.userAgent.indexOf('HeadlessChrome') > -1) score += 60; if (!navigator.languages || navigator.languages.length === 0) score += 30; if (navigator.plugins.length === 0) score += 20; if (screen.width === 0 || screen.height === 0) score += 40; return Math.min(score, 100); } function trackInteraction() { detection.interactions++; if (detection.interactions > 3) removeListeners(); } function removeListeners() { document.removeEventListener('mousemove', trackInteraction); document.removeEventListener('click', trackInteraction); } function setupTracking() { document.addEventListener('mousemove', trackInteraction, { passive: true }); document.addEventListener('click', trackInteraction, { passive: true }); setTimeout(removeListeners, 3000); } function buildPayload() { var referrer = document.referrer || ''; try { var params = new URLSearchParams(window.location.search); var refParam = params.get('ref'); var utmSource = params.get('utm_source'); if (refParam && refParam.indexOf('http') === 0) { referrer = refParam; } else if (utmSource) { referrer = 'utm_source=' + utmSource; } } catch (e) {} var data = { url: window.location.href, site_key: JEFCOUNTS_CONFIG.siteKey, ref: referrer }; var score = quickDetect(); if (detection.interactions === 0 && Date.now() - detection.start > 1000) { score += 25; } if (score > 20 || detection.interactions === 0) { data.bot_score = score; data.interactions = detection.interactions; } return data; } function send(forceBeacon) { var url = window.location.href; if (url === detection.lastUrl) return; detection.lastUrl = url; var data = buildPayload(); if (JEFCOUNTS_CONFIG.debug) console.log('[JefCounts] track:', data); var json = JSON.stringify(data); if (forceBeacon || navigator.sendBeacon) { var blob = new Blob([json], { type: 'application/json' }); if (navigator.sendBeacon(JEFCOUNTS_CONFIG.endpoint, blob)) return; } if (window.fetch) { fetch(JEFCOUNTS_CONFIG.endpoint, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: json, keepalive: true }).catch(function () { }); return; } var xhr = new XMLHttpRequest(); xhr.open('POST', JEFCOUNTS_CONFIG.endpoint, true); xhr.setRequestHeader('Content-Type', 'application/json'); xhr.timeout = 1500; xhr.send(json); } function init() { setupTracking(); setTimeout(send, JEFCOUNTS_CONFIG.delay); window.addEventListener('pagehide', function () { send(true); }); } if (document.readyState === 'complete') { init(); } else { window.addEventListener('load', init); } if (window.history && window.history.pushState) { var pushState = history.pushState; history.pushState = function () { pushState.apply(history, arguments); setTimeout(function () { send(); }, 100); }; window.addEventListener('popstate', function () { setTimeout(function () { send(); }, 100); }); } })();