From 4324d886d8502841f4d113be58fdb90bbfe3df01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=96=BB=E5=8B=87=E7=A5=A5?= <237899745@qq.com> Date: Mon, 17 Nov 2025 20:33:01 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84=E5=BC=80=E5=8F=91=E8=80=85?= =?UTF-8?q?=E5=B7=A5=E5=85=B7=E6=A3=80=E6=B5=8B=E6=9C=BA=E5=88=B6=20-=20?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E5=A4=9A=E9=87=8D=E6=A3=80=E6=B5=8B=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复了控制台在其他页面打开后仍能在本站显示的问题。 核心改进: 1. 新增Console对象toString检测(最有效) 2. 优化debugger暂停时间检测 3. 保留窗口尺寸检测作为补充 4. 综合多种方法,提高检测准确率 5. 页面加载时立即执行检测 6. 持续监控确保实时防护 检测原理: - console.log会触发对象的toString方法 - 当控制台打开时,这个方法会被调用 - 通过标志位检测到调用,即可判断控制台已打开 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- frontend/app.html | 191 +++++++++++++++++++++++++--------------------- 1 file changed, 103 insertions(+), 88 deletions(-) diff --git a/frontend/app.html b/frontend/app.html index 198bc9a..adb879b 100644 --- a/frontend/app.html +++ b/frontend/app.html @@ -2251,104 +2251,119 @@ // 检测开发者工具是否打开(调试模式下不检测) if (!isDebugMode) { - (function() { - const threshold = 160; - let isDevToolsOpen = false; - let warningShown = false; + let devtoolsDetected = false; - // 增强型检测:结合窗口尺寸和debugger暂停 - function checkDevTools() { - const widthThreshold = window.outerWidth - window.innerWidth > threshold; - const heightThreshold = window.outerHeight - window.innerHeight > threshold; + // 方法1: 使用console对象检测 + const devtools = /./; + devtools.toString = function() { + devtoolsDetected = true; + }; - // 检测是否有开发者工具打开 - const isOpen = widthThreshold || heightThreshold || - (window.Firebug && window.Firebug.chrome && window.Firebug.chrome.isInitialized); - - if (isOpen && !isDevToolsOpen) { - isDevToolsOpen = true; - - if (!warningShown) { - warningShown = true; - - // 清空控制台 - console.clear(); - - // 显示警告页面 - const warningHTML = ` -
-
- -

检测到开发者工具

-

- 为保护系统安全,请关闭浏览器开发者工具后刷新页面 -

- -

- 如需使用开发者工具,请联系管理员开启调试模式 -

-
-
- `; - - // 替换页面内容 - document.body.innerHTML = warningHTML; - } - } else if (!isOpen) { - isDevToolsOpen = false; - } + // 方法2: debugger暂停时间检测 + function detectByDebugger() { + const start = performance.now(); + debugger; + const end = performance.now(); + return (end - start) > 100; // 如果暂停超过100ms,说明开发者工具打开 } - // 立即检测一次(页面加载时就检查) - checkDevTools(); + // 方法3: 窗口尺寸检测 + function detectByWindowSize() { + const threshold = 160; + const widthDiff = window.outerWidth - window.innerWidth; + const heightDiff = window.outerHeight - window.innerHeight; + return widthDiff > threshold || heightDiff > threshold; + } - // 定期检测 - setInterval(checkDevTools, 500); + // 方法4: 检测console.log是否被执行 + function detectByConsole() { + devtoolsDetected = false; + console.log(devtools); + console.clear(); + return devtoolsDetected; + } - // 使用debugger语句检测(更灵敏) + // 显示警告页面 + function showWarning() { + const warningHTML = ` +
+
+ +

检测到开发者工具

+

+ 为保护系统安全,请关闭浏览器开发者工具后刷新页面 +

+ +

+ 如需使用开发者工具,请联系管理员开启调试模式 +

+
+
+ `; + document.body.innerHTML = warningHTML; + } + + // 综合检测函数 + function checkDevTools() { + // 使用多种方法检测,任意一种检测到就触发 + const method1 = detectByConsole(); + const method2 = detectByDebugger(); + const method3 = detectByWindowSize(); + + if (method1 || method2 || method3) { + showWarning(); + return true; + } + return false; + } + + // 页面加载完成后立即检测 + if (document.readyState === 'loading') { + document.addEventListener('DOMContentLoaded', function() { + setTimeout(checkDevTools, 100); + }); + } else { + setTimeout(checkDevTools, 100); + } + + // 持续监控 setInterval(function() { - const before = new Date().getTime(); - debugger; // 如果开发者工具打开,这里会暂停 - const after = new Date().getTime(); - - // 如果暂停时间超过100ms,说明开发者工具打开了 - if (after - before > 100) { + if (!document.body.innerHTML.includes('检测到开发者工具')) { checkDevTools(); } }, 1000); - })(); } // 禁用console输出(调试模式下不禁用)