-
Notifications
You must be signed in to change notification settings - Fork 6
/
test.html
38 lines (32 loc) · 1.14 KB
/
test.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Test</title>
</head>
<body>
<button id="foo-btn">TEST</button>
<script src="main.js"></script>
<script>
// 提前埋伏好,后面增加事件监听的时候会把给定的逻辑放进去,通常情况下是借助油猴脚本等之类的工具注入到正常页面的头部先执行
(() => {
const fooBtnElement = document.getElementById("foo-btn");
const hookFunc = function () {
alert("执行了Hook逻辑!");
return true;
// return false;
};
new HookEventListener(fooBtnElement, "onclick", "addEventListener", ["click"], hookFunc).addHook();
})();
</script>
<script>
// 正常的代码,就正常添加事件,但是会被前面添加的Hook给捕捉到先悄悄执行Hook逻辑,然后才会执行此处指定的事件回调方法
const elementById = document.getElementById("foo-btn");
const eventFunc = function () {
alert("按钮被单击!");
};
// elementById.addEventListener("click", eventFunc);
elementById.onclick = eventFunc;
</script>
</body>
</html>