mirror of
https://github.com/afoim/fuwari.git
synced 2026-01-31 09:03:18 +08:00
feat(安全): 添加域名检测脚本防止钓鱼网站
添加域名检测功能,当用户访问非官方域名时弹出警告并提示跳转至官方网站。主要检测当前域名是否与配置的官方域名一致,不一致时显示警告弹窗,用户可选择跳转或继续访问。
This commit is contained in:
@@ -199,6 +199,56 @@ var _hmt = _hmt || [];
|
||||
|
||||
<!-- increase the page height during page transition to prevent the scrolling animation from jumping -->
|
||||
<div id="page-height-extend" class="hidden h-[300vh]"></div>
|
||||
|
||||
<!-- 域名检测脚本 -->
|
||||
<script is:inline define:vars={{officialSite: "https://www.afo.im"}}>
|
||||
// 域名检测功能
|
||||
function checkDomain() {
|
||||
try {
|
||||
// 获取当前访问的完整URL
|
||||
const currentUrl = window.location.href;
|
||||
// 获取配置的官方网站URL
|
||||
const officialUrl = new URL(officialSite);
|
||||
// 获取当前域名
|
||||
const currentDomain = window.location.hostname;
|
||||
// 获取官方域名
|
||||
const officialDomain = officialUrl.hostname;
|
||||
|
||||
// 如果当前域名与官方域名不一致,且不是localhost(本地开发环境)
|
||||
if (currentDomain !== officialDomain && currentDomain !== 'localhost' && currentDomain !== '127.0.0.1') {
|
||||
// 创建警告弹窗
|
||||
const shouldRedirect = confirm(
|
||||
`⚠️ 域名安全警告\n\n` +
|
||||
`您当前访问的域名:${currentDomain}\n` +
|
||||
`官方域名:${officialDomain}\n\n` +
|
||||
`您可能正在访问非官方网站,存在安全风险!\n\n` +
|
||||
`点击"确定"跳转到官方网站\n` +
|
||||
`点击"取消"继续访问当前网站(不推荐)`
|
||||
);
|
||||
|
||||
// 如果用户选择跳转到官方网站
|
||||
if (shouldRedirect) {
|
||||
// 构建官方网站的对应页面URL
|
||||
const currentPath = window.location.pathname + window.location.search + window.location.hash;
|
||||
const officialPageUrl = officialSite + currentPath;
|
||||
// 跳转到官方网站
|
||||
window.location.href = officialPageUrl;
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
// 如果检测过程中出现错误,静默处理,不影响正常访问
|
||||
console.warn('域名检测失败:', error);
|
||||
}
|
||||
}
|
||||
|
||||
// 页面加载完成后执行域名检测
|
||||
if (document.readyState === 'loading') {
|
||||
document.addEventListener('DOMContentLoaded', checkDomain);
|
||||
} else {
|
||||
checkDomain();
|
||||
}
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user