@whitesev/utils 2.5.9 → 2.6.1
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/dist/index.amd.js +3564 -3513
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +3564 -3513
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +3564 -3513
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +3564 -3513
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +3564 -3513
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +3564 -3513
- package/dist/index.umd.js.map +1 -1
- package/dist/types/src/Utils.d.ts +3 -2
- package/package.json +52 -52
- package/src/Utils.ts +5 -4
- package/src/ajaxHooker/ajaxHooker.js +54 -4
- package/LICENSE +0 -674
|
@@ -56,11 +56,12 @@ declare class Utils {
|
|
|
56
56
|
* ajax劫持库,支持xhr和fetch劫持。
|
|
57
57
|
* + 来源:https://bbs.tampermonkey.net.cn/thread-3284-1-1.html
|
|
58
58
|
* + 作者:cxxjackie
|
|
59
|
-
* + 版本:1.4.
|
|
59
|
+
* + 版本:1.4.4
|
|
60
|
+
* + 旧版本:1.2.4
|
|
60
61
|
* + 文档:https://scriptcat.org/zh-CN/script-show-page/637/
|
|
61
62
|
* @param useOldVersion 是否使用旧版本,默认false
|
|
62
63
|
*/
|
|
63
|
-
ajaxHooker: () => UtilsAjaxHookResult;
|
|
64
|
+
ajaxHooker: (useOldVersion?: boolean) => UtilsAjaxHookResult;
|
|
64
65
|
/**
|
|
65
66
|
* 根据坐标点击canvas元素的内部位置
|
|
66
67
|
* @param canvasElement 画布元素
|
package/package.json
CHANGED
|
@@ -1,52 +1,52 @@
|
|
|
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
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@whitesev/utils",
|
|
3
|
+
"version": "2.6.1",
|
|
4
|
+
"description": "一个常用的工具库",
|
|
5
|
+
"main": "dist/index.cjs.js",
|
|
6
|
+
"module": "dist/index.esm.js",
|
|
7
|
+
"types": "dist/types/index.d.ts",
|
|
8
|
+
"jsdelivr": "dist/index.umd.js",
|
|
9
|
+
"exports": {
|
|
10
|
+
"./package.json": "./package.json",
|
|
11
|
+
"./dist/*": "./dist/*",
|
|
12
|
+
".": {
|
|
13
|
+
"import": "./dist/index.esm.js",
|
|
14
|
+
"require": "./dist/index.cjs.js",
|
|
15
|
+
"types": "./dist/types/index.d.ts"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist",
|
|
20
|
+
"src"
|
|
21
|
+
],
|
|
22
|
+
"scripts": {
|
|
23
|
+
"dev": "rollup --config --watch",
|
|
24
|
+
"build": "rollup --config",
|
|
25
|
+
"build:all": "rollup --config",
|
|
26
|
+
"build:all-new": "rollup --config"
|
|
27
|
+
},
|
|
28
|
+
"publishConfig": {
|
|
29
|
+
"registry": "https://registry.npmjs.org/"
|
|
30
|
+
},
|
|
31
|
+
"keywords": [
|
|
32
|
+
"typescript",
|
|
33
|
+
"Utils",
|
|
34
|
+
"工具类",
|
|
35
|
+
"TamperMonkey",
|
|
36
|
+
"VioletMonkey",
|
|
37
|
+
"ScriptCat"
|
|
38
|
+
],
|
|
39
|
+
"author": "WhiteSev",
|
|
40
|
+
"license": "MIT",
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"@rollup/plugin-babel": "^6.0.4",
|
|
43
|
+
"@rollup/plugin-commonjs": "^26.0.1",
|
|
44
|
+
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
45
|
+
"@rollup/plugin-typescript": "^11.1.6",
|
|
46
|
+
"rollup-plugin-clear": "^2.0.7",
|
|
47
|
+
"tslib": "^2.6.3"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"typescript": "^5.5.4"
|
|
51
|
+
}
|
|
52
|
+
}
|
package/src/Utils.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { ColorConversion } from "./ColorConversion";
|
|
|
2
2
|
import { GBKEncoder } from "./GBKEncoder";
|
|
3
3
|
import { UtilsGMCookie } from "./UtilsGMCookie";
|
|
4
4
|
import { AjaxHooker } from "./ajaxHooker/ajaxHooker.js";
|
|
5
|
+
import { AjaxHooker1_2_4 } from "./ajaxHooker/ajaxHooker1.2.4";
|
|
5
6
|
import { GMMenu } from "./UtilsGMMenu";
|
|
6
7
|
import { Hooks } from "./Hooks";
|
|
7
8
|
import { Httpx } from "./Httpx";
|
|
@@ -23,7 +24,6 @@ import {
|
|
|
23
24
|
} from "./types/global";
|
|
24
25
|
import type { WindowApiOption } from "./types/WindowApi";
|
|
25
26
|
import { ModuleRaid } from "./ModuleRaid";
|
|
26
|
-
import { AjaxHooker1_2_4 } from "./ajaxHooker/ajaxHooker1.2.4";
|
|
27
27
|
|
|
28
28
|
class Utils {
|
|
29
29
|
private windowApi: typeof WindowApi.prototype;
|
|
@@ -31,7 +31,7 @@ class Utils {
|
|
|
31
31
|
this.windowApi = new WindowApi(option);
|
|
32
32
|
}
|
|
33
33
|
/** 版本号 */
|
|
34
|
-
version = "2025.
|
|
34
|
+
version = "2025.2.8";
|
|
35
35
|
|
|
36
36
|
/**
|
|
37
37
|
* 在页面中增加style元素,如果html节点存在子节点,添加子节点第一个,反之,添加到html节点的子节点最后一个
|
|
@@ -209,11 +209,12 @@ class Utils {
|
|
|
209
209
|
* ajax劫持库,支持xhr和fetch劫持。
|
|
210
210
|
* + 来源:https://bbs.tampermonkey.net.cn/thread-3284-1-1.html
|
|
211
211
|
* + 作者:cxxjackie
|
|
212
|
-
* + 版本:1.4.
|
|
212
|
+
* + 版本:1.4.4
|
|
213
|
+
* + 旧版本:1.2.4
|
|
213
214
|
* + 文档:https://scriptcat.org/zh-CN/script-show-page/637/
|
|
214
215
|
* @param useOldVersion 是否使用旧版本,默认false
|
|
215
216
|
*/
|
|
216
|
-
ajaxHooker
|
|
217
|
+
ajaxHooker = (useOldVersion: boolean = false): UtilsAjaxHookResult => {
|
|
217
218
|
if (useOldVersion) {
|
|
218
219
|
return AjaxHooker1_2_4();
|
|
219
220
|
} else {
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
// @name ajaxHooker
|
|
2
2
|
// @author cxxjackie
|
|
3
|
-
// @version 1.4.
|
|
4
|
-
// @updateLog
|
|
5
|
-
// @updateLog xhr事件增加currentTarget劫持。
|
|
3
|
+
// @version 1.4.4
|
|
4
|
+
// @updateLog 修复头条、抖音部分站点下this引用错误的问题。
|
|
6
5
|
// @supportURL https://bbs.tampermonkey.net.cn/thread-3284-1-1.html
|
|
7
6
|
|
|
8
7
|
export const AjaxHooker = function () {
|
|
9
8
|
return (function () {
|
|
10
9
|
"use strict";
|
|
11
|
-
const version = "1.4.
|
|
10
|
+
const version = "1.4.4";
|
|
12
11
|
const hookInst = {
|
|
13
12
|
hookFns: [],
|
|
14
13
|
filters: [],
|
|
@@ -542,6 +541,57 @@ export const AjaxHooker = function () {
|
|
|
542
541
|
win.fetch = winAh.fakeFetch;
|
|
543
542
|
resProto.clone = winAh.fakeFetchClone;
|
|
544
543
|
winAh.hookInsts.add(hookInst);
|
|
544
|
+
// 针对头条、抖音 secsdk.umd.js 的兼容性处理
|
|
545
|
+
class AHFunction {
|
|
546
|
+
call(thisArg, ...args) {
|
|
547
|
+
if (
|
|
548
|
+
thisArg &&
|
|
549
|
+
thisArg.__ajaxHooker &&
|
|
550
|
+
thisArg.__ajaxHooker.proxyXhr === thisArg
|
|
551
|
+
) {
|
|
552
|
+
thisArg = thisArg.__ajaxHooker.originalXhr;
|
|
553
|
+
}
|
|
554
|
+
return Reflect.apply(this, thisArg, args);
|
|
555
|
+
}
|
|
556
|
+
apply(thisArg, args) {
|
|
557
|
+
if (
|
|
558
|
+
thisArg &&
|
|
559
|
+
thisArg.__ajaxHooker &&
|
|
560
|
+
thisArg.__ajaxHooker.proxyXhr === thisArg
|
|
561
|
+
) {
|
|
562
|
+
thisArg = thisArg.__ajaxHooker.originalXhr;
|
|
563
|
+
}
|
|
564
|
+
return Reflect.apply(this, thisArg, args || []);
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
function hookSecsdk(csrf) {
|
|
568
|
+
Object.setPrototypeOf(
|
|
569
|
+
csrf.nativeXMLHttpRequestSetRequestHeader,
|
|
570
|
+
AHFunction.prototype
|
|
571
|
+
);
|
|
572
|
+
Object.setPrototypeOf(
|
|
573
|
+
csrf.nativeXMLHttpRequestOpen,
|
|
574
|
+
AHFunction.prototype
|
|
575
|
+
);
|
|
576
|
+
Object.setPrototypeOf(
|
|
577
|
+
csrf.nativeXMLHttpRequestSend,
|
|
578
|
+
AHFunction.prototype
|
|
579
|
+
);
|
|
580
|
+
}
|
|
581
|
+
if (win.secsdk) {
|
|
582
|
+
if (win.secsdk.csrf && win.secsdk.csrf.nativeXMLHttpRequestOpen)
|
|
583
|
+
hookSecsdk(win.secsdk.csrf);
|
|
584
|
+
} else {
|
|
585
|
+
defineProp(win, "secsdk", emptyFn, (secsdk) => {
|
|
586
|
+
delete win.secsdk;
|
|
587
|
+
win.secsdk = secsdk;
|
|
588
|
+
defineProp(secsdk, "csrf", emptyFn, (csrf) => {
|
|
589
|
+
delete secsdk.csrf;
|
|
590
|
+
secsdk.csrf = csrf;
|
|
591
|
+
if (csrf.nativeXMLHttpRequestOpen) hookSecsdk(csrf);
|
|
592
|
+
});
|
|
593
|
+
});
|
|
594
|
+
}
|
|
545
595
|
return {
|
|
546
596
|
hook: (fn) => hookInst.hookFns.push(fn),
|
|
547
597
|
filter: (arr) => {
|