使用useCapture拦截阻止事件
当前为
// ==UserScript==
// @name 破解禁止复制+破解禁止右键菜单
// @version 1.0.3
// @description 使用useCapture拦截阻止事件
// @author TAOTAO1919
// @match *://*/*
// @icon https://cdn.jsdelivr.net/gh/kaokei/static-cdn/icon/peach.svg
// @grant none
// @license MIT
// @namespace https://gf.qytechs.cn/users/1495458
// ==/UserScript==
// 开发文档 https://wiki.greasespot.net/Metadata_Block
// 示例网站 https://sfbook.com/scales.htm
// 示例网站 https://www.ratzillacosme.com/blog/global-beauty-marketing-cultural-clash/
// 示例网站 https://www.zhihu.com/question/1910463767457792735/answer/1929126549698873125
// 示例网站 https://www.jianshu.com/p/3f540c02a4b9
// 示例网站 https://blog.csdn.net/hgl868/article/details/45095153
(function () {
"use strict";
const block = e => e.stopImmediatePropagation();
const events = ['copy', 'cut', 'keydown', 'contextmenu', 'mousedown', 'mousemove', 'selectstart', 'paste'];
function preventDom(d) {
events.forEach(ev => {
d.addEventListener(ev, block, true);
});
}
// 清除文档和body元素的事件监听器
const doc = document;
const bd = doc.body;
preventDom(doc);
preventDom(bd);
preventDom(window);
// 清除body上的事件处理函数
bd.onselectstart = null;
bd.oncopy = null;
bd.oncut = null;
bd.onpaste = null;
bd.onkeydown = null;
bd.oncontextmenu = null;
bd.onmousemove = null;
bd.onmouseup = null;
bd.onmousedown = null;
bd.ondragstart = null;
// 清除document上的事件处理函数
const docWrapper = doc.wrappedJSObject || doc;
docWrapper.onselectstart = null;
docWrapper.oncopy = null;
docWrapper.oncut = null;
docWrapper.onpaste = null;
docWrapper.onkeydown = null;
docWrapper.oncontextmenu = null;
docWrapper.onmousemove = null;
docWrapper.onmouseup = null;
docWrapper.onmousedown = null;
docWrapper.ondragstart = null;
// 遍历所有DOM元素清除事件限制
const allElements = document.querySelectorAll('*');
for (const element of allElements) {
const elWrapper = element.wrappedJSObject || element;
elWrapper.onselectstart = null;
elWrapper.oncopy = null;
elWrapper.oncut = null;
elWrapper.onpaste = null;
elWrapper.onkeydown = null;
elWrapper.oncontextmenu = null;
elWrapper.onmousemove = null;
elWrapper.onmouseup = null;
elWrapper.onmousedown = null;
elWrapper.ondragstart = null;
preventDom(elWrapper);
}
// 添加CSS强制启用文本选择
const head = doc.head || doc.getElementsByTagName('head')[0];
if (head) {
const style = document.createElement('style');
style.textContent = `
html, * {
user-select: auto !important;
-webkit-user-select: auto !important;
-moz-user-select: auto !important;
-ms-user-select: auto !important;
}
*::selection {
background-color: #409EFF !important;
color: #ffffff !important;
text-shadow: none !important;
}
`;
head.appendChild(style);
}
// 劫持getComputedStyle
const originalGetComputedStyle = window.getComputedStyle;
window.getComputedStyle = function(element, pseudoElement) {
const result = originalGetComputedStyle(element, pseudoElement);
// 创建虚拟样式对象
const proxy = new Proxy(result, {
get(target, property) {
if (property === 'userSelect' || property === 'webkitUserSelect' || property === 'mozUserSelect' || property === 'msUserSelect' ) {
return 'none'; // 始终返回"none"欺骗检测
}
return Reflect.get(target, property);
}
});
return proxy;
};
})();
QingJ © 2025
镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址