# 前言

今天做了网课的期末考试,结果提前半小时做完了,闲着无聊于是在网页上捣鼓起了怎么解除网页的不能复制 & 不能打开右键菜单的限制。捣鼓出来后,发现好久没写(氵)博客了,那就分享一下这个操作。

# 正文

# 智慧树

F12 打开控制台,切换到 element 一栏,随便点一个元素
我们可以看到下面的几个事件
file

然后按 remove 把这个事件移除掉就完事了。

当然你也可以复制下面的命令到控制台执行一下

document.oncopy = null;
document.onselectstart = null;
document.oncontextmenu = null;
document.oncut = null;

file

这样也是 ok 的

# bilibili

顺带一提 b 站专栏禁止复制的实现不太一样,是用的 css 禁用

file

我们也可以把它禁用实现复制

file

# 脚本自动化

不过每次都要打开控制台粘贴太麻烦了,我们整个自动化脚本
我们用个油猴插件,在每个网页打开时都执行这段代码

file

(function() {
  let style = document.createElement("style");
    style.innerText = `
		* {
			  user-select: initial!important;
			  -webkit-user-select: initial!important;
			  -moz-user-select: initial!important;
			  -ms-user-select: initial!important;
		}
	`;
    document.body.append(style);
	document.oncopy = null;
	document.onselectstart = null;
	document.oncontextmenu = null;
	document.oncut = null;
})()

好的完事,通过这个方法也可以防止一些网站(没错就是 CSDN)在你复制时,给你在后面加上一堆没用的东西,真香。

# 后记

希望下学期没有网课