feat: 添加管理员可控的F12调试模式开关

## 功能说明
- 管理员登录后可在管理后台页面看到"调试模式"卡片
- 点击开关按钮可启用/禁用F12和开发者工具
- 调试模式状态保存在localStorage,页面刷新后保持
- 同时控制主应用(app.html)和分享页面(share.html)的调试权限

## 技术实现
1. app.js新增debugMode配置和toggleDebugMode方法
2. app.html添加调试模式开关UI,并修改防调试代码支持debugMode控制
3. share.html添加防调试代码,受localStorage中的debugMode控制

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-11-14 16:04:17 +08:00
parent 024e807f75
commit bce225ec5c
3 changed files with 145 additions and 13 deletions

View File

@@ -885,5 +885,81 @@
}
}).mount('#app');
</script>
<script>
// 检查是否启用调试模式
const isDebugMode = localStorage.getItem('debugMode') === 'true';
// 禁用右键菜单(调试模式下不禁用)
if (!isDebugMode) {
document.addEventListener('contextmenu', function(e) {
e.preventDefault();
return false;
});
}
// 禁用F12和常见开发者工具快捷键调试模式下不禁用
if (!isDebugMode) {
document.addEventListener('keydown', function(e) {
// F12
if (e.key === 'F12' || e.keyCode === 123) {
e.preventDefault();
return false;
}
// Ctrl+Shift+I (开发者工具)
if (e.ctrlKey && e.shiftKey && (e.key === 'I' || e.keyCode === 73)) {
e.preventDefault();
return false;
}
// Ctrl+Shift+J (控制台)
if (e.ctrlKey && e.shiftKey && (e.key === 'J' || e.keyCode === 74)) {
e.preventDefault();
return false;
}
// Ctrl+U (查看源代码)
if (e.ctrlKey && (e.key === 'U' || e.keyCode === 85)) {
e.preventDefault();
return false;
}
// Ctrl+Shift+C (元素选择器)
if (e.ctrlKey && e.shiftKey && (e.key === 'C' || e.keyCode === 67)) {
e.preventDefault();
return false;
}
});
}
// 检测开发者工具是否打开(调试模式下不检测)
if (!isDebugMode) {
(function() {
const threshold = 160;
let isDevToolsOpen = false;
setInterval(function() {
const widthThreshold = window.outerWidth - window.innerWidth > threshold;
const heightThreshold = window.outerHeight - window.innerHeight > threshold;
if (!(heightThreshold && widthThreshold) &&
((window.Firebug && window.Firebug.chrome && window.Firebug.chrome.isInitialized) || widthThreshold || heightThreshold)) {
if (!isDevToolsOpen) {
isDevToolsOpen = true;
console.clear();
}
} else {
isDevToolsOpen = false;
}
}, 500);
})();
}
// 禁用console输出调试模式下不禁用
if (!isDebugMode && window.location.hostname !== 'localhost' && window.location.hostname !== '127.0.0.1') {
console.log = function() {};
console.info = function() {};
console.warn = function() {};
console.error = function() {};
console.debug = function() {};
}
</script>
</body>
</html>