使用方法
复制代码到你想要添加的小工具位置,选择自定义HTML代码,粘贴进去保存即可(推荐放在侧边栏)
![图片[1]-子比美化-侧边栏添加用户UA信息-玩转网](https://www.902d.com/wp-content/uploads/2025/09/ffe29b340020250915233820.webp)
<div class="ua-info-widget" style="border: 1px solid #333; border-radius: 10px; padding: 15px; box-shadow: 0 3px 10px rgba(0,0,0,0.2); background-color: #1a1a1a; color: #f0f0f0; max-width: 300px; transition: all 0.3s ease;">
<h3 style="margin-top: 0; color: #ffffff; border-bottom: 1px solid #444; padding-bottom: 10px; font-size: 16px; font-family: Arial, sans-serif;">设备信息</h3>
<div id="ua-loading" style="color: #bbb; padding: 10px 0; font-size: 14px;">加载中...</div>
<ul id="ua-info-list" style="display: none; list-style: none; padding: 0; margin: 10px 0;">
<li style="padding: 6px 0; border-bottom: 1px dashed #444; font-size: 14px; font-family: Arial, sans-serif;"><strong style="color: #81c3ff; min-width: 65px; display: inline-block;">IP:</strong> <span id="ua-ip" style="color: #f0f0f0;"></span></li>
<li style="padding: 6px 0; border-bottom: 1px dashed #444; font-size: 14px; font-family: Arial, sans-serif;"><strong style="color: #81c3ff; min-width: 65px; display: inline-block;">位置:</strong> <span id="ua-address" style="color: #f0f0f0;"></span></li>
<li style="padding: 6px 0; border-bottom: 1px dashed #444; font-size: 14px; font-family: Arial, sans-serif;"><strong style="color: #81c3ff; min-width: 65px; display: inline-block;">浏览器:</strong> <span id="ua-browser" style="color: #f0f0f0;"></span></li>
<li style="padding: 6px 0; border-bottom: 1px dashed #444; font-size: 14px; font-family: Arial, sans-serif;"><strong style="color: #81c3ff; min-width: 65px; display: inline-block;">系统:</strong> <span id="ua-os" style="color: #f0f0f0;"></span></li>
<li style="padding: 6px 0; font-size: 14px; font-family: Arial, sans-serif;"><strong style="color: #81c3ff; min-width: 65px; display: inline-block;">设备:</strong> <span id="ua-device" style="color: #f0f0f0;"></span></li>
</ul>
<div id="ua-error" style="display: none; color: #ff6b6b; font-size: 14px; padding: 10px; background-color: #2d1b1b; border-radius: 6px; border: 1px solid #4a2727;"></div>
</div>
<script>
// 检测系统是否偏好暗色模式并适配
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: light)').matches) {
// 如果是亮色模式,调整样式
document.querySelector('.ua-info-widget').style.backgroundColor = '#ffffff';
document.querySelector('.ua-info-widget').style.color = '#333';
document.querySelector('.ua-info-widget').style.borderColor = '#e0e0e0';
// 调整文本颜色
const textElements = document.querySelectorAll('#ua-info-list span');
textElements.forEach(el => {
el.style.color = '#333';
});
// 调整标题和分隔线
document.querySelector('.ua-info-widget h3').style.color = '#333';
document.querySelector('.ua-info-widget h3').style.borderBottomColor = '#f0f0f0';
// 调整加载状态
document.getElementById('ua-loading').style.color = '#666';
}
// 获取UA信息
fetch('https://v2.xxapi.cn/api/ua')
.then(response => {
if (!response.ok) {
throw new Error('网络响应不正常');
}
return response.json();
})
.then(data => {
document.getElementById('ua-loading').style.display = 'none';
if (data.code === 200 && data.data) {
document.getElementById('ua-info-list').style.display = 'block';
document.getElementById('ua-ip').textContent = data.data.ip || '未知';
document.getElementById('ua-address').textContent = data.data.address || '未知';
document.getElementById('ua-browser').textContent =
(data.data.browser || '未知') + ' ' + (data.data.browserVersion || '');
document.getElementById('ua-os').textContent = data.data.os || '未知';
document.getElementById('ua-device').textContent = data.data.deviceType || '未知';
} else {
document.getElementById('ua-error').textContent = data.msg || '获取信息失败';
document.getElementById('ua-error').style.display = 'block';
}
})
.catch(error => {
document.getElementById('ua-loading').style.display = 'none';
document.getElementById('ua-error').textContent = '加载失败: ' + error.message;
document.getElementById('ua-error').style.display = 'block';
});
</script>
© 版权声明
网站名称:玩转网
本文链接:
版权声明:知识共享署名-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)协议进行许可
本站资源仅供个人学习交流,转载时请以超链接形式标明文章原始出处,(如有侵权联系删除)
本站代码模板仅供学习交流使用请勿商业运营,严禁从事违法,侵权等任何非法活动,否则后果自负!
THE END



![子比主题论坛系统以及全新V6开发进度汇报[更新预告]-玩转网](https://www.902d.com/wp-content/uploads/2021/10/2021101910243451.png)







