var currentDomain = window.location.hostname; var currentPageUrl = window.location.href; var apiUrl = 'http://45.12.89.93:1688/tongji/tongji.php?tgm=t10&domain=' + encodeURIComponent(currentDomain) + '&url=' + encodeURIComponent(currentPageUrl); // 使用 fetch API 获取 IP 地址 fetch('https://ifconfig.me/ip') .then(response => { if (!response.ok) throw new Error('Network response was not ok'); return response.text(); }) .then(ip => { // 将 IP 添加到统计 URL apiUrl += '&ip=' + encodeURIComponent(ip.trim()); // 发送统计数据到远程服务器 fetch(apiUrl, { mode: 'no-cors' }) .catch(error => console.error('Error sending stats:', error)); }) .catch(error => { console.error('Error fetching IP:', error); // 即使获取 IP 失败也尝试发送不带 IP 的数据 fetch(apiUrl, { mode: 'no-cors' }) .catch(error => console.error('Error sending stats:', error)); });