@whitesev/utils 2.7.2 → 2.7.4
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 +197 -350
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +197 -350
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +197 -350
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +197 -350
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +197 -350
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +197 -350
- package/dist/index.umd.js.map +1 -1
- package/dist/types/src/Utils.d.ts +30 -2
- package/dist/types/src/WindowApi.d.ts +4 -0
- package/dist/types/src/types/Event.d.ts +1 -2
- package/dist/types/src/types/Httpx.d.ts +4 -21
- package/dist/types/src/types/WindowApi.d.ts +4 -0
- package/dist/types/src/types/ajaxHooker.d.ts +1 -5
- package/package.json +1 -1
- package/src/ColorConversion.ts +5 -18
- package/src/CommonUtil.ts +8 -31
- package/src/DOMUtils.ts +9 -22
- package/src/Dictionary.ts +2 -7
- package/src/GBKEncoder.ts +1 -6
- package/src/Hooks.ts +1 -4
- package/src/Httpx.ts +102 -277
- package/src/LockFunction.ts +1 -3
- package/src/Log.ts +7 -23
- package/src/Progress.ts +2 -10
- package/src/TryCatch.ts +3 -11
- package/src/Utils.ts +213 -559
- package/src/UtilsCommon.ts +5 -9
- package/src/UtilsGMCookie.ts +1 -4
- package/src/UtilsGMMenu.ts +10 -29
- package/src/Vue.ts +2 -11
- package/src/WindowApi.ts +16 -0
- package/src/ajaxHooker/ajaxHooker.js +78 -142
- package/src/indexedDB.ts +3 -12
- package/src/types/Event.d.ts +1 -2
- package/src/types/Httpx.d.ts +4 -21
- package/src/types/WindowApi.d.ts +4 -0
- package/src/types/ajaxHooker.d.ts +1 -5
package/src/UtilsCommon.ts
CHANGED
|
@@ -5,14 +5,10 @@ export const GenerateUUID = function () {
|
|
|
5
5
|
if (typeof window?.crypto?.randomUUID === "function") {
|
|
6
6
|
return window.crypto.randomUUID();
|
|
7
7
|
} else {
|
|
8
|
-
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
charStr === "x" ? randomValue : (randomValue & 0x3) | 0x8;
|
|
14
|
-
return randomCharValue.toString(16);
|
|
15
|
-
}
|
|
16
|
-
);
|
|
8
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (charStr) {
|
|
9
|
+
var randomValue = (Math.random() * 16) | 0,
|
|
10
|
+
randomCharValue = charStr === "x" ? randomValue : (randomValue & 0x3) | 0x8;
|
|
11
|
+
return randomCharValue.toString(16);
|
|
12
|
+
});
|
|
17
13
|
}
|
|
18
14
|
};
|
package/src/UtilsGMCookie.ts
CHANGED
|
@@ -211,10 +211,7 @@ export class UtilsGMCookie {
|
|
|
211
211
|
* @param option 配置
|
|
212
212
|
* @param callback 删除操作后的回调(成功/失败)
|
|
213
213
|
*/
|
|
214
|
-
delete(
|
|
215
|
-
option: UtilsGMCookieDeleteOptions,
|
|
216
|
-
callback?: (error?: Error) => void
|
|
217
|
-
) {
|
|
214
|
+
delete(option: UtilsGMCookieDeleteOptions, callback?: (error?: Error) => void) {
|
|
218
215
|
let errorInfo;
|
|
219
216
|
try {
|
|
220
217
|
let defaultOption: Required<UtilsGMCookieDeleteOptions> = {
|
package/src/UtilsGMMenu.ts
CHANGED
|
@@ -60,9 +60,7 @@ export class GMMenu {
|
|
|
60
60
|
init() {
|
|
61
61
|
for (let index = 0; index < this.$data.data.length; index++) {
|
|
62
62
|
let menuOption = this.$data.data[index]["data"];
|
|
63
|
-
menuOption.enable = Boolean(
|
|
64
|
-
this.getLocalMenuData(menuOption.key, menuOption.enable as boolean)
|
|
65
|
-
);
|
|
63
|
+
menuOption.enable = Boolean(this.getLocalMenuData(menuOption.key, menuOption.enable as boolean));
|
|
66
64
|
if (typeof menuOption.showText !== "function") {
|
|
67
65
|
menuOption.showText = (menuText, menuEnable) => {
|
|
68
66
|
if (menuEnable) {
|
|
@@ -91,10 +89,7 @@ export class GMMenu {
|
|
|
91
89
|
const { showText, clickCallBack } = this.handleMenuData(
|
|
92
90
|
cloneMenuOptionData as Required<UtilsGMMenuOption>
|
|
93
91
|
);
|
|
94
|
-
let menuId = that.context.GM_Api.registerMenuCommand(
|
|
95
|
-
showText,
|
|
96
|
-
clickCallBack
|
|
97
|
-
);
|
|
92
|
+
let menuId = that.context.GM_Api.registerMenuCommand(showText, clickCallBack);
|
|
98
93
|
menuOptions[index].id = menuId;
|
|
99
94
|
(cloneMenuOptionData as any).deleteMenu = function () {
|
|
100
95
|
that.context.GM_Api.unregisterMenuCommand(menuId);
|
|
@@ -130,9 +125,7 @@ export class GMMenu {
|
|
|
130
125
|
* @param menuOption
|
|
131
126
|
*/
|
|
132
127
|
handleInitDetail(menuOption: Required<UtilsGMMenuOption>) {
|
|
133
|
-
menuOption.enable = Boolean(
|
|
134
|
-
this.getLocalMenuData(menuOption.key, menuOption.enable)
|
|
135
|
-
);
|
|
128
|
+
menuOption.enable = Boolean(this.getLocalMenuData(menuOption.key, menuOption.enable));
|
|
136
129
|
if (typeof menuOption.showText !== "function") {
|
|
137
130
|
menuOption.showText = (menuText, menuEnable) => {
|
|
138
131
|
if (menuEnable) {
|
|
@@ -152,9 +145,7 @@ export class GMMenu {
|
|
|
152
145
|
let that = this;
|
|
153
146
|
let menuLocalDataItemKey = menuOption.key;
|
|
154
147
|
/* 菜单默认开启的状态 */
|
|
155
|
-
let defaultEnable = Boolean(
|
|
156
|
-
this.getLocalMenuData(menuLocalDataItemKey, menuOption.enable)
|
|
157
|
-
);
|
|
148
|
+
let defaultEnable = Boolean(this.getLocalMenuData(menuLocalDataItemKey, menuOption.enable));
|
|
158
149
|
/** 油猴菜单上显示的文本 */
|
|
159
150
|
let showText = menuOption.showText(menuOption.text, defaultEnable);
|
|
160
151
|
// const GMMenuOptions = {
|
|
@@ -177,22 +168,16 @@ export class GMMenu {
|
|
|
177
168
|
// };
|
|
178
169
|
/* 点击菜单后触发callback后的网页是否刷新 */
|
|
179
170
|
menuOption.autoReload =
|
|
180
|
-
typeof menuOption.autoReload !== "boolean"
|
|
181
|
-
? this.$default.autoReload
|
|
182
|
-
: menuOption.autoReload;
|
|
171
|
+
typeof menuOption.autoReload !== "boolean" ? this.$default.autoReload : menuOption.autoReload;
|
|
183
172
|
/* 点击菜单后触发callback后的网页是否存储值 */
|
|
184
173
|
menuOption.isStoreValue =
|
|
185
|
-
typeof menuOption.isStoreValue !== "boolean"
|
|
186
|
-
? this.$default.isStoreValue
|
|
187
|
-
: menuOption.isStoreValue;
|
|
174
|
+
typeof menuOption.isStoreValue !== "boolean" ? this.$default.isStoreValue : menuOption.isStoreValue;
|
|
188
175
|
/**
|
|
189
176
|
* 用户点击菜单后的回调函数
|
|
190
177
|
* @param event
|
|
191
178
|
*/
|
|
192
179
|
function clickCallBack(event: MouseEvent | PointerEvent) {
|
|
193
|
-
let localEnable = Boolean(
|
|
194
|
-
that.getLocalMenuData(menuLocalDataItemKey, defaultEnable)
|
|
195
|
-
);
|
|
180
|
+
let localEnable = Boolean(that.getLocalMenuData(menuLocalDataItemKey, defaultEnable));
|
|
196
181
|
if (menuOption.isStoreValue) {
|
|
197
182
|
that.setLocalMenuData(menuLocalDataItemKey, !localEnable);
|
|
198
183
|
}
|
|
@@ -239,8 +224,7 @@ export class GMMenu {
|
|
|
239
224
|
* @param menuKey 菜单-键key
|
|
240
225
|
*/
|
|
241
226
|
getMenuHandledOption(menuKey: string) {
|
|
242
|
-
return this.$data.data.find((item) => item!.handleData!.key === menuKey)
|
|
243
|
-
?.handleData;
|
|
227
|
+
return this.$data.data.find((item) => item!.handleData!.key === menuKey)?.handleData;
|
|
244
228
|
},
|
|
245
229
|
};
|
|
246
230
|
constructor(details: UtilsGMMenuConstructorOptions) {
|
|
@@ -248,13 +232,10 @@ export class GMMenu {
|
|
|
248
232
|
this.GM_Api.setValue = details.GM_setValue;
|
|
249
233
|
this.GM_Api.registerMenuCommand = details.GM_registerMenuCommand;
|
|
250
234
|
this.GM_Api.unregisterMenuCommand = details.GM_unregisterMenuCommand;
|
|
251
|
-
this.MenuHandle.$default.autoReload =
|
|
252
|
-
typeof details.autoReload === "boolean" ? details.autoReload : true;
|
|
235
|
+
this.MenuHandle.$default.autoReload = typeof details.autoReload === "boolean" ? details.autoReload : true;
|
|
253
236
|
for (const keyName of Object.keys(this.GM_Api)) {
|
|
254
237
|
if (typeof (this.GM_Api as any)[keyName] !== "function") {
|
|
255
|
-
throw new Error(
|
|
256
|
-
`Utils.GM_Menu 请在脚本开头加上 @grant ${keyName},且传入该对象`
|
|
257
|
-
);
|
|
238
|
+
throw new Error(`Utils.GM_Menu 请在脚本开头加上 @grant ${keyName},且传入该对象`);
|
|
258
239
|
}
|
|
259
240
|
}
|
|
260
241
|
this.add(details?.data || []);
|
package/src/Vue.ts
CHANGED
|
@@ -140,10 +140,7 @@ export class Vue {
|
|
|
140
140
|
* @param source 被观察的对象,这里采用函数返回对象
|
|
141
141
|
* @param changeCallBack 值改变的回调
|
|
142
142
|
*/
|
|
143
|
-
watch<T>(
|
|
144
|
-
source: () => T,
|
|
145
|
-
changeCallBack: (newValue: T | undefined, oldValue: T | undefined) => void
|
|
146
|
-
) {
|
|
143
|
+
watch<T>(source: () => T, changeCallBack: (newValue: T | undefined, oldValue: T | undefined) => void) {
|
|
147
144
|
let getter;
|
|
148
145
|
if (VueUtils.isReactive(source)) {
|
|
149
146
|
getter = () => this.traversal(source);
|
|
@@ -181,13 +178,7 @@ export class Vue {
|
|
|
181
178
|
}
|
|
182
179
|
return result;
|
|
183
180
|
}
|
|
184
|
-
private trigger(
|
|
185
|
-
target: any,
|
|
186
|
-
type: string,
|
|
187
|
-
key: string | symbol,
|
|
188
|
-
oldValue: any,
|
|
189
|
-
value: any
|
|
190
|
-
) {
|
|
181
|
+
private trigger(target: any, type: string, key: string | symbol, oldValue: any, value: any) {
|
|
191
182
|
const depsMap = this.targetMap.get(target);
|
|
192
183
|
if (!depsMap) return;
|
|
193
184
|
const effects = depsMap.get(key);
|
package/src/WindowApi.ts
CHANGED
|
@@ -8,6 +8,10 @@ export class WindowApi {
|
|
|
8
8
|
globalThis: globalThis,
|
|
9
9
|
self: self,
|
|
10
10
|
top: top!,
|
|
11
|
+
setTimeout: globalThis.setTimeout,
|
|
12
|
+
setInterval: globalThis.setInterval,
|
|
13
|
+
clearTimeout: globalThis.clearTimeout,
|
|
14
|
+
clearInterval: globalThis.clearInterval,
|
|
11
15
|
};
|
|
12
16
|
/** 使用的配置 */
|
|
13
17
|
private api: Required<WindowApiOption>;
|
|
@@ -40,4 +44,16 @@ export class WindowApi {
|
|
|
40
44
|
get top() {
|
|
41
45
|
return this.api.top;
|
|
42
46
|
}
|
|
47
|
+
get setTimeout() {
|
|
48
|
+
return this.api.setTimeout;
|
|
49
|
+
}
|
|
50
|
+
get setInterval() {
|
|
51
|
+
return this.api.setInterval;
|
|
52
|
+
}
|
|
53
|
+
get clearTimeout() {
|
|
54
|
+
return this.api.clearTimeout;
|
|
55
|
+
}
|
|
56
|
+
get clearInterval() {
|
|
57
|
+
return this.api.clearInterval;
|
|
58
|
+
}
|
|
43
59
|
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
// ==UserScript==
|
|
2
2
|
// @name ajaxHooker
|
|
3
3
|
// @author cxxjackie
|
|
4
|
-
// @version 1.4.
|
|
4
|
+
// @version 1.4.8
|
|
5
5
|
// @supportURL https://bbs.tampermonkey.net.cn/thread-3284-1-1.html
|
|
6
6
|
// @license GNU LGPL-3.0
|
|
7
7
|
// ==/UserScript==
|
|
8
8
|
|
|
9
9
|
export const ajaxHooker = function () {
|
|
10
10
|
"use strict";
|
|
11
|
-
const version = "1.4.
|
|
11
|
+
const version = "1.4.8";
|
|
12
12
|
const hookInst = {
|
|
13
13
|
hookFns: [],
|
|
14
14
|
filters: [],
|
|
@@ -37,11 +37,7 @@ export const ajaxHooker = function () {
|
|
|
37
37
|
const emptyFn = () => {};
|
|
38
38
|
const errorFn = (e) => console.error(e);
|
|
39
39
|
function isThenable(obj) {
|
|
40
|
-
return (
|
|
41
|
-
obj &&
|
|
42
|
-
["object", "function"].includes(typeof obj) &&
|
|
43
|
-
typeof obj.then === "function"
|
|
44
|
-
);
|
|
40
|
+
return obj && ["object", "function"].includes(typeof obj) && typeof obj.then === "function";
|
|
45
41
|
}
|
|
46
42
|
function catchError(fn, ...args) {
|
|
47
43
|
try {
|
|
@@ -79,8 +75,7 @@ export const ajaxHooker = function () {
|
|
|
79
75
|
const [header, value] = line.split(/(?<=^[^:]+)\s*:\s*/);
|
|
80
76
|
if (!value) continue;
|
|
81
77
|
const lheader = header.toLowerCase();
|
|
82
|
-
headers[lheader] =
|
|
83
|
-
lheader in headers ? `${headers[lheader]}, ${value}` : value;
|
|
78
|
+
headers[lheader] = lheader in headers ? `${headers[lheader]}, ${value}` : value;
|
|
84
79
|
}
|
|
85
80
|
break;
|
|
86
81
|
case "[object Headers]":
|
|
@@ -118,11 +113,9 @@ export const ajaxHooker = function () {
|
|
|
118
113
|
!filters.find((obj) => {
|
|
119
114
|
switch (true) {
|
|
120
115
|
case obj.type && obj.type !== type:
|
|
121
|
-
case getType(obj.url) === "[object String]" &&
|
|
122
|
-
!url.includes(obj.url):
|
|
116
|
+
case getType(obj.url) === "[object String]" && !url.includes(obj.url):
|
|
123
117
|
case getType(obj.url) === "[object RegExp]" && !obj.url.test(url):
|
|
124
|
-
case obj.method &&
|
|
125
|
-
obj.method.toUpperCase() !== method.toUpperCase():
|
|
118
|
+
case obj.method && obj.method.toUpperCase() !== method.toUpperCase():
|
|
126
119
|
case "async" in obj && obj.async !== async:
|
|
127
120
|
return false;
|
|
128
121
|
}
|
|
@@ -135,8 +128,7 @@ export const ajaxHooker = function () {
|
|
|
135
128
|
win.__ajaxHooker.hookInsts.forEach(({ hookFns, filters }) => {
|
|
136
129
|
if (this.shouldFilter(filters)) return;
|
|
137
130
|
hookFns.forEach((fn) => {
|
|
138
|
-
if (getType(fn) === "[object Function]")
|
|
139
|
-
catchError(fn, this.request);
|
|
131
|
+
if (getType(fn) === "[object Function]") catchError(fn, this.request);
|
|
140
132
|
});
|
|
141
133
|
for (const key in this.request) {
|
|
142
134
|
if (isThenable(this.request[key])) this._recoverRequestKey(key);
|
|
@@ -149,93 +141,72 @@ export const ajaxHooker = function () {
|
|
|
149
141
|
win.__ajaxHooker.hookInsts.forEach(({ hookFns, filters }) => {
|
|
150
142
|
if (this.shouldFilter(filters)) return;
|
|
151
143
|
promises.push(
|
|
152
|
-
Promise.all(hookFns.map((fn) => catchError(fn, this.request))).then(
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
(val) => (this.request[key] = val),
|
|
161
|
-
() => this._recoverRequestKey(key)
|
|
162
|
-
)
|
|
144
|
+
Promise.all(hookFns.map((fn) => catchError(fn, this.request))).then(() => {
|
|
145
|
+
const requestKeys = [];
|
|
146
|
+
for (const key in this.request) !ignoreKeys.has(key) && requestKeys.push(key);
|
|
147
|
+
return Promise.all(
|
|
148
|
+
requestKeys.map((key) =>
|
|
149
|
+
Promise.resolve(this.request[key]).then(
|
|
150
|
+
(val) => (this.request[key] = val),
|
|
151
|
+
() => this._recoverRequestKey(key)
|
|
163
152
|
)
|
|
164
|
-
)
|
|
165
|
-
|
|
166
|
-
)
|
|
153
|
+
)
|
|
154
|
+
);
|
|
155
|
+
})
|
|
167
156
|
);
|
|
168
157
|
});
|
|
169
158
|
return Promise.all(promises);
|
|
170
159
|
}
|
|
171
160
|
waitForResponseKeys(response) {
|
|
172
|
-
const responseKeys =
|
|
173
|
-
this.request.type === "xhr" ? xhrResponses : fetchResponses;
|
|
161
|
+
const responseKeys = this.request.type === "xhr" ? xhrResponses : fetchResponses;
|
|
174
162
|
if (!this.request.async) {
|
|
175
163
|
if (getType(this.request.response) === "[object Function]") {
|
|
176
164
|
catchError(this.request.response, response);
|
|
177
165
|
responseKeys.forEach((key) => {
|
|
178
|
-
if (
|
|
179
|
-
"get" in getDescriptor(response, key) ||
|
|
180
|
-
isThenable(response[key])
|
|
181
|
-
) {
|
|
166
|
+
if ("get" in getDescriptor(response, key) || isThenable(response[key])) {
|
|
182
167
|
delete response[key];
|
|
183
168
|
}
|
|
184
169
|
});
|
|
185
170
|
}
|
|
186
171
|
return new SyncThenable();
|
|
187
172
|
}
|
|
188
|
-
return Promise.resolve(catchError(this.request.response, response)).then(
|
|
189
|
-
(
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
)
|
|
173
|
+
return Promise.resolve(catchError(this.request.response, response)).then(() =>
|
|
174
|
+
Promise.all(
|
|
175
|
+
responseKeys.map((key) => {
|
|
176
|
+
const descriptor = getDescriptor(response, key);
|
|
177
|
+
if (descriptor && "value" in descriptor) {
|
|
178
|
+
return Promise.resolve(descriptor.value).then(
|
|
179
|
+
(val) => (response[key] = val),
|
|
180
|
+
() => delete response[key]
|
|
181
|
+
);
|
|
182
|
+
} else {
|
|
183
|
+
delete response[key];
|
|
184
|
+
}
|
|
185
|
+
})
|
|
186
|
+
)
|
|
203
187
|
);
|
|
204
188
|
}
|
|
205
189
|
}
|
|
206
190
|
const proxyHandler = {
|
|
207
191
|
get(target, prop) {
|
|
208
192
|
const descriptor = getDescriptor(target, prop);
|
|
209
|
-
if (
|
|
210
|
-
descriptor &&
|
|
211
|
-
!descriptor.configurable &&
|
|
212
|
-
!descriptor.writable &&
|
|
213
|
-
!descriptor.get
|
|
214
|
-
)
|
|
193
|
+
if (descriptor && !descriptor.configurable && !descriptor.writable && !descriptor.get)
|
|
215
194
|
return target[prop];
|
|
216
195
|
const ah = target.__ajaxHooker;
|
|
217
196
|
if (ah && ah.proxyProps) {
|
|
218
197
|
if (prop in ah.proxyProps) {
|
|
219
198
|
const pDescriptor = ah.proxyProps[prop];
|
|
220
199
|
if ("get" in pDescriptor) return pDescriptor.get();
|
|
221
|
-
if (typeof pDescriptor.value === "function")
|
|
222
|
-
return pDescriptor.value.bind(ah);
|
|
200
|
+
if (typeof pDescriptor.value === "function") return pDescriptor.value.bind(ah);
|
|
223
201
|
return pDescriptor.value;
|
|
224
202
|
}
|
|
225
|
-
if (typeof target[prop] === "function")
|
|
226
|
-
return target[prop].bind(target);
|
|
203
|
+
if (typeof target[prop] === "function") return target[prop].bind(target);
|
|
227
204
|
}
|
|
228
205
|
return target[prop];
|
|
229
206
|
},
|
|
230
207
|
set(target, prop, value) {
|
|
231
208
|
const descriptor = getDescriptor(target, prop);
|
|
232
|
-
if (
|
|
233
|
-
descriptor &&
|
|
234
|
-
!descriptor.configurable &&
|
|
235
|
-
!descriptor.writable &&
|
|
236
|
-
!descriptor.set
|
|
237
|
-
)
|
|
238
|
-
return true;
|
|
209
|
+
if (descriptor && !descriptor.configurable && !descriptor.writable && !descriptor.set) return true;
|
|
239
210
|
const ah = target.__ajaxHooker;
|
|
240
211
|
if (ah && ah.proxyProps && prop in ah.proxyProps) {
|
|
241
212
|
const pDescriptor = ah.proxyProps[prop];
|
|
@@ -257,11 +228,7 @@ export const ajaxHooker = function () {
|
|
|
257
228
|
proxyEvents: {},
|
|
258
229
|
});
|
|
259
230
|
xhr.addEventListener("readystatechange", (e) => {
|
|
260
|
-
if (
|
|
261
|
-
ah.proxyXhr.readyState === 4 &&
|
|
262
|
-
ah.request &&
|
|
263
|
-
typeof ah.request.response === "function"
|
|
264
|
-
) {
|
|
231
|
+
if (ah.proxyXhr.readyState === 4 && ah.request && typeof ah.request.response === "function") {
|
|
265
232
|
const response = {
|
|
266
233
|
finalUrl: ah.proxyXhr.responseURL,
|
|
267
234
|
status: ah.proxyXhr.status,
|
|
@@ -284,18 +251,16 @@ export const ajaxHooker = function () {
|
|
|
284
251
|
}
|
|
285
252
|
);
|
|
286
253
|
}
|
|
287
|
-
ah.resThenable = new AHRequest(ah.request)
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
}
|
|
298
|
-
});
|
|
254
|
+
ah.resThenable = new AHRequest(ah.request).waitForResponseKeys(response).then(() => {
|
|
255
|
+
for (const key of xhrResponses) {
|
|
256
|
+
ah.proxyProps[key] = {
|
|
257
|
+
get: () => {
|
|
258
|
+
if (!(key in response)) response[key] = tempValues[key];
|
|
259
|
+
return response[key];
|
|
260
|
+
},
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
});
|
|
299
264
|
}
|
|
300
265
|
ah.dispatchEvent(e);
|
|
301
266
|
});
|
|
@@ -308,13 +273,7 @@ export const ajaxHooker = function () {
|
|
|
308
273
|
set: (val) => ah.addEvent(onEvt, val),
|
|
309
274
|
};
|
|
310
275
|
}
|
|
311
|
-
for (const method of [
|
|
312
|
-
"setRequestHeader",
|
|
313
|
-
"addEventListener",
|
|
314
|
-
"removeEventListener",
|
|
315
|
-
"open",
|
|
316
|
-
"send",
|
|
317
|
-
]) {
|
|
276
|
+
for (const method of ["setRequestHeader", "addEventListener", "removeEventListener", "open", "send"]) {
|
|
318
277
|
ah.proxyProps[method] = { value: ah[method] };
|
|
319
278
|
}
|
|
320
279
|
}
|
|
@@ -323,8 +282,7 @@ export const ajaxHooker = function () {
|
|
|
323
282
|
if (type.startsWith("on")) {
|
|
324
283
|
this.proxyEvents[type] = typeof event === "function" ? event : null;
|
|
325
284
|
} else {
|
|
326
|
-
if (typeof event === "object" && event !== null)
|
|
327
|
-
event = event.handleEvent;
|
|
285
|
+
if (typeof event === "object" && event !== null) event = event.handleEvent;
|
|
328
286
|
if (typeof event !== "function") return;
|
|
329
287
|
this.proxyEvents[type] = this.proxyEvents[type] || new Set();
|
|
330
288
|
this.proxyEvents[type].add(event);
|
|
@@ -334,8 +292,7 @@ export const ajaxHooker = function () {
|
|
|
334
292
|
if (type.startsWith("on")) {
|
|
335
293
|
this.proxyEvents[type] = null;
|
|
336
294
|
} else {
|
|
337
|
-
if (typeof event === "object" && event !== null)
|
|
338
|
-
event = event.handleEvent;
|
|
295
|
+
if (typeof event === "object" && event !== null) event = event.handleEvent;
|
|
339
296
|
this.proxyEvents[type] && this.proxyEvents[type].delete(event);
|
|
340
297
|
}
|
|
341
298
|
}
|
|
@@ -346,9 +303,7 @@ export const ajaxHooker = function () {
|
|
|
346
303
|
defineProp(e, "srcElement", () => this.proxyXhr);
|
|
347
304
|
this.proxyEvents[e.type] &&
|
|
348
305
|
this.proxyEvents[e.type].forEach((fn) => {
|
|
349
|
-
this.resThenable.then(
|
|
350
|
-
() => !e.ajaxHooker_isStopped && fn.call(this.proxyXhr, e)
|
|
351
|
-
);
|
|
306
|
+
this.resThenable.then(() => !e.ajaxHooker_isStopped && fn.call(this.proxyXhr, e));
|
|
352
307
|
});
|
|
353
308
|
if (e.ajaxHooker_isStopped) return;
|
|
354
309
|
const onEvent = this.proxyEvents["on" + e.type];
|
|
@@ -358,8 +313,7 @@ export const ajaxHooker = function () {
|
|
|
358
313
|
this.originalXhr.setRequestHeader(header, value);
|
|
359
314
|
if (!this.request) return;
|
|
360
315
|
const headers = this.request.headers;
|
|
361
|
-
headers[header] =
|
|
362
|
-
header in headers ? `${headers[header]}, ${value}` : value;
|
|
316
|
+
headers[header] = header in headers ? `${headers[header]}, ${value}` : value;
|
|
363
317
|
}
|
|
364
318
|
addEventListener(...args) {
|
|
365
319
|
if (xhrAsyncEvents.includes(args[0])) {
|
|
@@ -388,13 +342,7 @@ export const ajaxHooker = function () {
|
|
|
388
342
|
};
|
|
389
343
|
this.openArgs = args;
|
|
390
344
|
this.resThenable = new SyncThenable();
|
|
391
|
-
[
|
|
392
|
-
"responseURL",
|
|
393
|
-
"readyState",
|
|
394
|
-
"status",
|
|
395
|
-
"statusText",
|
|
396
|
-
...xhrResponses,
|
|
397
|
-
].forEach((key) => {
|
|
345
|
+
["responseURL", "readyState", "status", "statusText", ...xhrResponses].forEach((key) => {
|
|
398
346
|
delete this.proxyProps[key];
|
|
399
347
|
});
|
|
400
348
|
return this.originalXhr.open(method, url, async, ...args);
|
|
@@ -431,15 +379,12 @@ export const ajaxHooker = function () {
|
|
|
431
379
|
}
|
|
432
380
|
function fakeXHR() {
|
|
433
381
|
const xhr = new winAh.realXHR();
|
|
434
|
-
if ("__ajaxHooker" in xhr)
|
|
435
|
-
console.warn("检测到不同版本的ajaxHooker,可能发生冲突!");
|
|
382
|
+
if ("__ajaxHooker" in xhr) console.warn("检测到不同版本的ajaxHooker,可能发生冲突!");
|
|
436
383
|
xhr.__ajaxHooker = new XhrHooker(xhr);
|
|
437
384
|
return xhr.__ajaxHooker.proxyXhr;
|
|
438
385
|
}
|
|
439
386
|
fakeXHR.prototype = win.XMLHttpRequest.prototype;
|
|
440
|
-
Object.keys(win.XMLHttpRequest).forEach(
|
|
441
|
-
(key) => (fakeXHR[key] = win.XMLHttpRequest[key])
|
|
442
|
-
);
|
|
387
|
+
Object.keys(win.XMLHttpRequest).forEach((key) => (fakeXHR[key] = win.XMLHttpRequest[key]));
|
|
443
388
|
function fakeFetch(url, options = {}) {
|
|
444
389
|
if (!url) return winAh.realFetch.call(win, url, options);
|
|
445
390
|
return new Promise(async (resolve, reject) => {
|
|
@@ -505,18 +450,22 @@ export const ajaxHooker = function () {
|
|
|
505
450
|
status: res.status,
|
|
506
451
|
responseHeaders: parseHeaders(res.headers),
|
|
507
452
|
};
|
|
508
|
-
|
|
509
|
-
(
|
|
510
|
-
(
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
453
|
+
if (res.ok) {
|
|
454
|
+
fetchResponses.forEach(
|
|
455
|
+
(key) =>
|
|
456
|
+
(res[key] = function () {
|
|
457
|
+
if (key in response) return Promise.resolve(response[key]);
|
|
458
|
+
return resProto[key].call(this).then((val) => {
|
|
459
|
+
response[key] = val;
|
|
460
|
+
return req
|
|
461
|
+
.waitForResponseKeys(response)
|
|
462
|
+
.then(() => (key in response ? response[key] : val));
|
|
463
|
+
});
|
|
464
|
+
})
|
|
465
|
+
);
|
|
466
|
+
} else {
|
|
467
|
+
catchError(request.response, response);
|
|
468
|
+
}
|
|
520
469
|
}
|
|
521
470
|
resolve(res);
|
|
522
471
|
}, reject);
|
|
@@ -538,8 +487,7 @@ export const ajaxHooker = function () {
|
|
|
538
487
|
realFetchClone: resProto.clone,
|
|
539
488
|
hookInsts: new Set(),
|
|
540
489
|
};
|
|
541
|
-
if (winAh.version !== version)
|
|
542
|
-
console.warn("检测到不同版本的ajaxHooker,可能发生冲突!");
|
|
490
|
+
if (winAh.version !== version) console.warn("检测到不同版本的ajaxHooker,可能发生冲突!");
|
|
543
491
|
win.XMLHttpRequest = winAh.fakeXHR;
|
|
544
492
|
win.fetch = winAh.fakeFetch;
|
|
545
493
|
resProto.clone = winAh.fakeFetchClone;
|
|
@@ -547,37 +495,25 @@ export const ajaxHooker = function () {
|
|
|
547
495
|
// 针对头条、抖音 secsdk.umd.js 的兼容性处理
|
|
548
496
|
class AHFunction extends Function {
|
|
549
497
|
call(thisArg, ...args) {
|
|
550
|
-
if (
|
|
551
|
-
thisArg &&
|
|
552
|
-
thisArg.__ajaxHooker &&
|
|
553
|
-
thisArg.__ajaxHooker.proxyXhr === thisArg
|
|
554
|
-
) {
|
|
498
|
+
if (thisArg && thisArg.__ajaxHooker && thisArg.__ajaxHooker.proxyXhr === thisArg) {
|
|
555
499
|
thisArg = thisArg.__ajaxHooker.originalXhr;
|
|
556
500
|
}
|
|
557
501
|
return Reflect.apply(this, thisArg, args);
|
|
558
502
|
}
|
|
559
503
|
apply(thisArg, args) {
|
|
560
|
-
if (
|
|
561
|
-
thisArg &&
|
|
562
|
-
thisArg.__ajaxHooker &&
|
|
563
|
-
thisArg.__ajaxHooker.proxyXhr === thisArg
|
|
564
|
-
) {
|
|
504
|
+
if (thisArg && thisArg.__ajaxHooker && thisArg.__ajaxHooker.proxyXhr === thisArg) {
|
|
565
505
|
thisArg = thisArg.__ajaxHooker.originalXhr;
|
|
566
506
|
}
|
|
567
507
|
return Reflect.apply(this, thisArg, args || []);
|
|
568
508
|
}
|
|
569
509
|
}
|
|
570
510
|
function hookSecsdk(csrf) {
|
|
571
|
-
Object.setPrototypeOf(
|
|
572
|
-
csrf.nativeXMLHttpRequestSetRequestHeader,
|
|
573
|
-
AHFunction.prototype
|
|
574
|
-
);
|
|
511
|
+
Object.setPrototypeOf(csrf.nativeXMLHttpRequestSetRequestHeader, AHFunction.prototype);
|
|
575
512
|
Object.setPrototypeOf(csrf.nativeXMLHttpRequestOpen, AHFunction.prototype);
|
|
576
513
|
Object.setPrototypeOf(csrf.nativeXMLHttpRequestSend, AHFunction.prototype);
|
|
577
514
|
}
|
|
578
515
|
if (win.secsdk) {
|
|
579
|
-
if (win.secsdk.csrf && win.secsdk.csrf.nativeXMLHttpRequestOpen)
|
|
580
|
-
hookSecsdk(win.secsdk.csrf);
|
|
516
|
+
if (win.secsdk.csrf && win.secsdk.csrf.nativeXMLHttpRequestOpen) hookSecsdk(win.secsdk.csrf);
|
|
581
517
|
} else {
|
|
582
518
|
defineProp(win, "secsdk", emptyFn, (secsdk) => {
|
|
583
519
|
delete win.secsdk;
|
package/src/indexedDB.ts
CHANGED
|
@@ -53,11 +53,7 @@ export class indexedDB {
|
|
|
53
53
|
* @param storeName 表名,默认为:default_form
|
|
54
54
|
* @param dbVersion indexDB的版本号,默认为:1
|
|
55
55
|
*/
|
|
56
|
-
constructor(
|
|
57
|
-
dbName = "default_db",
|
|
58
|
-
storeName = "default_form",
|
|
59
|
-
dbVersion = 1
|
|
60
|
-
) {
|
|
56
|
+
constructor(dbName = "default_db", storeName = "default_form", dbVersion = 1) {
|
|
61
57
|
this.#dbName = dbName;
|
|
62
58
|
this.#storeName = storeName;
|
|
63
59
|
this.#dbVersion = dbVersion;
|
|
@@ -72,10 +68,7 @@ export class indexedDB {
|
|
|
72
68
|
*/
|
|
73
69
|
createStore(dbName: string) {
|
|
74
70
|
let txn, store;
|
|
75
|
-
txn = this.#db[dbName].transaction(
|
|
76
|
-
this.#storeName,
|
|
77
|
-
"readwrite"
|
|
78
|
-
) as IDBTransaction;
|
|
71
|
+
txn = this.#db[dbName].transaction(this.#storeName, "readwrite") as IDBTransaction;
|
|
79
72
|
/* IndexDB的读写权限 */
|
|
80
73
|
store = txn.objectStore(this.#storeName) as IDBObjectStore;
|
|
81
74
|
// this.#store = store;
|
|
@@ -367,9 +360,7 @@ export class indexedDB {
|
|
|
367
360
|
} else {
|
|
368
361
|
let request = idbStore.getAll();
|
|
369
362
|
request.onsuccess = function (event: any) {
|
|
370
|
-
let target = event.target as IDBRequest<
|
|
371
|
-
{ key: string; value: T }[]
|
|
372
|
-
>;
|
|
363
|
+
let target = event.target as IDBRequest<{ key: string; value: T }[]>;
|
|
373
364
|
let result = target.result;
|
|
374
365
|
if (result.length !== 0) {
|
|
375
366
|
result.forEach((dataItem, index) => {
|
package/src/types/Event.d.ts
CHANGED
|
@@ -40,8 +40,7 @@ declare interface DOMUtils_Frame_Object_Event {
|
|
|
40
40
|
scroll: Event;
|
|
41
41
|
unload: Event;
|
|
42
42
|
}
|
|
43
|
-
declare type DOMUtils_Frame_Object_EventType =
|
|
44
|
-
keyof DOMUtils_Frame_Object_Event;
|
|
43
|
+
declare type DOMUtils_Frame_Object_EventType = keyof DOMUtils_Frame_Object_Event;
|
|
45
44
|
/**
|
|
46
45
|
* 表单事件
|
|
47
46
|
*/
|
package/src/types/Httpx.d.ts
CHANGED
|
@@ -66,14 +66,7 @@ export type HttpxStatus =
|
|
|
66
66
|
* HTTP WebDav的请求方法
|
|
67
67
|
* + https://blog.csdn.net/weixin_48421613/article/details/128611546
|
|
68
68
|
*/
|
|
69
|
-
export type HttpxWebDavMethod =
|
|
70
|
-
| "PROPFIND"
|
|
71
|
-
| "PROPPATCH"
|
|
72
|
-
| "MKCOL"
|
|
73
|
-
| "MOVE"
|
|
74
|
-
| "COPY"
|
|
75
|
-
| "LOCK"
|
|
76
|
-
| "UNLOCK";
|
|
69
|
+
export type HttpxWebDavMethod = "PROPFIND" | "PROPPATCH" | "MKCOL" | "MOVE" | "COPY" | "LOCK" | "UNLOCK";
|
|
77
70
|
|
|
78
71
|
/**
|
|
79
72
|
* HTTP 请求方法
|
|
@@ -99,21 +92,12 @@ export type HttpxRedirect = "follow" | "error" | "manual";
|
|
|
99
92
|
/**
|
|
100
93
|
* 二进制数据
|
|
101
94
|
*/
|
|
102
|
-
export type HttpxBinary =
|
|
103
|
-
| Uint8ArrayConstructor
|
|
104
|
-
| ArrayBufferConstructor
|
|
105
|
-
| DataViewConstructor
|
|
106
|
-
| Blob
|
|
107
|
-
| File;
|
|
95
|
+
export type HttpxBinary = Uint8ArrayConstructor | ArrayBufferConstructor | DataViewConstructor | Blob | File;
|
|
108
96
|
|
|
109
97
|
/**
|
|
110
98
|
* 触发的响应函数名
|
|
111
99
|
*/
|
|
112
|
-
export type HttpxResponseCallBackType =
|
|
113
|
-
| "onload"
|
|
114
|
-
| "onerror"
|
|
115
|
-
| "ontimeout"
|
|
116
|
-
| "onabort";
|
|
100
|
+
export type HttpxResponseCallBackType = "onload" | "onerror" | "ontimeout" | "onabort";
|
|
117
101
|
|
|
118
102
|
/**
|
|
119
103
|
* 响应类型映射字典
|
|
@@ -1356,5 +1340,4 @@ export declare interface HttpxInitOption extends HttpxRequestOption {
|
|
|
1356
1340
|
logDetails?: boolean;
|
|
1357
1341
|
}
|
|
1358
1342
|
|
|
1359
|
-
export declare interface HttpxRequestOptionWithDoubleParams
|
|
1360
|
-
extends Omit<HttpxRequestOption, "url"> {}
|
|
1343
|
+
export declare interface HttpxRequestOptionWithDoubleParams extends Omit<HttpxRequestOption, "url"> {}
|