注意浏览器要开开发者模式,不然油猴脚本都是不生效的
理论上是通用的,其他检测切屏的场景也可以用,自行修改匹配的(@match部分)域名即可,
如需完整活动教程,可看飞书:https://acn4gjw5vke5.feishu.cn/wiki/DQIVw8GUbi4wkakFf5xc2eWdn2g
[upvote]
// ==UserScript==
// @name 防切屏检测
// @namespace http://tampermonkey.net/
// @version 1.0.0
// @description 阻止各类切屏检测
// @author 4P
// @match https://connect.huaweicloud.com/courses/exam/*
// @match https://edu.huaweicloud.com/certifications/*
// @match https://edu.huaweicloud.com/signup/*
// @match https://www.huaweicloud.com
// @run-at document-start
// @grant unsafeWindow
// @license gpl-3.0
// ==/UserScript==
(function () {
'use strict';
const window = unsafeWindow;
const blackList = new Set(["visibilitychange", "blur", "pagehide", "mouseleave"]);
const isDebug = false;
const log = console.log.bind(console, "[阻止切屏检测]");
const debug = isDebug ? log : () => { };
function patchToString(obj, ref) {
return; // Not enabled for now
obj.toString = () => ref.toString();
obj.toString.toString = () => ref.toString.toString();
obj.toString.toString.toString = obj.toString.toString;
}
function patchAddEventListener(obj, name) {
obj._addEventListener = obj.addEventListener;
obj.addEventListener = (...args) => {
if (!blackList.has(args[0])) {
debug(`allow ${name}.addEventListener`, ...args);
return obj._addEventListener(...args);
} else {
log(`block ${name}.addEventListener`, ...args);
return undefined;
}
};
patchToString(obj.addEventListener, obj._addEventListener);
}
patchAddEventListener(window, "window");
patchAddEventListener(document, "document");
document.addEventListener("DOMContentLoaded", () => {
patchAddEventListener(document.body, "document.body");
}, { once: true, passive: true, capture: true });
log("addEventListener hooked!");
if (isDebug) { // DEBUG ONLY: find out all timers
window._setInterval = window.setInterval;
window.setInterval = (...args) => {
const id = window._setInterval(...args);
debug("calling window.setInterval", id, ...args);
return id;
};
debug("setInterval hooked!");
window._setTimeout = window.setTimeout;
window.setTimeout = (...args) => {
const id = window._setTimeout(...args);
debug("calling window.setTimeout", id, ...args);
return id;
};
debug("setTimeout hooked!");
}
Object.defineProperties(document, {
hidden: {
value: false
},
visibilityState: {
value: "visible"
},
hasFocus: {
value: () => true
},
onvisibilitychange: {
get: () => undefined,
set: () => { }
},
onblur: {
get: () => undefined,
set: () => { }
},
onmouseleave: {
get: () => undefined,
set: () => { }
},
});
log("document properties set!");
Object.defineProperties(window, {
onblur: {
get: () => undefined,
set: () => { }
},
onpagehide: {
get: () => undefined,
set: () => { }
},
});
log("window properties set!");
})();
[/upvote]
15
78


78 条回复
排序