修正无法取消 Devtools 的选项

修正无法取消 Devtools 的选项
新增无水印类型
This commit is contained in:
文派备案 2025-04-11 08:52:58 +08:00
parent f29d48fbdb
commit 00557b4d67
2 changed files with 37 additions and 31 deletions

View file

@ -7,7 +7,8 @@
const container = $('#lelms-watermark');
const username = lelmsData.username;
// 使用 Math.max 获取真实文档高度
if (!username) return;
const documentHeight = Math.max(
$(document).height(),
$(window).height(),
@ -22,7 +23,6 @@
const rows = Math.ceil(documentHeight / spacing);
const cols = Math.ceil(windowWidth / spacing);
// 使用文档片段优化性能
const fragment = document.createDocumentFragment();
for (let i = 0; i < rows; i++) {
for (let j = 0; j < cols; j++) {
@ -47,7 +47,6 @@
function preventDevTools() {
if (options.enable_devtools_protection !== 'yes') return;
// 优化的事件处理
document.addEventListener('keydown', function(e) {
if (e.key === 'F12' ||
(e.ctrlKey && e.shiftKey && e.key === 'I') ||
@ -58,7 +57,6 @@
}
});
// 改进的右键菜单处理
document.addEventListener('contextmenu', function(e) {
const target = e.target;
const allowedSelectors = [
@ -76,13 +74,12 @@
}
});
// 优化的开发者工具检测
let devToolsCounter = 0;
let lastCheck = Date.now();
const checkDevTools = () => {
const now = Date.now();
if (now - lastCheck < 800) return; // 防止过于频繁检查
if (now - lastCheck < 800) return;
lastCheck = now;
const threshold = 160;
@ -134,22 +131,25 @@
});
}
// 初始化
$(document).ready(function() {
preventDevTools();
addWatermark();
if (lelmsData.username) {
addWatermark();
}
preventCopy();
// 使用 ResizeObserver 监听尺寸变化
const resizeObserver = new ResizeObserver(_.debounce(() => {
addWatermark();
if (lelmsData.username) {
addWatermark();
}
}, 200));
resizeObserver.observe(document.body);
// 监听动态内容变化
const mutationObserver = new MutationObserver(_.debounce(() => {
addWatermark();
if (lelmsData.username) {
addWatermark();
}
}, 200));
mutationObserver.observe(document.body, {
@ -158,10 +158,9 @@
attributes: true
});
// 清理函数
$(window).on('unload', () => {
resizeObserver.disconnect();
mutationObserver.disconnect();
});
});
})(jQuery);
})(jQuery);