完美解决浏览器不能复制的问题(比如赛氪网的中题库练习题)
仅供复制题库题目进行打印学习使用!
最近想把赛氪网题库中的题目打印出来做练习,发现题库中的题目不能复制,不能在试卷上勾画标记太难受了,而且不能留作材料以后复习,故出此策。
而且Ctrl+P打印出的pdf会缺少题目。(我的打印钱...)
目录
一、问题
二、解决方法
1. Fn+F12打开控制台编辑
2.输入代码回车
3.复制内容成功
一、问题
正常打开赛氪网题库是无法进行复制的(或者其他网页)。
二、解决方法
1. Fn+F12打开控制台

2.输入代码回车
(function() {// 解除常见禁止操作function unlock() {document.oncontextmenu = null;document.onselectstart = null;document.oncopy = null;document.oncut = null;document.onpaste = null;document.onmousedown = null;document.onmouseup = null;document.body.oncontextmenu = null;document.body.onselectstart = null;document.body.oncopy = null;document.body.oncut = null;document.body.onpaste = null;document.body.onmousedown = null;document.body.onmouseup = null;// 删除禁止选中的CSS样式const css = '* { -webkit-user-select: text !important; -moz-user-select: text !important; -ms-user-select: text !important; user-select: text !important; }';const style = document.createElement('style');style.type = 'text/css';style.appendChild(document.createTextNode(css));document.head.appendChild(style);// 移除网页监听的所有阻止复制的事件["copy", "cut", "paste", "selectstart", "contextmenu", "mousedown", "mouseup", "keydown", "keypress", "keyup"].forEach(function(event) {document.body.addEventListener(event, function(e) {e.stopPropagation();}, true);});// 尝试解除iframe中的限制document.querySelectorAll('iframe').forEach(iframe => {try {const iframeDoc = iframe.contentDocument || iframe.contentWindow.document;iframeDoc.oncontextmenu = null;iframeDoc.onselectstart = null;iframeDoc.oncopy = null;iframeDoc.oncut = null;iframeDoc.onpaste = null;iframeDoc.onmousedown = null;iframeDoc.onmouseup = null;} catch (e) {console.log('iframe无法访问,跨域保护');}});console.log('%c复制限制解除成功!', 'color: green; font-weight: bold;');}unlock();// 监听页面动态生成内容,持续解除const observer = new MutationObserver(unlock);observer.observe(document.body, { childList: true, subtree: true });
})();