mirror of
https://github.com/WenPai-org/lelms-copyright.git
synced 2025-08-03 04:08:45 +08:00
166 lines
No EOL
5.1 KiB
JavaScript
166 lines
No EOL
5.1 KiB
JavaScript
(function($) {
|
|
'use strict';
|
|
|
|
const options = lelmsData.options;
|
|
|
|
function addWatermark() {
|
|
const container = $('#lelms-watermark');
|
|
const username = lelmsData.username;
|
|
|
|
if (!username) return;
|
|
|
|
const documentHeight = Math.max(
|
|
$(document).height(),
|
|
$(window).height(),
|
|
$('body').height(),
|
|
$('.site-content').height() || 0
|
|
);
|
|
const windowWidth = $(window).width();
|
|
|
|
container.empty().css('height', documentHeight + 'px');
|
|
|
|
const spacing = parseInt(options.watermark_spacing);
|
|
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++) {
|
|
const watermark = $('<div>', {
|
|
class: 'watermark-text',
|
|
text: username,
|
|
css: {
|
|
left: (j * spacing) + 'px',
|
|
top: (i * spacing) + 'px',
|
|
color: options.watermark_color,
|
|
opacity: options.watermark_opacity,
|
|
fontSize: options.watermark_size + 'px',
|
|
transform: `rotate(${options.watermark_angle}deg)`
|
|
}
|
|
})[0];
|
|
fragment.appendChild(watermark);
|
|
}
|
|
}
|
|
container[0].appendChild(fragment);
|
|
}
|
|
|
|
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') ||
|
|
(e.ctrlKey && e.key === 'U')) {
|
|
e.preventDefault();
|
|
alert(lelmsData.warningMessage);
|
|
return false;
|
|
}
|
|
});
|
|
|
|
document.addEventListener('contextmenu', function(e) {
|
|
const target = e.target;
|
|
const allowedSelectors = [
|
|
'input', 'textarea', 'select',
|
|
'[contenteditable="true"]',
|
|
'.comment-form *',
|
|
'.wp-block-post-comments *',
|
|
'.wp-block-post-comments-form *',
|
|
'form *'
|
|
].join(',');
|
|
|
|
if (!target.matches(allowedSelectors)) {
|
|
e.preventDefault();
|
|
return false;
|
|
}
|
|
});
|
|
|
|
let devToolsCounter = 0;
|
|
let lastCheck = Date.now();
|
|
|
|
const checkDevTools = () => {
|
|
const now = Date.now();
|
|
if (now - lastCheck < 800) return;
|
|
lastCheck = now;
|
|
|
|
const threshold = 160;
|
|
const widthDiff = window.outerWidth - window.innerWidth;
|
|
const heightDiff = window.outerHeight - window.innerHeight;
|
|
|
|
if (widthDiff > threshold || heightDiff > threshold) {
|
|
devToolsCounter++;
|
|
if (devToolsCounter > 3) {
|
|
alert(lelmsData.warningMessage);
|
|
setTimeout(() => location.reload(), 100);
|
|
}
|
|
} else {
|
|
devToolsCounter = Math.max(0, devToolsCounter - 1);
|
|
}
|
|
};
|
|
|
|
const rafLoop = () => {
|
|
checkDevTools();
|
|
requestAnimationFrame(rafLoop);
|
|
};
|
|
requestAnimationFrame(rafLoop);
|
|
}
|
|
|
|
function preventCopy() {
|
|
if (options.enable_copy_protection !== 'yes') return;
|
|
|
|
const allowedSelectors = [
|
|
'input', 'textarea',
|
|
'[contenteditable="true"]',
|
|
'.comment-form *',
|
|
'.wp-block-post-comments *',
|
|
'.wp-block-post-comments-form *',
|
|
'form *'
|
|
].join(',');
|
|
|
|
document.addEventListener('copy', function(e) {
|
|
if (!e.target.matches(allowedSelectors)) {
|
|
e.preventDefault();
|
|
return false;
|
|
}
|
|
});
|
|
|
|
document.addEventListener('selectstart', function(e) {
|
|
if (!e.target.matches(allowedSelectors)) {
|
|
e.preventDefault();
|
|
return false;
|
|
}
|
|
});
|
|
}
|
|
|
|
$(document).ready(function() {
|
|
preventDevTools();
|
|
if (lelmsData.username) {
|
|
addWatermark();
|
|
}
|
|
preventCopy();
|
|
|
|
const resizeObserver = new ResizeObserver(_.debounce(() => {
|
|
if (lelmsData.username) {
|
|
addWatermark();
|
|
}
|
|
}, 200));
|
|
|
|
resizeObserver.observe(document.body);
|
|
|
|
const mutationObserver = new MutationObserver(_.debounce(() => {
|
|
if (lelmsData.username) {
|
|
addWatermark();
|
|
}
|
|
}, 200));
|
|
|
|
mutationObserver.observe(document.body, {
|
|
childList: true,
|
|
subtree: true,
|
|
attributes: true
|
|
});
|
|
|
|
$(window).on('unload', () => {
|
|
resizeObserver.disconnect();
|
|
mutationObserver.disconnect();
|
|
});
|
|
});
|
|
})(jQuery); |