File size: 592 Bytes
1b72d7e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
import { siteConfig } from '@/lib/config'
import { useEffect } from 'react'
/**
* 禁止用户拷贝文章的插件
*/
export default function DisableCopy() {
useEffect(() => {
if (!JSON.parse(siteConfig('CAN_COPY'))) {
// 全栈添加禁止复制的样式
document.getElementsByTagName('html')[0].classList.add('forbid-copy')
// 监听复制事件
document.addEventListener('copy', function (event) {
event.preventDefault() // 阻止默认复制行为
alert('抱歉,本网页内容不可复制!')
})
}
}, [])
return null
}
|