diff --git a/blog.config.js b/blog.config.js
index 32e80f10..3a7cc530 100644
--- a/blog.config.js
+++ b/blog.config.js
@@ -83,7 +83,7 @@ const BLOG = {
FONT_AWESOME: process.env.NEXT_PUBLIC_FONT_AWESOME_PATH || 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css', // font-awesome 字体图标地址; 可选 /css/all.min.css , https://lf9-cdn-tos.bytecdntp.com/cdn/expire-1-M/font-awesome/6.0.0/css/all.min.css
// END ************网站字体*****************
-
+ CAN_COPY: process.env.NEXT_PUBLIC_CAN_COPY || true, // 是否允许复制页面内容 默认允许,如果设置为false、则全栈禁止复制内容。
CUSTOM_RIGHT_CLICK_CONTEXT_MENU: process.env.NEXT_PUBLIC_CUSTOM_RIGHT_CLICK_CONTEXT_MENU || true, // 自定义右键菜单,覆盖系统菜单
// 自定义外部脚本,外部样式
diff --git a/components/DisableCopy.js b/components/DisableCopy.js
new file mode 100644
index 00000000..80860714
--- /dev/null
+++ b/components/DisableCopy.js
@@ -0,0 +1,21 @@
+import BLOG from '@/blog.config'
+import { useEffect } from 'react'
+
+/**
+ * 禁止用户拷贝文章的插件
+ */
+export default function DisableCopy() {
+ useEffect(() => {
+ if (!JSON.parse(BLOG.CAN_COPY)) {
+ // 全栈添加禁止复制的样式
+ document.getElementsByTagName('html')[0].classList.add('forbid-copy')
+ // 监听复制事件
+ document.addEventListener('copy', function (event) {
+ event.preventDefault() // 阻止默认复制行为
+ alert('抱歉,本网页内容不可复制!')
+ })
+ }
+ }, [])
+
+ return null
+}
diff --git a/components/ExternalPlugins.js b/components/ExternalPlugins.js
index c4b62548..b239f954 100644
--- a/components/ExternalPlugins.js
+++ b/components/ExternalPlugins.js
@@ -30,6 +30,7 @@ const GoogleAdsense = dynamic(() => import('@/components/GoogleAdsense'), { ssr:
const Messenger = dynamic(() => import('@/components/FacebookMessenger'), { ssr: false })
const VConsole = dynamic(() => import('@/components/VConsole'), { ssr: false })
const CustomContextMenu = dynamic(() => import('@/components/CustomContextMenu'), { ssr: false })
+const DisableCopy = dynamic(() => import('@/components/DisableCopy'), { ssr: false })
/**
* 各种第三方组件
@@ -55,6 +56,7 @@ const ExternalPlugin = (props) => {
{JSON.parse(BLOG.COMMENT_TWIKOO_COUNT_ENABLE) && }
{JSON.parse(BLOG.RIBBON) && }
{JSON.parse(BLOG.CUSTOM_RIGHT_CLICK_CONTEXT_MENU) && }
+ {!JSON.parse(BLOG.CAN_COPY) && }
>
}
diff --git a/styles/globals.css b/styles/globals.css
index dbaa8ef2..5151e216 100644
--- a/styles/globals.css
+++ b/styles/globals.css
@@ -263,3 +263,9 @@ a.avatar-wrapper {
.reply-author-name {
font-weight: 500;
}
+
+.forbid-copy {
+ user-select: none;
+ -webkit-user-select: none;
+ -ms-user-select: none;
+}
\ No newline at end of file
diff --git a/themes/simple/style.js b/themes/simple/style.js
index 647a404e..2bccde8a 100644
--- a/themes/simple/style.js
+++ b/themes/simple/style.js
@@ -11,6 +11,12 @@ const Style = () => {
.dark body{
background-color: black;
}
+ // 文本不可选取
+ .forbid-copy {
+ user-select: none;
+ -webkit-user-select: none;
+ -ms-user-select: none;
+ }
#theme-simple #announcement-content {
/* background-color: #f6f6f6; */