WordPress blocksy主题访客代码
<div id="luze-ip-box" style="display:inline-flex;flex-direction:column;align-items:flex-start;gap:4px;font-size:13px;line-height:1.4;font-weight:500;padding:10px 16px;border-radius:12px;background:rgba(128,128,128,0.1);font-variant-numeric:tabular-nums;">
<div style="display:flex;align-items:center;gap:6px;">
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="flex-shrink:0;"><circle cx="12" cy="12" r="10"></circle><line x1="2" y1="12" x2="22" y2="12"></line><path d="M12 2a15.3 15.3 0 0 1 4 10 15.3 15.3 0 0 1-4 10 15.3 15.3 0 0 1-4-10 15.3 15.3 0 0 1 4-10z"></path></svg>
<span>您的 IP:<span id="user-ip">正在检测...</span></span>
</div>
<div style="display:flex;align-items:center;gap:6px;">
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="flex-shrink:0;"><path d="M21 10c0 7-9 13-9 13s-9-6-9-13a9 9 0 0 1 18 0z"></path><circle cx="12" cy="10" r="3"></circle></svg>
<span>归属地:<span id="user-loc">正在定位...</span></span>
</div>
<div style="display:flex;align-items:center;gap:6px;">
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="flex-shrink:0;"><rect x="2" y="2" width="20" height="8" rx="2" ry="2"></rect><rect x="2" y="14" width="20" height="8" rx="2" ry="2"></rect><line x1="6" y1="6" x2="6.01" y2="6"></line><line x1="6" y1="18" x2="6.01" y2="18"></line></svg>
<span>运营商:<span id="user-isp">正在识别...</span></span>
</div>
<div style="display:flex;align-items:center;gap:6px;">
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="flex-shrink:0;"><circle cx="12" cy="12" r="10"></circle><polyline points="12 6 12 12 16 14"></polyline></svg>
<span>访问时间:<span id="user-visit-time">正在记录...</span></span>
</div>
</div>
<script>
(function() {
// 0. 记录当前访问时间(固定快照,格式:YYYY-MM-DD HH:mm:ss)
function pad(n) { return n < 10 ? "0" + n : n; }
var now = new Date();
var visitTimeStr = now.getFullYear() + "-" + pad(now.getMonth() + 1) + "-" + pad(now.getDate()) + " " +
pad(now.getHours()) + ":" + pad(now.getMinutes()) + ":" + pad(now.getSeconds());
document.getElementById('user-visit-time').innerText = visitTimeStr;
// 1. 常见运营商名称转中文
function translateISP(isp) {
if (!isp) return "未知运营商";
var s = isp.toLowerCase();
if (s.includes("chinanet") || s.includes("china telecom")) return "中国电信";
if (s.includes("china unicom") || s.includes("cncgroup")) return "中国联通";
if (s.includes("china mobile") || s.includes("cmnet")) return "中国移动";
if (s.includes("china education") || s.includes("cernet")) return "中国教育网";
if (s.includes("china broadcast") || s.includes("cbn")) return "中国广电";
if (s.includes("alibaba") || s.includes("aliyun")) return "阿里云";
if (s.includes("tencent")) return "腾讯云";
if (s.includes("huawei")) return "华为云";
if (s.includes("baidu")) return "百度云";
if (s.includes("bytedance") || s.includes("volcengine")) return "火山引擎";
if (s.includes("google")) return "谷歌云 (Google)";
if (s.includes("amazon") || s.includes("aws")) return "亚马逊云 (AWS)";
if (s.includes("microsoft") || s.includes("azure")) return "微软云 (Azure)";
if (s.includes("cloudflare")) return "Cloudflare";
if (s.includes("oracle")) return "甲骨文云 (Oracle)";
if (s.includes("digitalocean")) return "DigitalOcean";
if (s.includes("vultr") || s.includes("choopa")) return "Vultr";
if (s.includes("linode") || s.includes("akamai")) return "Akamai / Linode";
if (s.includes("ovh")) return "OVHcloud";
if (s.includes("hetzner")) return "Hetzner";
if (s.includes("cogent")) return "Cogent";
if (s.includes("ntt")) return "NTT";
if (s.includes("softbank")) return "日本软银 (SoftBank)";
if (s.includes("kddi")) return "日本 KDDI";
if (s.includes("kt corp") || s.includes("korea telecom")) return "韩国 KT";
if (s.includes("sk broadband")) return "韩国 SK";
if (s.includes("lg uplus") || s.includes("lg dacom")) return "韩国 LG U+";
if (s.includes("chunghwa")) return "中华电信";
if (s.includes("pccw")) return "电讯盈科 (PCCW)";
if (s.includes("hgc")) return "环球全域电讯 (HGC)";
return isp;
}
// 2. 备用接口用的常见地区词典(仅当主接口失败时触发)
var fallbackDict = {
"Beijing": "北京", "Shanghai": "上海", "Tianjin": "天津", "Chongqing": "重庆",
"Guangdong": "广东", "Zhejiang": "浙江", "Jiangsu": "江苏", "Sichuan": "四川",
"Hubei": "湖北", "Hunan": "湖南", "Fujian": "福建", "Shandong": "山东",
"Henan": "河南", "Hebei": "河北", "Shaanxi": "陕西", "Liaoning": "辽宁",
"Jilin": "吉林", "Heilongjiang": "黑龙江", "Anhui": "安徽", "Jiangxi": "江西",
"Shanxi": "山西", "Yunnan": "云南", "Guizhou": "贵州", "Guangxi": "广西",
"Hainan": "海南", "Gansu": "甘肃", "Qinghai": "青海", "Inner Mongolia": "内蒙古",
"Xinjiang": "新疆", "Tibet": "西藏", "Ningxia": "宁夏",
"Hong Kong": "香港", "Macao": "澳门", "Taiwan": "台湾",
"California": "加利福尼亚", "New York": "纽约", "Texas": "德克萨斯",
"Washington": "华盛顿", "Virginia": "弗吉尼亚", "Oregon": "俄勒冈",
"Tokyo": "东京", "Osaka": "大阪", "Seoul": "首尔", "Singapore": "新加坡",
"London": "伦敦", "Frankfurt": "法兰克福", "Paris": "巴黎", "Sydney": "悉尼"
};
var regionNames = null;
try { regionNames = new Intl.DisplayNames(['zh-Hans'], { type: 'region' }); } catch (e) {}
function translateFallbackLoc(code, country, region, city) {
var c = country;
if (code && regionNames) {
try {
var zh = regionNames.of(code.toUpperCase());
if (zh && zh !== code) c = zh;
} catch (e) {}
}
var r = fallbackDict[region] || region;
var ct = fallbackDict[city] || city;
return [c, r, ct];
}
function renderIP(ip, locArray, isp) {
var cleaned = locArray.filter(Boolean).map(function(item) {
return item.replace(/(省|市|自治区|特别行政区)$/, '');
});
var uniqueLoc = [...new Set(cleaned)].join(' · ') || '未知地区';
document.getElementById('user-ip').innerText = ip || '未知';
document.getElementById('user-loc').innerText = uniqueLoc;
document.getElementById('user-isp').innerText = translateISP(isp);
}
// 主接口:ipapi.co + 联动全中文接口 vore.top
fetch('https://ipapi.co')
.then(res => res.json())
.then(data => {
if (data && data.ip && !data.error) {
return fetch('https://vore.top' + data.ip)
.then(r => r.json())
.then(vore => {
if (vore && vore.code === 200 && vore.ipdata) {
var d = vore.ipdata;
var country = d.info1 || data.country_name;
var region = d.info2 || '';
var city = d.info3 || '';
var isp = d.isp || data.org;
renderIP(data.ip, [country, region, city], isp);
} else {
renderIP(data.ip, translateFallbackLoc(data.country_code, data.country_name, data.region, data.city), data.org);
}
})
.catch(() => {
renderIP(data.ip, translateFallbackLoc(data.country_code, data.country_name, data.region, data.city), data.org);
});
} else {
throw new Error('ipapi error');
}
})
.catch(() => {
// 备用接口:ipwho.is
fetch('https://ipwho.is')
.then(res => res.json())
.then(data => {
if (data && data.success) {
renderIP(
data.ip,
translateFallbackLoc(data.country_code, data.country, data.region, data.city),
data.connection?.isp || data.connection?.org
);
} else {
throw new Error('ipwho error');
}
})
.catch(() => {
document.getElementById('user-ip').innerText = '获取受限';
document.getElementById('user-loc').innerText = '-';
document.getElementById('user-isp').innerText = '-';
});
});
})();
</script>
<script>
(function() {
function maskIP(ip) {
ip = ip.trim();
if (!ip || ip.includes('正在') || ip.includes('*') || ip.includes('失败')) return ip;
if (ip.includes('.')) {
const parts = ip.split('.');
if (parts.length === 4) {
return `${parts[0]}.${parts[1]}.*.*`;
}
}
if (ip.includes(':')) {
const parts = ip.split(':');
if (parts.length > 2) {
return `${parts[0]}:${parts[1]}:****:${parts[parts.length - 1]}`;
}
}
return ip;
}
function applyMask() {
const ipEl = document.getElementById('user-ip');
if (!ipEl) return;
// 标记当前是否处于隐藏(脱敏)状态
let isMasked = true;
function processText() {
const currentText = ipEl.textContent.trim();
// 忽略提示文字和已脱敏文本
if (!currentText || currentText.includes('正在') || currentText.includes('*') || currentText.includes('失败')) {
return;
}
// 1. 保存完整 IP 到 dataset,方便后续切换
ipEl.dataset.fullIp = currentText;
ipEl.style.cursor = 'pointer';
ipEl.title = '点击切换显示/隐藏完整 IP';
// 2. 如果当前处于脱敏模式,立即替换为带星号的文本
if (isMasked) {
ipEl.textContent = maskIP(currentText);
}
}
// 立即检查当前已显示的 IP
processText();
// 持续监听:旧脚本写入新 IP 时自动保存并脱敏
const observer = new MutationObserver(() => {
processText();
});
observer.observe(ipEl, { childList: true, characterData: true, subtree: true });
// 绑定点击事件:切换显示完整 IP 或脱敏 IP
ipEl.addEventListener('click', function() {
const fullIp = ipEl.dataset.fullIp;
// 还未获取到有效 IP 时不执行切换
if (!fullIp) return;
isMasked = !isMasked;
ipEl.textContent = isMasked ? maskIP(fullIp) : fullIp;
});
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', applyMask);
} else {
applyMask();
}
})();
</script>
版权声明:本文由 鹿泽笔记 原创发布。
本文链接:https://www.bailuze.com/26833.html
许可协议:本文标题《WordPress blocksy主题访客代码》,转载请注明文章出处及原始链接。
