Files
est-frame/DisableCopy.js
2025-10-22 05:38:27 +00:00

36 lines
1.0 KiB
JavaScript
Executable File

import React, { useEffect } from 'react';
const DisableCopy = () => {
useEffect(() => {
// 禁止复制事件
const disableCopy = (event) => {
event.preventDefault();
alert('版权所有 © EST 禁止复制 非法必究');
};
// 添加禁止复制事件监听器
document.addEventListener('copy', disableCopy);
// 禁止文本选择
const disableTextSelection = () => {
if (typeof window.getSelection !== 'undefined') {
window.getSelection().removeAllRanges();
} else if (typeof document.selection !== 'undefined') {
document.selection.empty();
}
};
// 添加禁止文本选择事件监听器
document.addEventListener('selectstart', disableTextSelection);
return () => {
// 移除事件监听器
document.removeEventListener('copy', disableCopy);
document.removeEventListener('selectstart', disableTextSelection);
};
}, []);
return null;
};
export default DisableCopy;