增强开发者工具检测防护功能
修复了用户可以在其他页面先打开F12控制台,然后访问网站时绕过禁用的问题。 主要改进: - 页面加载时立即检测开发者工具是否已打开 - 新增 debugger 断点检测机制,检测更灵敏 - 检测到开发者工具时显示美观的全屏警告页面 - 防止重复警告显示 - 调试模式下所有保护机制自动禁用 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -2254,24 +2254,100 @@
|
|||||||
(function() {
|
(function() {
|
||||||
const threshold = 160;
|
const threshold = 160;
|
||||||
let isDevToolsOpen = false;
|
let isDevToolsOpen = false;
|
||||||
|
let warningShown = false;
|
||||||
|
|
||||||
setInterval(function() {
|
// 增强型检测:结合窗口尺寸和debugger暂停
|
||||||
|
function checkDevTools() {
|
||||||
const widthThreshold = window.outerWidth - window.innerWidth > threshold;
|
const widthThreshold = window.outerWidth - window.innerWidth > threshold;
|
||||||
const heightThreshold = window.outerHeight - window.innerHeight > threshold;
|
const heightThreshold = window.outerHeight - window.innerHeight > threshold;
|
||||||
const orientation = widthThreshold ? 'vertical' : 'horizontal';
|
|
||||||
|
|
||||||
if (!(heightThreshold && widthThreshold) &&
|
// 检测是否有开发者工具打开
|
||||||
((window.Firebug && window.Firebug.chrome && window.Firebug.chrome.isInitialized) || widthThreshold || heightThreshold)) {
|
const isOpen = widthThreshold || heightThreshold ||
|
||||||
if (!isDevToolsOpen) {
|
(window.Firebug && window.Firebug.chrome && window.Firebug.chrome.isInitialized);
|
||||||
|
|
||||||
|
if (isOpen && !isDevToolsOpen) {
|
||||||
isDevToolsOpen = true;
|
isDevToolsOpen = true;
|
||||||
// 检测到开发者工具打开,可以选择清空页面或重定向
|
|
||||||
// document.body.innerHTML = '<h1 style="text-align:center;margin-top:20%;">请关闭开发者工具</h1>';
|
if (!warningShown) {
|
||||||
|
warningShown = true;
|
||||||
|
|
||||||
|
// 清空控制台
|
||||||
console.clear();
|
console.clear();
|
||||||
|
|
||||||
|
// 显示警告页面
|
||||||
|
const warningHTML = `
|
||||||
|
<div style="
|
||||||
|
position: fixed;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
z-index: 999999;
|
||||||
|
font-family: Arial, sans-serif;
|
||||||
|
">
|
||||||
|
<div style="
|
||||||
|
background: white;
|
||||||
|
padding: 60px;
|
||||||
|
border-radius: 20px;
|
||||||
|
text-align: center;
|
||||||
|
max-width: 500px;
|
||||||
|
box-shadow: 0 20px 60px rgba(0,0,0,0.3);
|
||||||
|
">
|
||||||
|
<i class="fas fa-shield-alt" style="font-size: 80px; color: #667eea; margin-bottom: 30px;"></i>
|
||||||
|
<h1 style="color: #333; margin-bottom: 20px; font-size: 32px;">检测到开发者工具</h1>
|
||||||
|
<p style="color: #666; font-size: 18px; margin-bottom: 30px; line-height: 1.6;">
|
||||||
|
为保护系统安全,请关闭浏览器开发者工具后刷新页面
|
||||||
|
</p>
|
||||||
|
<button onclick="location.reload()" style="
|
||||||
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||||
|
color: white;
|
||||||
|
border: none;
|
||||||
|
padding: 15px 40px;
|
||||||
|
font-size: 16px;
|
||||||
|
border-radius: 10px;
|
||||||
|
cursor: pointer;
|
||||||
|
font-weight: 600;
|
||||||
|
box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
|
||||||
|
transition: transform 0.2s;
|
||||||
|
" onmouseover="this.style.transform='translateY(-2px)'" onmouseout="this.style.transform='translateY(0)'">
|
||||||
|
<i class="fas fa-sync-alt"></i> 刷新页面
|
||||||
|
</button>
|
||||||
|
<p style="color: #999; font-size: 14px; margin-top: 20px;">
|
||||||
|
如需使用开发者工具,请联系管理员开启调试模式
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
|
||||||
|
// 替换页面内容
|
||||||
|
document.body.innerHTML = warningHTML;
|
||||||
}
|
}
|
||||||
} else {
|
} else if (!isOpen) {
|
||||||
isDevToolsOpen = false;
|
isDevToolsOpen = false;
|
||||||
}
|
}
|
||||||
}, 500);
|
}
|
||||||
|
|
||||||
|
// 立即检测一次(页面加载时就检查)
|
||||||
|
checkDevTools();
|
||||||
|
|
||||||
|
// 定期检测
|
||||||
|
setInterval(checkDevTools, 500);
|
||||||
|
|
||||||
|
// 使用debugger语句检测(更灵敏)
|
||||||
|
setInterval(function() {
|
||||||
|
const before = new Date().getTime();
|
||||||
|
debugger; // 如果开发者工具打开,这里会暂停
|
||||||
|
const after = new Date().getTime();
|
||||||
|
|
||||||
|
// 如果暂停时间超过100ms,说明开发者工具打开了
|
||||||
|
if (after - before > 100) {
|
||||||
|
checkDevTools();
|
||||||
|
}
|
||||||
|
}, 1000);
|
||||||
})();
|
})();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user