@whitesev/utils 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +172 -0
- package/dist/index.cjs.js +6017 -0
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.esm.js +6015 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/index.umd.js +6023 -0
- package/dist/index.umd.js.map +1 -0
- package/dist/src/ColorConversion.d.ts +45 -0
- package/dist/src/Dictionary.d.ts +87 -0
- package/dist/src/GBKEncoder.d.ts +17 -0
- package/dist/src/Hooks.d.ts +5 -0
- package/dist/src/Httpx.d.ts +50 -0
- package/dist/src/LockFunction.d.ts +16 -0
- package/dist/src/Log.d.ts +66 -0
- package/dist/src/Progress.d.ts +6 -0
- package/dist/src/Utils.d.ts +1560 -0
- package/dist/src/UtilsCore.d.ts +9 -0
- package/dist/src/UtilsGMCookie.d.ts +36 -0
- package/dist/src/UtilsGMMenu.d.ts +119 -0
- package/dist/src/ajaxHooker.d.ts +6 -0
- package/dist/src/indexedDB.d.ts +165 -0
- package/dist/src/tryCatch.d.ts +31 -0
- package/index.ts +3 -0
- package/package.json +34 -0
- package/rollup.config.js +28 -0
- package/src/ColorConversion.ts +124 -0
- package/src/Dictionary.ts +158 -0
- package/src/GBKEncoder.js +111 -0
- package/src/GBKEncoder.ts +116 -0
- package/src/Hooks.js +73 -0
- package/src/Httpx.js +747 -0
- package/src/LockFunction.js +35 -0
- package/src/Log.js +256 -0
- package/src/Progress.js +98 -0
- package/src/Utils.ts +4495 -0
- package/src/UtilsCore.ts +39 -0
- package/src/UtilsGMCookie.ts +167 -0
- package/src/UtilsGMMenu.js +464 -0
- package/src/ajaxHooker.js +560 -0
- package/src/indexedDB.js +355 -0
- package/src/tryCatch.js +100 -0
- package/src/types/AjaxHooker.d.ts +153 -0
- package/src/types/DOMUtils.d.ts +188 -0
- package/src/types/Hook.d.ts +16 -0
- package/src/types/Httpx.d.ts +1308 -0
- package/src/types/Indexdb.d.ts +128 -0
- package/src/types/LockFunction.d.ts +47 -0
- package/src/types/Log.d.ts +91 -0
- package/src/types/Progress.d.ts +30 -0
- package/src/types/TryCatch.d.ts +6 -0
- package/src/types/UtilsCore.d.ts +7 -0
- package/src/types/UtilsGMMenu.d.ts +224 -0
- package/src/types/global.d.ts +58 -0
- package/tsconfig.json +32 -0
package/src/Hooks.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
const Hooks = function () {
|
|
2
|
+
this.initEnv = function () {
|
|
3
|
+
Function.prototype.hook = function (realFunc, hookFunc, context) {
|
|
4
|
+
let _context = null; //函数上下文
|
|
5
|
+
let _funcName = null; //函数名
|
|
6
|
+
|
|
7
|
+
_context = context || window;
|
|
8
|
+
_funcName = getFuncName(this);
|
|
9
|
+
_context["realFunc_" + _funcName] = this;
|
|
10
|
+
|
|
11
|
+
if (
|
|
12
|
+
_context[_funcName].prototype &&
|
|
13
|
+
_context[_funcName].prototype.isHooked
|
|
14
|
+
) {
|
|
15
|
+
console.log("Already has been hooked,unhook first");
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
function getFuncName(fn) {
|
|
19
|
+
// 获取函数名
|
|
20
|
+
let strFunc = fn.toString();
|
|
21
|
+
let _regex = /function\s+(\w+)\s*\(/;
|
|
22
|
+
let patten = strFunc.match(_regex);
|
|
23
|
+
if (patten) {
|
|
24
|
+
return patten[1];
|
|
25
|
+
}
|
|
26
|
+
return "";
|
|
27
|
+
}
|
|
28
|
+
try {
|
|
29
|
+
eval(
|
|
30
|
+
"_context[_funcName] = function " +
|
|
31
|
+
_funcName +
|
|
32
|
+
"(){\n" +
|
|
33
|
+
"let args = Array.prototype.slice.call(arguments,0);\n" +
|
|
34
|
+
"let obj = this;\n" +
|
|
35
|
+
"hookFunc.apply(obj,args);\n" +
|
|
36
|
+
"return _context['realFunc_" +
|
|
37
|
+
_funcName +
|
|
38
|
+
"'].apply(obj,args);\n" +
|
|
39
|
+
"};"
|
|
40
|
+
);
|
|
41
|
+
_context[_funcName].prototype.isHooked = true;
|
|
42
|
+
return true;
|
|
43
|
+
} catch (e) {
|
|
44
|
+
console.log("Hook failed,check the params.");
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
Function.prototype.unhook = function (realFunc, funcName, context) {
|
|
49
|
+
let _context = null;
|
|
50
|
+
let _funcName = null;
|
|
51
|
+
_context = context || window;
|
|
52
|
+
_funcName = funcName;
|
|
53
|
+
if (!_context[_funcName].prototype.isHooked) {
|
|
54
|
+
console.log("No function is hooked on");
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
_context[_funcName] = _context["realFunc" + _funcName];
|
|
58
|
+
Reflect.deleteProperty(_context, "realFunc_" + _funcName);
|
|
59
|
+
return true;
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
this.cleanEnv = function () {
|
|
63
|
+
if (Function.prototype.hasOwnProperty("hook")) {
|
|
64
|
+
Reflect.deleteProperty(unction.prototype, "hook");
|
|
65
|
+
}
|
|
66
|
+
if (Function.prototype.hasOwnProperty("unhook")) {
|
|
67
|
+
Reflect.deleteProperty(unction.prototype, "unhook");
|
|
68
|
+
}
|
|
69
|
+
return true;
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
export { Hooks };
|