mirror of
https://github.com/WenPai-org/lelms-copyright.git
synced 2025-08-03 04:08:45 +08:00
修正无法取消 Devtools 的选项
修正无法取消 Devtools 的选项 新增无水印类型
This commit is contained in:
parent
f29d48fbdb
commit
00557b4d67
2 changed files with 37 additions and 31 deletions
|
@ -7,7 +7,8 @@
|
||||||
const container = $('#lelms-watermark');
|
const container = $('#lelms-watermark');
|
||||||
const username = lelmsData.username;
|
const username = lelmsData.username;
|
||||||
|
|
||||||
// 使用 Math.max 获取真实文档高度
|
if (!username) return;
|
||||||
|
|
||||||
const documentHeight = Math.max(
|
const documentHeight = Math.max(
|
||||||
$(document).height(),
|
$(document).height(),
|
||||||
$(window).height(),
|
$(window).height(),
|
||||||
|
@ -22,7 +23,6 @@
|
||||||
const rows = Math.ceil(documentHeight / spacing);
|
const rows = Math.ceil(documentHeight / spacing);
|
||||||
const cols = Math.ceil(windowWidth / spacing);
|
const cols = Math.ceil(windowWidth / spacing);
|
||||||
|
|
||||||
// 使用文档片段优化性能
|
|
||||||
const fragment = document.createDocumentFragment();
|
const fragment = document.createDocumentFragment();
|
||||||
for (let i = 0; i < rows; i++) {
|
for (let i = 0; i < rows; i++) {
|
||||||
for (let j = 0; j < cols; j++) {
|
for (let j = 0; j < cols; j++) {
|
||||||
|
@ -47,7 +47,6 @@
|
||||||
function preventDevTools() {
|
function preventDevTools() {
|
||||||
if (options.enable_devtools_protection !== 'yes') return;
|
if (options.enable_devtools_protection !== 'yes') return;
|
||||||
|
|
||||||
// 优化的事件处理
|
|
||||||
document.addEventListener('keydown', function(e) {
|
document.addEventListener('keydown', function(e) {
|
||||||
if (e.key === 'F12' ||
|
if (e.key === 'F12' ||
|
||||||
(e.ctrlKey && e.shiftKey && e.key === 'I') ||
|
(e.ctrlKey && e.shiftKey && e.key === 'I') ||
|
||||||
|
@ -58,7 +57,6 @@
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// 改进的右键菜单处理
|
|
||||||
document.addEventListener('contextmenu', function(e) {
|
document.addEventListener('contextmenu', function(e) {
|
||||||
const target = e.target;
|
const target = e.target;
|
||||||
const allowedSelectors = [
|
const allowedSelectors = [
|
||||||
|
@ -76,13 +74,12 @@
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// 优化的开发者工具检测
|
|
||||||
let devToolsCounter = 0;
|
let devToolsCounter = 0;
|
||||||
let lastCheck = Date.now();
|
let lastCheck = Date.now();
|
||||||
|
|
||||||
const checkDevTools = () => {
|
const checkDevTools = () => {
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
if (now - lastCheck < 800) return; // 防止过于频繁检查
|
if (now - lastCheck < 800) return;
|
||||||
lastCheck = now;
|
lastCheck = now;
|
||||||
|
|
||||||
const threshold = 160;
|
const threshold = 160;
|
||||||
|
@ -134,22 +131,25 @@
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// 初始化
|
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
preventDevTools();
|
preventDevTools();
|
||||||
addWatermark();
|
if (lelmsData.username) {
|
||||||
|
addWatermark();
|
||||||
|
}
|
||||||
preventCopy();
|
preventCopy();
|
||||||
|
|
||||||
// 使用 ResizeObserver 监听尺寸变化
|
|
||||||
const resizeObserver = new ResizeObserver(_.debounce(() => {
|
const resizeObserver = new ResizeObserver(_.debounce(() => {
|
||||||
addWatermark();
|
if (lelmsData.username) {
|
||||||
|
addWatermark();
|
||||||
|
}
|
||||||
}, 200));
|
}, 200));
|
||||||
|
|
||||||
resizeObserver.observe(document.body);
|
resizeObserver.observe(document.body);
|
||||||
|
|
||||||
// 监听动态内容变化
|
|
||||||
const mutationObserver = new MutationObserver(_.debounce(() => {
|
const mutationObserver = new MutationObserver(_.debounce(() => {
|
||||||
addWatermark();
|
if (lelmsData.username) {
|
||||||
|
addWatermark();
|
||||||
|
}
|
||||||
}, 200));
|
}, 200));
|
||||||
|
|
||||||
mutationObserver.observe(document.body, {
|
mutationObserver.observe(document.body, {
|
||||||
|
@ -158,10 +158,9 @@
|
||||||
attributes: true
|
attributes: true
|
||||||
});
|
});
|
||||||
|
|
||||||
// 清理函数
|
|
||||||
$(window).on('unload', () => {
|
$(window).on('unload', () => {
|
||||||
resizeObserver.disconnect();
|
resizeObserver.disconnect();
|
||||||
mutationObserver.disconnect();
|
mutationObserver.disconnect();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
})(jQuery);
|
})(jQuery);
|
|
@ -3,7 +3,7 @@
|
||||||
* Plugin Name: LeLMS Copyright
|
* Plugin Name: LeLMS Copyright
|
||||||
* Plugin URI: https://wenpai.org/plugins/lelms-copyright
|
* Plugin URI: https://wenpai.org/plugins/lelms-copyright
|
||||||
* Description: Adds watermark with username and prevents unauthorized screenshots
|
* Description: Adds watermark with username and prevents unauthorized screenshots
|
||||||
* Version: 1.1.7
|
* Version: 1.1.8
|
||||||
* Author: LeLMS.com
|
* Author: LeLMS.com
|
||||||
* Author URI: https://lelms.com
|
* Author URI: https://lelms.com
|
||||||
* License: GPL v2 or later
|
* License: GPL v2 or later
|
||||||
|
@ -18,7 +18,7 @@ if (!defined('ABSPATH')) {
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
define('LELMS_COPYRIGHT_VERSION', '1.1.7');
|
define('LELMS_COPYRIGHT_VERSION', '1.1.8');
|
||||||
define('LELMS_COPYRIGHT_DIR_URL', plugin_dir_url(__FILE__));
|
define('LELMS_COPYRIGHT_DIR_URL', plugin_dir_url(__FILE__));
|
||||||
define('LELMS_COPYRIGHT_DIR_PATH', plugin_dir_path(__FILE__));
|
define('LELMS_COPYRIGHT_DIR_PATH', plugin_dir_path(__FILE__));
|
||||||
define('LELMS_COPYRIGHT_BASENAME', plugin_basename(__FILE__));
|
define('LELMS_COPYRIGHT_BASENAME', plugin_basename(__FILE__));
|
||||||
|
@ -78,11 +78,11 @@ class LELMS_Copyright {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function register_settings() {
|
public function register_settings() {
|
||||||
if (!isset($_GET['page']) || $_GET['page'] !== 'lelms-copyright') {
|
register_setting('lelms_copyright', 'lelms_copyright_options', array($this, 'sanitize_options'));
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
register_setting('lelms_copyright', 'lelms_copyright_options', array($this, 'sanitize_options'));
|
if (!isset($_GET['page']) || $_GET['page'] !== 'lelms-copyright') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
add_settings_section(
|
add_settings_section(
|
||||||
'lelms_copyright_section',
|
'lelms_copyright_section',
|
||||||
|
@ -135,7 +135,7 @@ class LELMS_Copyright {
|
||||||
$sanitized['watermark_spacing'] = absint($input['watermark_spacing']);
|
$sanitized['watermark_spacing'] = absint($input['watermark_spacing']);
|
||||||
$sanitized['watermark_color'] = sanitize_hex_color($input['watermark_color']);
|
$sanitized['watermark_color'] = sanitize_hex_color($input['watermark_color']);
|
||||||
$sanitized['watermark_angle'] = intval($input['watermark_angle']);
|
$sanitized['watermark_angle'] = intval($input['watermark_angle']);
|
||||||
$sanitilized['enable_devtools_protection'] = isset($input['enable_devtools_protection']) && $input['enable_devtools_protection'] === 'yes' ? 'yes' : 'no';
|
$sanitized['enable_devtools_protection'] = isset($input['enable_devtools_protection']) && $input['enable_devtools_protection'] === 'yes' ? 'yes' : 'no';
|
||||||
$sanitized['enable_print_protection'] = isset($input['enable_print_protection']) && $input['enable_print_protection'] === 'yes' ? 'yes' : 'no';
|
$sanitized['enable_print_protection'] = isset($input['enable_print_protection']) && $input['enable_print_protection'] === 'yes' ? 'yes' : 'no';
|
||||||
$sanitized['enable_copy_protection'] = isset($input['enable_copy_protection']) && $input['enable_copy_protection'] === 'yes' ? 'yes' : 'no';
|
$sanitized['enable_copy_protection'] = isset($input['enable_copy_protection']) && $input['enable_copy_protection'] === 'yes' ? 'yes' : 'no';
|
||||||
$sanitized['enable_for_guests'] = isset($input['enable_for_guests']) && $input['enable_for_guests'] === 'yes' ? 'yes' : 'no';
|
$sanitized['enable_for_guests'] = isset($input['enable_for_guests']) && $input['enable_for_guests'] === 'yes' ? 'yes' : 'no';
|
||||||
|
@ -143,7 +143,7 @@ class LELMS_Copyright {
|
||||||
$sanitized['enable_guest_custom_watermark'] = isset($input['enable_guest_custom_watermark']) && $input['enable_guest_custom_watermark'] === 'yes' ? 'yes' : 'no';
|
$sanitized['enable_guest_custom_watermark'] = isset($input['enable_guest_custom_watermark']) && $input['enable_guest_custom_watermark'] === 'yes' ? 'yes' : 'no';
|
||||||
$sanitized['enable_custom_watermark'] = isset($input['enable_custom_watermark']) && $input['enable_custom_watermark'] === 'yes' ? 'yes' : 'no';
|
$sanitized['enable_custom_watermark'] = isset($input['enable_custom_watermark']) && $input['enable_custom_watermark'] === 'yes' ? 'yes' : 'no';
|
||||||
$sanitized['custom_watermark_text'] = sanitize_text_field($input['custom_watermark_text']);
|
$sanitized['custom_watermark_text'] = sanitize_text_field($input['custom_watermark_text']);
|
||||||
$sanitized['watermark_type'] = in_array($input['watermark_type'], ['username', 'nickname', 'email', 'timestamp']) ? $input['watermark_type'] : 'username';
|
$sanitized['watermark_type'] = in_array($input['watermark_type'], ['none', 'username', 'nickname', 'email', 'timestamp']) ? $input['watermark_type'] : 'username';
|
||||||
$sanitized['excluded_post_types'] = array_map('sanitize_key', (array) $input['excluded_post_types']);
|
$sanitized['excluded_post_types'] = array_map('sanitize_key', (array) $input['excluded_post_types']);
|
||||||
$sanitized['excluded_roles'] = array_map('sanitize_key', (array) $input['excluded_roles']);
|
$sanitized['excluded_roles'] = array_map('sanitize_key', (array) $input['excluded_roles']);
|
||||||
|
|
||||||
|
@ -151,11 +151,6 @@ class LELMS_Copyright {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function should_apply_protection() {
|
public function should_apply_protection() {
|
||||||
$enable_for_guests = $this->options['enable_for_guests'] === 'yes';
|
|
||||||
if (!is_user_logged_in() && !$enable_for_guests) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$user = wp_get_current_user();
|
$user = wp_get_current_user();
|
||||||
$user_roles = $user && $user->roles ? $user->roles : array('guest');
|
$user_roles = $user && $user->roles ? $user->roles : array('guest');
|
||||||
if (array_intersect($user_roles, (array) $this->options['excluded_roles'])) {
|
if (array_intersect($user_roles, (array) $this->options['excluded_roles'])) {
|
||||||
|
@ -167,6 +162,10 @@ class LELMS_Copyright {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!is_user_logged_in()) {
|
||||||
|
return $this->options['enable_for_guests'] === 'yes';
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -175,12 +174,16 @@ class LELMS_Copyright {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($this->options['watermark_type'] === 'none' && $this->options['enable_custom_watermark'] !== 'yes') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
$is_guest = !is_user_logged_in();
|
$is_guest = !is_user_logged_in();
|
||||||
if ($is_guest) {
|
if ($is_guest) {
|
||||||
return $this->options['enable_for_guests'] === 'yes' && $this->options['enable_guest_custom_watermark'] === 'yes';
|
return $this->options['enable_for_guests'] === 'yes' && $this->options['enable_guest_custom_watermark'] === 'yes';
|
||||||
} else {
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function add_watermark_container() {
|
public function add_watermark_container() {
|
||||||
|
@ -222,6 +225,7 @@ class LELMS_Copyright {
|
||||||
'type' => 'select',
|
'type' => 'select',
|
||||||
'description' => __('Choose the type of watermark to display for logged-in users (overridden by custom watermark if enabled).', 'lelms-copyright'),
|
'description' => __('Choose the type of watermark to display for logged-in users (overridden by custom watermark if enabled).', 'lelms-copyright'),
|
||||||
'options' => array(
|
'options' => array(
|
||||||
|
'none' => __('No Watermark', 'lelms-copyright'),
|
||||||
'username' => __('Username', 'lelms-copyright'),
|
'username' => __('Username', 'lelms-copyright'),
|
||||||
'nickname' => __('Nickname', 'lelms-copyright'),
|
'nickname' => __('Nickname', 'lelms-copyright'),
|
||||||
'email' => __('Email', 'lelms-copyright'),
|
'email' => __('Email', 'lelms-copyright'),
|
||||||
|
@ -412,7 +416,7 @@ class LELMS_Copyright {
|
||||||
</div>
|
</div>
|
||||||
<div id="about-tab" class="lelms-tab-content" style="display: none;">
|
<div id="about-tab" class="lelms-tab-content" style="display: none;">
|
||||||
<h3><?php esc_html_e('How to Use LeLMS Copyright', 'lelms-copyright'); ?></h3>
|
<h3><?php esc_html_e('How to Use LeLMS Copyright', 'lelms-copyright'); ?></h3>
|
||||||
<p><?php esc_html_e('This plugin adds a watermark and protection features to your WordPress site. Here’s how to configure it:', 'lelms-copyright'); ?></p>
|
<p><?php esc_html_e('This plugin adds a watermark and protection features to your WordPress site. Here\'s how to configure it:', 'lelms-copyright'); ?></p>
|
||||||
<ul style="list-style: decimal; padding-left: 2em;">
|
<ul style="list-style: decimal; padding-left: 2em;">
|
||||||
<li><?php esc_html_e('Watermark Settings: Adjust opacity, size, spacing, color, and angle.', 'lelms-copyright'); ?></li>
|
<li><?php esc_html_e('Watermark Settings: Adjust opacity, size, spacing, color, and angle.', 'lelms-copyright'); ?></li>
|
||||||
<li><?php esc_html_e('Protection Features: Enable options to block DevTools, printing, and copying.', 'lelms-copyright'); ?></li>
|
<li><?php esc_html_e('Protection Features: Enable options to block DevTools, printing, and copying.', 'lelms-copyright'); ?></li>
|
||||||
|
@ -564,6 +568,9 @@ class LELMS_Copyright {
|
||||||
$watermark_text = !empty($this->options['custom_watermark_text']) ? $this->options['custom_watermark_text'] : 'LeLMS Copyright';
|
$watermark_text = !empty($this->options['custom_watermark_text']) ? $this->options['custom_watermark_text'] : 'LeLMS Copyright';
|
||||||
} else {
|
} else {
|
||||||
switch ($this->options['watermark_type']) {
|
switch ($this->options['watermark_type']) {
|
||||||
|
case 'none':
|
||||||
|
$watermark_text = '';
|
||||||
|
break;
|
||||||
case 'username':
|
case 'username':
|
||||||
$watermark_text = $user ? '@' . $user->user_login : '';
|
$watermark_text = $user ? '@' . $user->user_login : '';
|
||||||
break;
|
break;
|
||||||
|
@ -629,4 +636,4 @@ $lelmsUpdateChecker = PucFactory::buildUpdateChecker(
|
||||||
'https://updates.weixiaoduo.com/lelms-copyright.json',
|
'https://updates.weixiaoduo.com/lelms-copyright.json',
|
||||||
__FILE__,
|
__FILE__,
|
||||||
'lelms-copyright'
|
'lelms-copyright'
|
||||||
);
|
);
|
Loading…
Add table
Add a link
Reference in a new issue