Skip to content

Commit 99b08b6

Browse files
committed
feat: devtools script
1 parent cf5a56a commit 99b08b6

File tree

8 files changed

+109
-0
lines changed

8 files changed

+109
-0
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,17 @@
8787
<td>移除常见网页的水印,请自行处理<code>@match</code>到匹配地址。</td>
8888
</tr>
8989

90+
<tr>
91+
<td>移除 DevTools 拦截器</td>
92+
<td><a href="https://github.com/WindrunnerMax/TKScript/blob/master/packages/devtools/README.md">详情</a></td>
93+
<td>
94+
<a href="https://windrunnermax.github.io/TKScript/devtools.user.js">安装</a>
95+
<span>|</span>
96+
<a href="https://cdn.jsdelivr.net/gh/WindrunnerMax/TKScript@gh-pages/devtools.user.js">备用</a>
97+
</td>
98+
<td>移除调试器拦截器,防止浏览器<code>DevTools</code>被拦截。</td>
99+
</tr>
100+
90101
<tr>
91102
<td>自动展开阅读全文</td>
92103
<td><a href="https://github.com/WindrunnerMax/TKScript/blob/master/packages/expansion/README.md">详情</a></td>

packages/devtools/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# 移除 DevTools 拦截器
2+
3+
移除调试器拦截器,防止浏览器 DevTools 被拦截。

packages/devtools/meta.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "Remove Debugger Interceptor",
3+
"namespace": "https://github.com/WindrunnerMax/TKScript",
4+
"version": "1.0.0",
5+
"description": "移除调试器拦截器",
6+
"author": "Czy",
7+
"match": ["http://*/*", "https://*/*"],
8+
"supportURL": "https://github.com/WindrunnerMax/TKScript/issues",
9+
"license": "GPL License",
10+
"installURL": "https://github.com/WindrunnerMax/TKScript",
11+
"run-at": "document-start",
12+
"grant": [ "unsafeWindow"]
13+
}

packages/devtools/package.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "devtools",
3+
"version": "1.0.0",
4+
"author": "Czy",
5+
"license": "MIT",
6+
"repository": {
7+
"type": "git",
8+
"url": "git://github.com/WindrunnerMax/TKScript"
9+
},
10+
"scripts": {
11+
"lint:ts": "../../node_modules/typescript/bin/tsc --noEmit"
12+
},
13+
"sideEffects": false,
14+
"files": [
15+
"src"
16+
]
17+
}

packages/devtools/src/global.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
declare const unsafeWindow = window;
2+
3+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
4+
type Any = any;

packages/devtools/src/index.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
let isHooked = false;
2+
3+
const InitLog = unsafeWindow.console.log;
4+
const InitSetInterval = unsafeWindow.setInterval;
5+
const InitCloseWindow = unsafeWindow.close;
6+
const InitFunctionConstructor = unsafeWindow.Function.prototype.constructor;
7+
8+
(<Any>unsafeWindow).logger = InitLog;
9+
10+
function hookedFunctionConstructor(...args: unknown[]) {
11+
if (args[0] == "debugger") {
12+
return function () {
13+
isHooked = true;
14+
};
15+
}
16+
return InitFunctionConstructor(...args);
17+
}
18+
unsafeWindow.Function.prototype.constructor = hookedFunctionConstructor;
19+
20+
function hookedSetInterval<TArgs extends unknown[]>(
21+
callback: (...args: TArgs) => void,
22+
ms?: number,
23+
...args: TArgs
24+
) {
25+
if (callback && callback.toString()) {
26+
const funString = callback.toString() as string;
27+
if (
28+
funString.includes("debugger") ||
29+
funString.includes("window.close") ||
30+
/\.ondevtool/i.test(funString)
31+
) {
32+
isHooked = true;
33+
return -1;
34+
}
35+
}
36+
return InitSetInterval(callback, ms, ...args);
37+
}
38+
unsafeWindow.setInterval = hookedSetInterval as typeof setInterval;
39+
40+
function hookedCloseWindow() {
41+
if (isHooked) return void 0;
42+
InitCloseWindow();
43+
}
44+
unsafeWindow.close = hookedCloseWindow;

packages/devtools/tsconfig.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": "../../tsconfig.json",
3+
"include": ["./src/**/*.ts", "./src/**/*.tsx"]
4+
}

rollup.config.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,19 @@ const scriptConfig = [
7676
injectCss: false,
7777
},
7878
},
79+
{
80+
name: "Devtools",
81+
meta: {
82+
input: "./meta/blank.ts",
83+
output: "./dist/meta/devtools.meta.js",
84+
metaFile: "./packages/devtools/meta.json",
85+
},
86+
script: {
87+
input: "./packages/devtools/src/index.ts",
88+
output: "./dist/devtools.user.js",
89+
injectCss: false,
90+
},
91+
},
7992
];
8093

8194
export default [

0 commit comments

Comments
 (0)