@whitesev/utils 2.5.7 → 2.5.9
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 +902 -47
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +902 -47
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +902 -47
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +902 -47
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +902 -47
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +902 -47
- package/dist/index.umd.js.map +1 -1
- package/dist/types/src/ModuleRaid.d.ts +171 -0
- package/dist/types/src/TryCatch.d.ts +2 -2
- package/dist/types/src/Utils.d.ts +6 -3
- package/dist/types/src/ajaxHooker/ajaxHooker1.2.4.d.ts +6 -0
- package/package.json +1 -1
- package/src/ModuleRaid.js +397 -0
- package/src/Utils.ts +13 -3
- package/src/ajaxHooker/ajaxHooker1.2.4.js +447 -0
package/dist/index.esm.js
CHANGED
|
@@ -243,7 +243,7 @@ class UtilsGMCookie {
|
|
|
243
243
|
throw new TypeError("Utils.GMCookie.get 参数cookieName 必须为字符串");
|
|
244
244
|
}
|
|
245
245
|
let cookies = this.windowApi.document.cookie.split(";");
|
|
246
|
-
let findValue =
|
|
246
|
+
let findValue = undefined;
|
|
247
247
|
for (const cookieItem of cookies) {
|
|
248
248
|
let item = cookieItem.trim();
|
|
249
249
|
let itemSplit = item.split("=");
|
|
@@ -1277,14 +1277,14 @@ class GMMenu {
|
|
|
1277
1277
|
const option = menuOption[index];
|
|
1278
1278
|
this.MenuHandle.$data.data.push({
|
|
1279
1279
|
data: option,
|
|
1280
|
-
id:
|
|
1280
|
+
id: undefined,
|
|
1281
1281
|
});
|
|
1282
1282
|
}
|
|
1283
1283
|
}
|
|
1284
1284
|
else {
|
|
1285
1285
|
this.MenuHandle.$data.data.push({
|
|
1286
1286
|
data: menuOption,
|
|
1287
|
-
id:
|
|
1287
|
+
id: undefined,
|
|
1288
1288
|
});
|
|
1289
1289
|
}
|
|
1290
1290
|
}
|
|
@@ -2412,13 +2412,13 @@ class Httpx {
|
|
|
2412
2412
|
status: fetchResponse.status,
|
|
2413
2413
|
statusText: fetchResponse.statusText,
|
|
2414
2414
|
// @ts-ignore
|
|
2415
|
-
response:
|
|
2415
|
+
response: undefined,
|
|
2416
2416
|
responseFetchHeaders: fetchResponse.headers,
|
|
2417
2417
|
responseHeaders: "",
|
|
2418
2418
|
// @ts-ignore
|
|
2419
|
-
responseText:
|
|
2419
|
+
responseText: undefined,
|
|
2420
2420
|
responseType: option.responseType,
|
|
2421
|
-
responseXML:
|
|
2421
|
+
responseXML: undefined,
|
|
2422
2422
|
};
|
|
2423
2423
|
Object.assign(httpxResponse, option.context || {});
|
|
2424
2424
|
// 把headers转为字符串
|
|
@@ -2530,30 +2530,30 @@ class Httpx {
|
|
|
2530
2530
|
* 默认配置
|
|
2531
2531
|
*/
|
|
2532
2532
|
#defaultDetails = {
|
|
2533
|
-
url:
|
|
2533
|
+
url: undefined,
|
|
2534
2534
|
timeout: 5000,
|
|
2535
2535
|
async: false,
|
|
2536
|
-
responseType:
|
|
2537
|
-
headers:
|
|
2538
|
-
data:
|
|
2539
|
-
redirect:
|
|
2540
|
-
cookie:
|
|
2541
|
-
cookiePartition:
|
|
2542
|
-
binary:
|
|
2543
|
-
nocache:
|
|
2544
|
-
revalidate:
|
|
2545
|
-
context:
|
|
2546
|
-
overrideMimeType:
|
|
2547
|
-
anonymous:
|
|
2548
|
-
fetch:
|
|
2549
|
-
fetchInit:
|
|
2536
|
+
responseType: undefined,
|
|
2537
|
+
headers: undefined,
|
|
2538
|
+
data: undefined,
|
|
2539
|
+
redirect: undefined,
|
|
2540
|
+
cookie: undefined,
|
|
2541
|
+
cookiePartition: undefined,
|
|
2542
|
+
binary: undefined,
|
|
2543
|
+
nocache: undefined,
|
|
2544
|
+
revalidate: undefined,
|
|
2545
|
+
context: undefined,
|
|
2546
|
+
overrideMimeType: undefined,
|
|
2547
|
+
anonymous: undefined,
|
|
2548
|
+
fetch: undefined,
|
|
2549
|
+
fetchInit: undefined,
|
|
2550
2550
|
allowInterceptConfig: {
|
|
2551
2551
|
beforeRequest: true,
|
|
2552
2552
|
afterResponseSuccess: true,
|
|
2553
2553
|
afterResponseError: true,
|
|
2554
2554
|
},
|
|
2555
|
-
user:
|
|
2556
|
-
password:
|
|
2555
|
+
user: undefined,
|
|
2556
|
+
password: undefined,
|
|
2557
2557
|
onabort() { },
|
|
2558
2558
|
onerror() { },
|
|
2559
2559
|
ontimeout() { },
|
|
@@ -3037,7 +3037,7 @@ class indexedDB {
|
|
|
3037
3037
|
success: false,
|
|
3038
3038
|
code: that.#statusCode.getFailed.code,
|
|
3039
3039
|
msg: that.#statusCode.getFailed.msg,
|
|
3040
|
-
data:
|
|
3040
|
+
data: undefined,
|
|
3041
3041
|
});
|
|
3042
3042
|
}
|
|
3043
3043
|
else {
|
|
@@ -3047,7 +3047,7 @@ class indexedDB {
|
|
|
3047
3047
|
let result = target.result;
|
|
3048
3048
|
/* result 返回的是 {key: string, value: any} */
|
|
3049
3049
|
/* 键值对存储 */
|
|
3050
|
-
let data = result ? result.value :
|
|
3050
|
+
let data = result ? result.value : undefined;
|
|
3051
3051
|
if (data == null) {
|
|
3052
3052
|
resolve({
|
|
3053
3053
|
success: true,
|
|
@@ -3074,7 +3074,7 @@ class indexedDB {
|
|
|
3074
3074
|
success: false,
|
|
3075
3075
|
code: that.#statusCode.getFailed.code,
|
|
3076
3076
|
msg: that.#statusCode.getFailed.msg,
|
|
3077
|
-
data:
|
|
3077
|
+
data: undefined,
|
|
3078
3078
|
event: event,
|
|
3079
3079
|
});
|
|
3080
3080
|
};
|
|
@@ -3654,7 +3654,7 @@ const TryCatch = function (...args) {
|
|
|
3654
3654
|
context = __context__ || this;
|
|
3655
3655
|
let result = executeTryCatch(callbackFunction, handleError, context);
|
|
3656
3656
|
// @ts-ignore
|
|
3657
|
-
return result !==
|
|
3657
|
+
return result !== undefined ? result : TryCatchCore;
|
|
3658
3658
|
},
|
|
3659
3659
|
};
|
|
3660
3660
|
/**
|
|
@@ -3665,7 +3665,7 @@ const TryCatch = function (...args) {
|
|
|
3665
3665
|
* @returns 如果函数有返回值,则返回该返回值;否则返回 undefined。
|
|
3666
3666
|
*/
|
|
3667
3667
|
function executeTryCatch(callback, handleErrorFunc, funcThis) {
|
|
3668
|
-
let result =
|
|
3668
|
+
let result = undefined;
|
|
3669
3669
|
try {
|
|
3670
3670
|
if (typeof callback === "string") {
|
|
3671
3671
|
(function () {
|
|
@@ -3733,7 +3733,7 @@ class UtilsDictionary {
|
|
|
3733
3733
|
*/
|
|
3734
3734
|
getStartsWith(key) {
|
|
3735
3735
|
let allKeys = this.keys();
|
|
3736
|
-
let result =
|
|
3736
|
+
let result = undefined;
|
|
3737
3737
|
for (const keyName of allKeys) {
|
|
3738
3738
|
if (String(keyName).startsWith(String(key))) {
|
|
3739
3739
|
result = this.get(keyName);
|
|
@@ -3748,7 +3748,7 @@ class UtilsDictionary {
|
|
|
3748
3748
|
* @param val 值,默认为""
|
|
3749
3749
|
*/
|
|
3750
3750
|
set(key, val) {
|
|
3751
|
-
if (key ===
|
|
3751
|
+
if (key === undefined) {
|
|
3752
3752
|
throw new Error("Utils.Dictionary().set 参数 key 不能为空");
|
|
3753
3753
|
}
|
|
3754
3754
|
Reflect.set(this.items, key, val);
|
|
@@ -4133,13 +4133,859 @@ class Vue {
|
|
|
4133
4133
|
}
|
|
4134
4134
|
}
|
|
4135
4135
|
|
|
4136
|
+
// ==UserScript==
|
|
4137
|
+
// @name ModuleRaid.js
|
|
4138
|
+
// @namespace http://tampermonkey.net/
|
|
4139
|
+
// @version 6.2.0
|
|
4140
|
+
// @description 检索调用webpackJsonp模块,可指定检索的window
|
|
4141
|
+
// @author empyrealtear
|
|
4142
|
+
// @license MIT
|
|
4143
|
+
// @original-script https://github.com/pixeldesu/moduleRaid
|
|
4144
|
+
// ==/UserScript==
|
|
4145
|
+
|
|
4146
|
+
|
|
4147
|
+
/**
|
|
4148
|
+
* Main moduleRaid class
|
|
4149
|
+
* @link https://scriptcat.org/zh-CN/script-show-page/2628
|
|
4150
|
+
*/
|
|
4151
|
+
class ModuleRaid {
|
|
4152
|
+
/**
|
|
4153
|
+
* moduleRaid constructor
|
|
4154
|
+
*
|
|
4155
|
+
* @example
|
|
4156
|
+
* Constructing an instance without any arguments:
|
|
4157
|
+
* ```ts
|
|
4158
|
+
* const mR = new ModuleRaid()
|
|
4159
|
+
* ```
|
|
4160
|
+
*
|
|
4161
|
+
* Constructing an instance with the optional `opts` object:
|
|
4162
|
+
* ```ts
|
|
4163
|
+
* const mR = new ModuleRaid({ entrypoint: 'webpackChunk_custom_name' })
|
|
4164
|
+
* ```
|
|
4165
|
+
*
|
|
4166
|
+
* @param opts a object containing options to initialize moduleRaid with
|
|
4167
|
+
* - **opts:**
|
|
4168
|
+
* - _target_: the window object being searched for
|
|
4169
|
+
* - _entrypoint_: the Webpack entrypoint present on the global window object
|
|
4170
|
+
* - _debug_: whether debug mode is enabled or not
|
|
4171
|
+
* - _strict_: whether strict mode is enabled or not
|
|
4172
|
+
*/
|
|
4173
|
+
constructor(opts) {
|
|
4174
|
+
/**
|
|
4175
|
+
* A random generated module ID we use for injecting into Webpack
|
|
4176
|
+
*/
|
|
4177
|
+
this.moduleID = Math.random().toString(36).substring(7);
|
|
4178
|
+
/**
|
|
4179
|
+
* An array containing different argument injection methods for
|
|
4180
|
+
* Webpack (before version 4), and subsequently pulling out methods and modules
|
|
4181
|
+
* @internal
|
|
4182
|
+
*/
|
|
4183
|
+
this.functionArguments = [
|
|
4184
|
+
[
|
|
4185
|
+
[0],
|
|
4186
|
+
[
|
|
4187
|
+
(_e, _t, i) => {
|
|
4188
|
+
this.modules = i.c;
|
|
4189
|
+
this.constructors = i.m;
|
|
4190
|
+
this.get = i;
|
|
4191
|
+
},
|
|
4192
|
+
],
|
|
4193
|
+
],
|
|
4194
|
+
[
|
|
4195
|
+
[1e3],
|
|
4196
|
+
{
|
|
4197
|
+
[this.moduleID]: (_e, _t, i) => {
|
|
4198
|
+
this.modules = i.c;
|
|
4199
|
+
this.constructors = i.m;
|
|
4200
|
+
this.get = i;
|
|
4201
|
+
},
|
|
4202
|
+
},
|
|
4203
|
+
[[this.moduleID]],
|
|
4204
|
+
],
|
|
4205
|
+
];
|
|
4206
|
+
/**
|
|
4207
|
+
* An array containing different argument injection methods for
|
|
4208
|
+
* Webpack (after version 4), and subsequently pulling out methods and modules
|
|
4209
|
+
* @internal
|
|
4210
|
+
*/
|
|
4211
|
+
this.arrayArguments = [
|
|
4212
|
+
[
|
|
4213
|
+
[this.moduleID],
|
|
4214
|
+
{},
|
|
4215
|
+
(e) => {
|
|
4216
|
+
const mCac = e.m;
|
|
4217
|
+
Object.keys(mCac).forEach((mod) => {
|
|
4218
|
+
try {
|
|
4219
|
+
this.modules[mod] = e(mod);
|
|
4220
|
+
}
|
|
4221
|
+
catch (err) {
|
|
4222
|
+
this.log(`[arrayArguments/1] Failed to require(${mod}) with error:\n${err}\n${err.stack}`);
|
|
4223
|
+
}
|
|
4224
|
+
});
|
|
4225
|
+
this.get = e;
|
|
4226
|
+
},
|
|
4227
|
+
],
|
|
4228
|
+
this.functionArguments[1],
|
|
4229
|
+
];
|
|
4230
|
+
/**
|
|
4231
|
+
* Storage for the modules we extracted from Webpack
|
|
4232
|
+
*/
|
|
4233
|
+
this.modules = {};
|
|
4234
|
+
/**
|
|
4235
|
+
* Storage for the constructors we extracted from Webpack
|
|
4236
|
+
*/
|
|
4237
|
+
this.constructors = [];
|
|
4238
|
+
let options = {
|
|
4239
|
+
target: window,
|
|
4240
|
+
entrypoint: 'webpackJsonp',
|
|
4241
|
+
debug: false,
|
|
4242
|
+
strict: false,
|
|
4243
|
+
};
|
|
4244
|
+
if (typeof opts === 'object') {
|
|
4245
|
+
options = Object.assign(Object.assign({}, options), opts);
|
|
4246
|
+
}
|
|
4247
|
+
this.target = options.target;
|
|
4248
|
+
this.entrypoint = options.entrypoint;
|
|
4249
|
+
this.debug = options.debug;
|
|
4250
|
+
this.strict = options.strict;
|
|
4251
|
+
this.detectEntrypoint();
|
|
4252
|
+
this.fillModules();
|
|
4253
|
+
this.replaceGet();
|
|
4254
|
+
this.setupPushEvent();
|
|
4255
|
+
}
|
|
4256
|
+
/**
|
|
4257
|
+
* Debug logging method, outputs to the console when {@link ModuleRaid.debug} is true
|
|
4258
|
+
*
|
|
4259
|
+
* @param {*} message The message to be logged
|
|
4260
|
+
* @internal
|
|
4261
|
+
*/
|
|
4262
|
+
log(message) {
|
|
4263
|
+
if (this.debug) {
|
|
4264
|
+
console.warn(`[moduleRaid] ${message}`);
|
|
4265
|
+
}
|
|
4266
|
+
}
|
|
4267
|
+
/**
|
|
4268
|
+
* Method to set an alternative getter if we weren't able to extract __webpack_require__
|
|
4269
|
+
* from Webpack
|
|
4270
|
+
* @internal
|
|
4271
|
+
*/
|
|
4272
|
+
replaceGet() {
|
|
4273
|
+
if (this.get === null) {
|
|
4274
|
+
this.get = (key) => this.modules[key];
|
|
4275
|
+
}
|
|
4276
|
+
}
|
|
4277
|
+
/**
|
|
4278
|
+
* Method that will try to inject a module into Webpack or get modules
|
|
4279
|
+
* depending on it's success it might be more or less brute about it
|
|
4280
|
+
* @internal
|
|
4281
|
+
*/
|
|
4282
|
+
fillModules() {
|
|
4283
|
+
if (typeof this.target[this.entrypoint] === 'function') {
|
|
4284
|
+
this.functionArguments.forEach((argument, index) => {
|
|
4285
|
+
try {
|
|
4286
|
+
if (this.modules && Object.keys(this.modules).length > 0)
|
|
4287
|
+
return;
|
|
4288
|
+
this.target[this.entrypoint](...argument);
|
|
4289
|
+
}
|
|
4290
|
+
catch (err) {
|
|
4291
|
+
this.log(`moduleRaid.functionArguments[${index}] failed:\n${err}\n${err.stack}`);
|
|
4292
|
+
}
|
|
4293
|
+
});
|
|
4294
|
+
}
|
|
4295
|
+
else {
|
|
4296
|
+
this.arrayArguments.forEach((argument, index) => {
|
|
4297
|
+
try {
|
|
4298
|
+
if (this.modules && Object.keys(this.modules).length > 0)
|
|
4299
|
+
return;
|
|
4300
|
+
this.target[this.entrypoint].push(argument);
|
|
4301
|
+
}
|
|
4302
|
+
catch (err) {
|
|
4303
|
+
this.log(`Pushing moduleRaid.arrayArguments[${index}] into ${this.entrypoint} failed:\n${err}\n${err.stack}`);
|
|
4304
|
+
}
|
|
4305
|
+
});
|
|
4306
|
+
}
|
|
4307
|
+
if (this.modules && Object.keys(this.modules).length == 0) {
|
|
4308
|
+
let moduleEnd = false;
|
|
4309
|
+
let moduleIterator = 0;
|
|
4310
|
+
if (typeof this.target[this.entrypoint] != 'function' || !this.target[this.entrypoint]([], [], [moduleIterator])) {
|
|
4311
|
+
throw Error('Unknown Webpack structure');
|
|
4312
|
+
}
|
|
4313
|
+
while (!moduleEnd) {
|
|
4314
|
+
try {
|
|
4315
|
+
this.modules[moduleIterator] = this.target[this.entrypoint]([], [], [moduleIterator]);
|
|
4316
|
+
moduleIterator++;
|
|
4317
|
+
}
|
|
4318
|
+
catch (err) {
|
|
4319
|
+
moduleEnd = true;
|
|
4320
|
+
}
|
|
4321
|
+
}
|
|
4322
|
+
}
|
|
4323
|
+
}
|
|
4324
|
+
/**
|
|
4325
|
+
* Method to hook into `window[this.entrypoint].push` adding a listener for new
|
|
4326
|
+
* chunks being pushed into Webpack
|
|
4327
|
+
*
|
|
4328
|
+
* @example
|
|
4329
|
+
* You can listen for newly pushed packages using the `moduleraid:webpack-push` event
|
|
4330
|
+
* on `document`
|
|
4331
|
+
*
|
|
4332
|
+
* ```ts
|
|
4333
|
+
* document.addEventListener('moduleraid:webpack-push', (e) => {
|
|
4334
|
+
* // e.detail contains the arguments push() was called with
|
|
4335
|
+
* console.log(e.detail)
|
|
4336
|
+
* })
|
|
4337
|
+
* ```
|
|
4338
|
+
* @internal
|
|
4339
|
+
*/
|
|
4340
|
+
setupPushEvent() {
|
|
4341
|
+
const originalPush = this.target[this.entrypoint].push;
|
|
4342
|
+
this.target[this.entrypoint].push = (...args) => {
|
|
4343
|
+
const result = Reflect.apply(originalPush, this.target[this.entrypoint], args);
|
|
4344
|
+
document.dispatchEvent(new CustomEvent('moduleraid:webpack-push', { detail: args }));
|
|
4345
|
+
return result;
|
|
4346
|
+
};
|
|
4347
|
+
}
|
|
4348
|
+
/**
|
|
4349
|
+
* Method to try autodetecting a Webpack JSONP entrypoint based on common naming
|
|
4350
|
+
*
|
|
4351
|
+
* If the default entrypoint, or the entrypoint that's passed to the moduleRaid constructor
|
|
4352
|
+
* already matches, the method exits early
|
|
4353
|
+
*
|
|
4354
|
+
* If `options.strict` has been set in the constructor and the initial entrypoint cannot
|
|
4355
|
+
* be found, this method will error, demanding a strictly set entrypoint
|
|
4356
|
+
* @internal
|
|
4357
|
+
*/
|
|
4358
|
+
detectEntrypoint() {
|
|
4359
|
+
if (this.target[this.entrypoint] != undefined) {
|
|
4360
|
+
return;
|
|
4361
|
+
}
|
|
4362
|
+
if (this.strict) {
|
|
4363
|
+
throw Error(`Strict mode is enabled and entrypoint at window.${this.entrypoint} couldn't be found. Please specify the correct one!`);
|
|
4364
|
+
}
|
|
4365
|
+
let windowObjects = Object.keys(this.target);
|
|
4366
|
+
windowObjects = windowObjects
|
|
4367
|
+
.filter((object) => object.toLowerCase().includes('chunk') || object.toLowerCase().includes('webpack'))
|
|
4368
|
+
.filter((object) => typeof this.target[object] === 'function' || Array.isArray(this.target[object]));
|
|
4369
|
+
if (windowObjects.length > 1) {
|
|
4370
|
+
throw Error(`Multiple possible endpoints have been detected, please create a new moduleRaid instance with a specific one:\n${windowObjects.join(', ')}`);
|
|
4371
|
+
}
|
|
4372
|
+
if (windowObjects.length === 0) {
|
|
4373
|
+
throw Error('No Webpack JSONP entrypoints could be detected');
|
|
4374
|
+
}
|
|
4375
|
+
this.log(`Entrypoint has been detected at window.${windowObjects[0]} and set for injection`);
|
|
4376
|
+
this.entrypoint = windowObjects[0];
|
|
4377
|
+
}
|
|
4378
|
+
/**
|
|
4379
|
+
* Recursive object-search function for modules
|
|
4380
|
+
*
|
|
4381
|
+
* @param object the object to search through
|
|
4382
|
+
* @param query the query the object keys/values are searched for
|
|
4383
|
+
* @returns boolean state of `object` containing `query` somewhere in it
|
|
4384
|
+
* @internal
|
|
4385
|
+
*/
|
|
4386
|
+
searchObject(object, query) {
|
|
4387
|
+
for (const key in object) {
|
|
4388
|
+
const value = object[key];
|
|
4389
|
+
const lowerCaseQuery = query.toLowerCase();
|
|
4390
|
+
if (typeof value != 'object') {
|
|
4391
|
+
const lowerCaseKey = key.toString().toLowerCase();
|
|
4392
|
+
if (lowerCaseKey.includes(lowerCaseQuery))
|
|
4393
|
+
return true;
|
|
4394
|
+
if (typeof value != 'object') {
|
|
4395
|
+
const lowerCaseValue = value.toString().toLowerCase();
|
|
4396
|
+
if (lowerCaseValue.includes(lowerCaseQuery))
|
|
4397
|
+
return true;
|
|
4398
|
+
}
|
|
4399
|
+
else {
|
|
4400
|
+
if (this.searchObject(value, query))
|
|
4401
|
+
return true;
|
|
4402
|
+
}
|
|
4403
|
+
}
|
|
4404
|
+
}
|
|
4405
|
+
return false;
|
|
4406
|
+
}
|
|
4407
|
+
/**
|
|
4408
|
+
* Method to search through the module object, searching for the fitting content
|
|
4409
|
+
* if a string is supplied
|
|
4410
|
+
*
|
|
4411
|
+
* If query is supplied as a function, everything that returns true when passed
|
|
4412
|
+
* to the query function will be returned
|
|
4413
|
+
*
|
|
4414
|
+
* @example
|
|
4415
|
+
* With a string as query argument:
|
|
4416
|
+
* ```ts
|
|
4417
|
+
* const results = mR.findModule('feature')
|
|
4418
|
+
* // => Array of module results
|
|
4419
|
+
* ```
|
|
4420
|
+
*
|
|
4421
|
+
* With a function as query argument:
|
|
4422
|
+
* ```ts
|
|
4423
|
+
* const results = mR.findModule((module) => { typeof module === 'function' })
|
|
4424
|
+
* // => Array of module results
|
|
4425
|
+
* ```
|
|
4426
|
+
*
|
|
4427
|
+
* @param query query to search the module list for
|
|
4428
|
+
* @return a list of modules fitting the query
|
|
4429
|
+
*/
|
|
4430
|
+
findModule(query) {
|
|
4431
|
+
const results = [];
|
|
4432
|
+
const modules = Object.keys(this.modules);
|
|
4433
|
+
if (modules.length === 0) {
|
|
4434
|
+
throw new Error('There are no modules to search through!');
|
|
4435
|
+
}
|
|
4436
|
+
modules.forEach((key) => {
|
|
4437
|
+
const module = this.modules[key.toString()];
|
|
4438
|
+
if (module === undefined)
|
|
4439
|
+
return;
|
|
4440
|
+
try {
|
|
4441
|
+
if (typeof query === 'string') {
|
|
4442
|
+
query = query.toLowerCase();
|
|
4443
|
+
switch (typeof module) {
|
|
4444
|
+
case 'string':
|
|
4445
|
+
if (module.toLowerCase().includes(query))
|
|
4446
|
+
results.push(module);
|
|
4447
|
+
break;
|
|
4448
|
+
case 'function':
|
|
4449
|
+
if (module.toString().toLowerCase().includes(query))
|
|
4450
|
+
results.push(module);
|
|
4451
|
+
break;
|
|
4452
|
+
case 'object':
|
|
4453
|
+
if (this.searchObject(module, query))
|
|
4454
|
+
results.push(module);
|
|
4455
|
+
break;
|
|
4456
|
+
}
|
|
4457
|
+
}
|
|
4458
|
+
else if (typeof query === 'function') {
|
|
4459
|
+
if (query(module))
|
|
4460
|
+
results.push(module);
|
|
4461
|
+
}
|
|
4462
|
+
else {
|
|
4463
|
+
throw new TypeError(`findModule can only find via string and function, ${typeof query} was passed`);
|
|
4464
|
+
}
|
|
4465
|
+
}
|
|
4466
|
+
catch (err) {
|
|
4467
|
+
this.log(`There was an error while searching through module '${key}':\n${err}\n${err.stack}`);
|
|
4468
|
+
}
|
|
4469
|
+
});
|
|
4470
|
+
return results;
|
|
4471
|
+
}
|
|
4472
|
+
/**
|
|
4473
|
+
* Method to search through the constructor array, searching for the fitting content
|
|
4474
|
+
* if a string is supplied
|
|
4475
|
+
*
|
|
4476
|
+
* If query is supplied as a function, everything that returns true when passed
|
|
4477
|
+
* to the query function will be returned
|
|
4478
|
+
*
|
|
4479
|
+
* @example
|
|
4480
|
+
* With a string as query argument:
|
|
4481
|
+
* ```ts
|
|
4482
|
+
* const results = mR.findConstructor('feature')
|
|
4483
|
+
* // => Array of constructor/module tuples
|
|
4484
|
+
* ```
|
|
4485
|
+
*
|
|
4486
|
+
* With a function as query argument:
|
|
4487
|
+
* ```ts
|
|
4488
|
+
* const results = mR.findConstructor((constructor) => { constructor.prototype.value !== undefined })
|
|
4489
|
+
* // => Array of constructor/module tuples
|
|
4490
|
+
* ```
|
|
4491
|
+
*
|
|
4492
|
+
* Accessing the resulting data:
|
|
4493
|
+
* ```ts
|
|
4494
|
+
* // With array destructuring (ES6)
|
|
4495
|
+
* const [constructor, module] = results[0]
|
|
4496
|
+
*
|
|
4497
|
+
* // ...or...
|
|
4498
|
+
*
|
|
4499
|
+
* // regular access
|
|
4500
|
+
* const constructor = results[0][0]
|
|
4501
|
+
* const module = results[0][1]
|
|
4502
|
+
* ```
|
|
4503
|
+
*
|
|
4504
|
+
* @param query query to search the constructor list for
|
|
4505
|
+
* @returns a list of constructor/module tuples fitting the query
|
|
4506
|
+
*/
|
|
4507
|
+
findConstructor(query) {
|
|
4508
|
+
const results = [];
|
|
4509
|
+
const constructors = Object.keys(this.constructors);
|
|
4510
|
+
if (constructors.length === 0) {
|
|
4511
|
+
throw new Error('There are no constructors to search through!');
|
|
4512
|
+
}
|
|
4513
|
+
constructors.forEach((key) => {
|
|
4514
|
+
const constructor = this.constructors[key];
|
|
4515
|
+
try {
|
|
4516
|
+
if (typeof query === 'string') {
|
|
4517
|
+
query = query.toLowerCase();
|
|
4518
|
+
if (constructor.toString().toLowerCase().includes(query))
|
|
4519
|
+
results.push([this.constructors[key], this.modules[key]]);
|
|
4520
|
+
}
|
|
4521
|
+
else if (typeof query === 'function') {
|
|
4522
|
+
if (query(constructor))
|
|
4523
|
+
results.push([this.constructors[key], this.modules[key]]);
|
|
4524
|
+
}
|
|
4525
|
+
}
|
|
4526
|
+
catch (err) {
|
|
4527
|
+
this.log(`There was an error while searching through constructor '${key}':\n${err}\n${err.stack}`);
|
|
4528
|
+
}
|
|
4529
|
+
});
|
|
4530
|
+
return results;
|
|
4531
|
+
}
|
|
4532
|
+
}
|
|
4533
|
+
|
|
4534
|
+
// ==UserScript==
|
|
4535
|
+
// @name ajaxHooker
|
|
4536
|
+
// @author cxxjackie
|
|
4537
|
+
// @version 1.2.4
|
|
4538
|
+
// @supportURL https://bbs.tampermonkey.net.cn/thread-3284-1-1.html
|
|
4539
|
+
// ==/UserScript==
|
|
4540
|
+
|
|
4541
|
+
const AjaxHooker1_2_4 = function () {
|
|
4542
|
+
return (function () {
|
|
4543
|
+
const win = window.unsafeWindow || document.defaultView || window;
|
|
4544
|
+
const hookFns = [];
|
|
4545
|
+
const realXhr = win.XMLHttpRequest;
|
|
4546
|
+
const resProto = win.Response.prototype;
|
|
4547
|
+
const toString = Object.prototype.toString;
|
|
4548
|
+
const realFetch = win.fetch;
|
|
4549
|
+
const xhrResponses = ["response", "responseText", "responseXML"];
|
|
4550
|
+
const fetchResponses = ["arrayBuffer", "blob", "formData", "json", "text"];
|
|
4551
|
+
const xhrAsyncEvents = ["readystatechange", "load", "loadend"];
|
|
4552
|
+
let filter;
|
|
4553
|
+
function emptyFn() {}
|
|
4554
|
+
function errorFn(err) {
|
|
4555
|
+
console.error(err);
|
|
4556
|
+
}
|
|
4557
|
+
function defineProp(obj, prop, getter, setter) {
|
|
4558
|
+
Object.defineProperty(obj, prop, {
|
|
4559
|
+
configurable: true,
|
|
4560
|
+
enumerable: true,
|
|
4561
|
+
get: getter,
|
|
4562
|
+
set: setter,
|
|
4563
|
+
});
|
|
4564
|
+
}
|
|
4565
|
+
function readonly(obj, prop, value = obj[prop]) {
|
|
4566
|
+
defineProp(obj, prop, () => value, emptyFn);
|
|
4567
|
+
}
|
|
4568
|
+
function writable(obj, prop, value = obj[prop]) {
|
|
4569
|
+
Object.defineProperty(obj, prop, {
|
|
4570
|
+
configurable: true,
|
|
4571
|
+
enumerable: true,
|
|
4572
|
+
writable: true,
|
|
4573
|
+
value: value,
|
|
4574
|
+
});
|
|
4575
|
+
}
|
|
4576
|
+
function toFilterObj(obj) {
|
|
4577
|
+
return {
|
|
4578
|
+
type: obj.type,
|
|
4579
|
+
url: obj.url,
|
|
4580
|
+
method: obj.method && obj.method.toUpperCase(),
|
|
4581
|
+
};
|
|
4582
|
+
}
|
|
4583
|
+
function shouldFilter(type, url, method) {
|
|
4584
|
+
return (
|
|
4585
|
+
filter &&
|
|
4586
|
+
!filter.find(
|
|
4587
|
+
(obj) =>
|
|
4588
|
+
(!obj.type || obj.type === type) &&
|
|
4589
|
+
(!obj.url ||
|
|
4590
|
+
(toString.call(obj.url) === "[object String]"
|
|
4591
|
+
? url.includes(obj.url)
|
|
4592
|
+
: obj.url.test(url))) &&
|
|
4593
|
+
(!obj.method || obj.method === method.toUpperCase())
|
|
4594
|
+
)
|
|
4595
|
+
);
|
|
4596
|
+
}
|
|
4597
|
+
function lookupGetter(obj, prop) {
|
|
4598
|
+
let getter;
|
|
4599
|
+
let proto = obj;
|
|
4600
|
+
while (proto) {
|
|
4601
|
+
const descriptor = Object.getOwnPropertyDescriptor(proto, prop);
|
|
4602
|
+
getter = descriptor && descriptor.get;
|
|
4603
|
+
if (getter) break;
|
|
4604
|
+
proto = Object.getPrototypeOf(proto);
|
|
4605
|
+
}
|
|
4606
|
+
return getter ? getter.bind(obj) : emptyFn;
|
|
4607
|
+
}
|
|
4608
|
+
function waitForHookFns(request) {
|
|
4609
|
+
return Promise.all(
|
|
4610
|
+
hookFns.map((fn) => Promise.resolve(fn(request)).then(emptyFn, errorFn))
|
|
4611
|
+
);
|
|
4612
|
+
}
|
|
4613
|
+
function waitForRequestKeys(request, requestClone) {
|
|
4614
|
+
return Promise.all(
|
|
4615
|
+
["url", "method", "abort", "headers", "data"].map((key) => {
|
|
4616
|
+
return Promise.resolve(request[key]).then(
|
|
4617
|
+
(val) => (request[key] = val),
|
|
4618
|
+
() => (request[key] = requestClone[key])
|
|
4619
|
+
);
|
|
4620
|
+
})
|
|
4621
|
+
);
|
|
4622
|
+
}
|
|
4623
|
+
function fakeEventSIP() {
|
|
4624
|
+
this.ajaxHooker_stopped = true;
|
|
4625
|
+
}
|
|
4626
|
+
function xhrDelegateEvent(e) {
|
|
4627
|
+
const xhr = e.target;
|
|
4628
|
+
e.stopImmediatePropagation = fakeEventSIP;
|
|
4629
|
+
xhr.__ajaxHooker.hookedEvents[e.type].forEach(
|
|
4630
|
+
(fn) => !e.ajaxHooker_stopped && fn.call(xhr, e)
|
|
4631
|
+
);
|
|
4632
|
+
const onEvent = xhr.__ajaxHooker.hookedEvents["on" + e.type];
|
|
4633
|
+
typeof onEvent === "function" && onEvent.call(xhr, e);
|
|
4634
|
+
}
|
|
4635
|
+
function xhrReadyStateChange(e) {
|
|
4636
|
+
if (e.target.readyState === 4) {
|
|
4637
|
+
e.target.dispatchEvent(
|
|
4638
|
+
new CustomEvent("ajaxHooker_responseReady", { detail: e })
|
|
4639
|
+
);
|
|
4640
|
+
} else {
|
|
4641
|
+
e.target.__ajaxHooker.delegateEvent(e);
|
|
4642
|
+
}
|
|
4643
|
+
}
|
|
4644
|
+
function xhrLoadAndLoadend(e) {
|
|
4645
|
+
e.target.__ajaxHooker.delegateEvent(e);
|
|
4646
|
+
}
|
|
4647
|
+
function fakeXhrOpen(method, url, ...args) {
|
|
4648
|
+
const ah = this.__ajaxHooker;
|
|
4649
|
+
ah.url = url.toString();
|
|
4650
|
+
ah.method = method.toUpperCase();
|
|
4651
|
+
ah.openArgs = args;
|
|
4652
|
+
ah.headers = {};
|
|
4653
|
+
return ah.originalMethods.open(method, url, ...args);
|
|
4654
|
+
}
|
|
4655
|
+
function fakeXhr() {
|
|
4656
|
+
const xhr = new realXhr();
|
|
4657
|
+
let ah = xhr.__ajaxHooker;
|
|
4658
|
+
if (!ah) {
|
|
4659
|
+
ah = xhr.__ajaxHooker = {
|
|
4660
|
+
headers: {},
|
|
4661
|
+
hookedEvents: {
|
|
4662
|
+
readystatechange: new Set(),
|
|
4663
|
+
load: new Set(),
|
|
4664
|
+
loadend: new Set(),
|
|
4665
|
+
},
|
|
4666
|
+
delegateEvent: xhrDelegateEvent,
|
|
4667
|
+
originalGetters: {},
|
|
4668
|
+
originalMethods: {},
|
|
4669
|
+
};
|
|
4670
|
+
xhr.addEventListener("readystatechange", xhrReadyStateChange);
|
|
4671
|
+
xhr.addEventListener("load", xhrLoadAndLoadend);
|
|
4672
|
+
xhr.addEventListener("loadend", xhrLoadAndLoadend);
|
|
4673
|
+
for (const key of xhrResponses) {
|
|
4674
|
+
ah.originalGetters[key] = lookupGetter(xhr, key);
|
|
4675
|
+
}
|
|
4676
|
+
for (const method of [
|
|
4677
|
+
"open",
|
|
4678
|
+
"setRequestHeader",
|
|
4679
|
+
"addEventListener",
|
|
4680
|
+
"removeEventListener",
|
|
4681
|
+
]) {
|
|
4682
|
+
ah.originalMethods[method] = xhr[method].bind(xhr);
|
|
4683
|
+
}
|
|
4684
|
+
xhr.open = fakeXhrOpen;
|
|
4685
|
+
xhr.setRequestHeader = (header, value) => {
|
|
4686
|
+
ah.originalMethods.setRequestHeader(header, value);
|
|
4687
|
+
if (xhr.readyState === 1) {
|
|
4688
|
+
if (ah.headers[header]) {
|
|
4689
|
+
ah.headers[header] += ", " + value;
|
|
4690
|
+
} else {
|
|
4691
|
+
ah.headers[header] = value;
|
|
4692
|
+
}
|
|
4693
|
+
}
|
|
4694
|
+
};
|
|
4695
|
+
xhr.addEventListener = function (...args) {
|
|
4696
|
+
if (xhrAsyncEvents.includes(args[0])) {
|
|
4697
|
+
ah.hookedEvents[args[0]].add(args[1]);
|
|
4698
|
+
} else {
|
|
4699
|
+
ah.originalMethods.addEventListener(...args);
|
|
4700
|
+
}
|
|
4701
|
+
};
|
|
4702
|
+
xhr.removeEventListener = function (...args) {
|
|
4703
|
+
if (xhrAsyncEvents.includes(args[0])) {
|
|
4704
|
+
ah.hookedEvents[args[0]].delete(args[1]);
|
|
4705
|
+
} else {
|
|
4706
|
+
ah.originalMethods.removeEventListener(...args);
|
|
4707
|
+
}
|
|
4708
|
+
};
|
|
4709
|
+
xhrAsyncEvents.forEach((evt) => {
|
|
4710
|
+
const onEvt = "on" + evt;
|
|
4711
|
+
defineProp(
|
|
4712
|
+
xhr,
|
|
4713
|
+
onEvt,
|
|
4714
|
+
() => {
|
|
4715
|
+
return ah.hookedEvents[onEvt] || null;
|
|
4716
|
+
},
|
|
4717
|
+
(val) => {
|
|
4718
|
+
ah.hookedEvents[onEvt] = typeof val === "function" ? val : null;
|
|
4719
|
+
}
|
|
4720
|
+
);
|
|
4721
|
+
});
|
|
4722
|
+
}
|
|
4723
|
+
const realSend = xhr.send.bind(xhr);
|
|
4724
|
+
xhr.send = function (data) {
|
|
4725
|
+
if (xhr.readyState !== 1) return realSend(data);
|
|
4726
|
+
ah.delegateEvent = xhrDelegateEvent;
|
|
4727
|
+
xhrResponses.forEach((prop) => {
|
|
4728
|
+
delete xhr[prop]; // delete descriptor
|
|
4729
|
+
});
|
|
4730
|
+
if (shouldFilter("xhr", ah.url, ah.method)) {
|
|
4731
|
+
xhr.addEventListener("ajaxHooker_responseReady", (e) => {
|
|
4732
|
+
ah.delegateEvent(e.detail);
|
|
4733
|
+
});
|
|
4734
|
+
return realSend(data);
|
|
4735
|
+
}
|
|
4736
|
+
try {
|
|
4737
|
+
const request = {
|
|
4738
|
+
type: "xhr",
|
|
4739
|
+
url: ah.url,
|
|
4740
|
+
method: ah.method,
|
|
4741
|
+
abort: false,
|
|
4742
|
+
headers: ah.headers,
|
|
4743
|
+
data: data,
|
|
4744
|
+
response: null,
|
|
4745
|
+
};
|
|
4746
|
+
const requestClone = { ...request };
|
|
4747
|
+
waitForHookFns(request).then(() => {
|
|
4748
|
+
waitForRequestKeys(request, requestClone).then(() => {
|
|
4749
|
+
if (request.abort) return;
|
|
4750
|
+
ah.originalMethods.open(
|
|
4751
|
+
request.method,
|
|
4752
|
+
request.url,
|
|
4753
|
+
...ah.openArgs
|
|
4754
|
+
);
|
|
4755
|
+
for (const header in request.headers) {
|
|
4756
|
+
ah.originalMethods.setRequestHeader(
|
|
4757
|
+
header,
|
|
4758
|
+
request.headers[header]
|
|
4759
|
+
);
|
|
4760
|
+
}
|
|
4761
|
+
data = request.data;
|
|
4762
|
+
xhr.addEventListener("ajaxHooker_responseReady", (e) => {
|
|
4763
|
+
try {
|
|
4764
|
+
if (typeof request.response === "function") {
|
|
4765
|
+
const arg = {
|
|
4766
|
+
finalUrl: xhr.responseURL,
|
|
4767
|
+
status: xhr.status,
|
|
4768
|
+
responseHeaders: {},
|
|
4769
|
+
};
|
|
4770
|
+
for (const line of xhr
|
|
4771
|
+
.getAllResponseHeaders()
|
|
4772
|
+
.trim()
|
|
4773
|
+
.split(/[\r\n]+/)) {
|
|
4774
|
+
const parts = line.split(/:\s*/);
|
|
4775
|
+
if (parts.length === 2) {
|
|
4776
|
+
const lheader = parts[0].toLowerCase();
|
|
4777
|
+
if (arg.responseHeaders[lheader]) {
|
|
4778
|
+
arg.responseHeaders[lheader] += ", " + parts[1];
|
|
4779
|
+
} else {
|
|
4780
|
+
arg.responseHeaders[lheader] = parts[1];
|
|
4781
|
+
}
|
|
4782
|
+
}
|
|
4783
|
+
}
|
|
4784
|
+
xhrResponses.forEach((prop) => {
|
|
4785
|
+
defineProp(
|
|
4786
|
+
arg,
|
|
4787
|
+
prop,
|
|
4788
|
+
() => {
|
|
4789
|
+
return (arg[prop] = ah.originalGetters[prop]());
|
|
4790
|
+
},
|
|
4791
|
+
(val) => {
|
|
4792
|
+
delete arg[prop];
|
|
4793
|
+
arg[prop] = val;
|
|
4794
|
+
}
|
|
4795
|
+
);
|
|
4796
|
+
defineProp(xhr, prop, () => {
|
|
4797
|
+
const val = ah.originalGetters[prop]();
|
|
4798
|
+
xhr.dispatchEvent(
|
|
4799
|
+
new CustomEvent("ajaxHooker_readResponse", {
|
|
4800
|
+
detail: { prop, val },
|
|
4801
|
+
})
|
|
4802
|
+
);
|
|
4803
|
+
return val;
|
|
4804
|
+
});
|
|
4805
|
+
});
|
|
4806
|
+
xhr.addEventListener("ajaxHooker_readResponse", (e) => {
|
|
4807
|
+
arg[e.detail.prop] = e.detail.val;
|
|
4808
|
+
});
|
|
4809
|
+
const resPromise = Promise.resolve(
|
|
4810
|
+
request.response(arg)
|
|
4811
|
+
).then(() => {
|
|
4812
|
+
const task = [];
|
|
4813
|
+
xhrResponses.forEach((prop) => {
|
|
4814
|
+
const descriptor = Object.getOwnPropertyDescriptor(
|
|
4815
|
+
arg,
|
|
4816
|
+
prop
|
|
4817
|
+
);
|
|
4818
|
+
if (descriptor && "value" in descriptor) {
|
|
4819
|
+
task.push(
|
|
4820
|
+
Promise.resolve(descriptor.value).then((val) => {
|
|
4821
|
+
arg[prop] = val;
|
|
4822
|
+
defineProp(xhr, prop, () => {
|
|
4823
|
+
xhr.dispatchEvent(
|
|
4824
|
+
new CustomEvent("ajaxHooker_readResponse", {
|
|
4825
|
+
detail: { prop, val },
|
|
4826
|
+
})
|
|
4827
|
+
);
|
|
4828
|
+
return val;
|
|
4829
|
+
});
|
|
4830
|
+
}, emptyFn)
|
|
4831
|
+
);
|
|
4832
|
+
}
|
|
4833
|
+
});
|
|
4834
|
+
return Promise.all(task);
|
|
4835
|
+
}, errorFn);
|
|
4836
|
+
const eventsClone = {};
|
|
4837
|
+
xhrAsyncEvents.forEach((type) => {
|
|
4838
|
+
eventsClone[type] = new Set([...ah.hookedEvents[type]]);
|
|
4839
|
+
eventsClone["on" + type] = ah.hookedEvents["on" + type];
|
|
4840
|
+
});
|
|
4841
|
+
ah.delegateEvent = (event) =>
|
|
4842
|
+
resPromise.then(() => {
|
|
4843
|
+
event.stopImmediatePropagation = fakeEventSIP;
|
|
4844
|
+
eventsClone[event.type].forEach(
|
|
4845
|
+
(fn) =>
|
|
4846
|
+
!event.ajaxHooker_stopped && fn.call(xhr, event)
|
|
4847
|
+
);
|
|
4848
|
+
const onEvent = eventsClone["on" + event.type];
|
|
4849
|
+
typeof onEvent === "function" &&
|
|
4850
|
+
onEvent.call(xhr, event);
|
|
4851
|
+
});
|
|
4852
|
+
}
|
|
4853
|
+
} catch (err) {
|
|
4854
|
+
console.error(err);
|
|
4855
|
+
}
|
|
4856
|
+
ah.delegateEvent(e.detail);
|
|
4857
|
+
});
|
|
4858
|
+
realSend(data);
|
|
4859
|
+
});
|
|
4860
|
+
});
|
|
4861
|
+
} catch (err) {
|
|
4862
|
+
console.error(err);
|
|
4863
|
+
realSend(data);
|
|
4864
|
+
}
|
|
4865
|
+
};
|
|
4866
|
+
return xhr;
|
|
4867
|
+
}
|
|
4868
|
+
function hookFetchResponse(response, arg, callback) {
|
|
4869
|
+
fetchResponses.forEach((prop) => {
|
|
4870
|
+
response[prop] = () =>
|
|
4871
|
+
new Promise((resolve, reject) => {
|
|
4872
|
+
resProto[prop].call(response).then((res) => {
|
|
4873
|
+
if (prop in arg) {
|
|
4874
|
+
resolve(arg[prop]);
|
|
4875
|
+
} else {
|
|
4876
|
+
try {
|
|
4877
|
+
arg[prop] = res;
|
|
4878
|
+
Promise.resolve(callback(arg)).then(() => {
|
|
4879
|
+
if (prop in arg) {
|
|
4880
|
+
Promise.resolve(arg[prop]).then(
|
|
4881
|
+
(val) => resolve((arg[prop] = val)),
|
|
4882
|
+
() => resolve(res)
|
|
4883
|
+
);
|
|
4884
|
+
} else {
|
|
4885
|
+
resolve(res);
|
|
4886
|
+
}
|
|
4887
|
+
}, errorFn);
|
|
4888
|
+
} catch (err) {
|
|
4889
|
+
console.error(err);
|
|
4890
|
+
resolve(res);
|
|
4891
|
+
}
|
|
4892
|
+
}
|
|
4893
|
+
}, reject);
|
|
4894
|
+
});
|
|
4895
|
+
});
|
|
4896
|
+
}
|
|
4897
|
+
function fakeFetch(url, init) {
|
|
4898
|
+
if (url && typeof url.toString === "function") {
|
|
4899
|
+
url = url.toString();
|
|
4900
|
+
init = init || {};
|
|
4901
|
+
init.method = init.method || "GET";
|
|
4902
|
+
init.headers = init.headers || {};
|
|
4903
|
+
if (shouldFilter("fetch", url, init.method))
|
|
4904
|
+
return realFetch.call(win, url, init);
|
|
4905
|
+
const request = {
|
|
4906
|
+
type: "fetch",
|
|
4907
|
+
url: url,
|
|
4908
|
+
method: init.method.toUpperCase(),
|
|
4909
|
+
abort: false,
|
|
4910
|
+
headers: {},
|
|
4911
|
+
data: init.body,
|
|
4912
|
+
response: null,
|
|
4913
|
+
};
|
|
4914
|
+
if (toString.call(init.headers) === "[object Headers]") {
|
|
4915
|
+
for (const [key, val] of init.headers) {
|
|
4916
|
+
request.headers[key] = val;
|
|
4917
|
+
}
|
|
4918
|
+
} else {
|
|
4919
|
+
request.headers = { ...init.headers };
|
|
4920
|
+
}
|
|
4921
|
+
const requestClone = { ...request };
|
|
4922
|
+
return new Promise((resolve, reject) => {
|
|
4923
|
+
try {
|
|
4924
|
+
waitForHookFns(request).then(() => {
|
|
4925
|
+
waitForRequestKeys(request, requestClone).then(() => {
|
|
4926
|
+
if (request.abort) return reject("aborted");
|
|
4927
|
+
url = request.url;
|
|
4928
|
+
init.method = request.method;
|
|
4929
|
+
init.headers = request.headers;
|
|
4930
|
+
init.body = request.data;
|
|
4931
|
+
realFetch.call(win, url, init).then((response) => {
|
|
4932
|
+
if (typeof request.response === "function") {
|
|
4933
|
+
const arg = {
|
|
4934
|
+
finalUrl: response.url,
|
|
4935
|
+
status: response.status,
|
|
4936
|
+
responseHeaders: {},
|
|
4937
|
+
};
|
|
4938
|
+
for (const [key, val] of response.headers) {
|
|
4939
|
+
arg.responseHeaders[key] = val;
|
|
4940
|
+
}
|
|
4941
|
+
hookFetchResponse(response, arg, request.response);
|
|
4942
|
+
response.clone = () => {
|
|
4943
|
+
const resClone = resProto.clone.call(response);
|
|
4944
|
+
hookFetchResponse(resClone, arg, request.response);
|
|
4945
|
+
return resClone;
|
|
4946
|
+
};
|
|
4947
|
+
}
|
|
4948
|
+
resolve(response);
|
|
4949
|
+
}, reject);
|
|
4950
|
+
});
|
|
4951
|
+
});
|
|
4952
|
+
} catch (err) {
|
|
4953
|
+
console.error(err);
|
|
4954
|
+
return realFetch.call(win, url, init);
|
|
4955
|
+
}
|
|
4956
|
+
});
|
|
4957
|
+
} else {
|
|
4958
|
+
return realFetch.call(win, url, init);
|
|
4959
|
+
}
|
|
4960
|
+
}
|
|
4961
|
+
win.XMLHttpRequest = fakeXhr;
|
|
4962
|
+
Object.keys(realXhr).forEach((key) => (fakeXhr[key] = realXhr[key]));
|
|
4963
|
+
fakeXhr.prototype = realXhr.prototype;
|
|
4964
|
+
win.fetch = fakeFetch;
|
|
4965
|
+
return {
|
|
4966
|
+
hook: (fn) => hookFns.push(fn),
|
|
4967
|
+
filter: (arr) => {
|
|
4968
|
+
filter = Array.isArray(arr) && arr.map(toFilterObj);
|
|
4969
|
+
},
|
|
4970
|
+
protect: () => {
|
|
4971
|
+
readonly(win, "XMLHttpRequest", fakeXhr);
|
|
4972
|
+
readonly(win, "fetch", fakeFetch);
|
|
4973
|
+
},
|
|
4974
|
+
unhook: () => {
|
|
4975
|
+
writable(win, "XMLHttpRequest", realXhr);
|
|
4976
|
+
writable(win, "fetch", realFetch);
|
|
4977
|
+
},
|
|
4978
|
+
};
|
|
4979
|
+
})();
|
|
4980
|
+
};
|
|
4981
|
+
|
|
4136
4982
|
class Utils {
|
|
4137
4983
|
windowApi;
|
|
4138
4984
|
constructor(option) {
|
|
4139
4985
|
this.windowApi = new WindowApi(option);
|
|
4140
4986
|
}
|
|
4141
4987
|
/** 版本号 */
|
|
4142
|
-
version = "2025.1.
|
|
4988
|
+
version = "2025.1.11";
|
|
4143
4989
|
addStyle(cssText) {
|
|
4144
4990
|
if (typeof cssText !== "string") {
|
|
4145
4991
|
throw new Error("Utils.addStyle 参数cssText 必须为String类型");
|
|
@@ -4259,10 +5105,18 @@ class Utils {
|
|
|
4259
5105
|
* ajax劫持库,支持xhr和fetch劫持。
|
|
4260
5106
|
* + 来源:https://bbs.tampermonkey.net.cn/thread-3284-1-1.html
|
|
4261
5107
|
* + 作者:cxxjackie
|
|
4262
|
-
* + 版本:1.4.
|
|
5108
|
+
* + 版本:1.4.3
|
|
4263
5109
|
* + 文档:https://scriptcat.org/zh-CN/script-show-page/637/
|
|
5110
|
+
* @param useOldVersion 是否使用旧版本,默认false
|
|
4264
5111
|
*/
|
|
4265
|
-
ajaxHooker =
|
|
5112
|
+
ajaxHooker = (useOldVersion = false) => {
|
|
5113
|
+
if (useOldVersion) {
|
|
5114
|
+
return AjaxHooker1_2_4();
|
|
5115
|
+
}
|
|
5116
|
+
else {
|
|
5117
|
+
return AjaxHooker();
|
|
5118
|
+
}
|
|
5119
|
+
};
|
|
4266
5120
|
canvasClickByPosition(canvasElement, clientX = 0, clientY = 0, view = globalThis) {
|
|
4267
5121
|
if (!(canvasElement instanceof HTMLCanvasElement)) {
|
|
4268
5122
|
throw new Error("Utils.canvasClickByPosition 参数canvasElement必须是canvas元素");
|
|
@@ -4362,8 +5216,8 @@ class Utils {
|
|
|
4362
5216
|
ColorConversion = ColorConversion;
|
|
4363
5217
|
deepClone(obj) {
|
|
4364
5218
|
let UtilsContext = this;
|
|
4365
|
-
if (obj ===
|
|
4366
|
-
return
|
|
5219
|
+
if (obj === undefined)
|
|
5220
|
+
return undefined;
|
|
4367
5221
|
if (obj === null)
|
|
4368
5222
|
return null;
|
|
4369
5223
|
let clone = obj instanceof Array ? [] : {};
|
|
@@ -5809,36 +6663,36 @@ class Utils {
|
|
|
5809
6663
|
* + true 监听以 target 为根节点的整个子树。包括子树中所有节点的属性,而不仅仅是针对 target
|
|
5810
6664
|
* + false (默认) 不生效
|
|
5811
6665
|
*/
|
|
5812
|
-
subtree:
|
|
6666
|
+
subtree: undefined,
|
|
5813
6667
|
/**
|
|
5814
6668
|
* + true 监听 target 节点中发生的节点的新增与删除(同时,如果 subtree 为 true,会针对整个子树生效)
|
|
5815
6669
|
* + false (默认) 不生效
|
|
5816
6670
|
*/
|
|
5817
|
-
childList:
|
|
6671
|
+
childList: undefined,
|
|
5818
6672
|
/**
|
|
5819
6673
|
* + true 观察所有监听的节点属性值的变化。默认值为 true,当声明了 attributeFilter 或 attributeOldValue
|
|
5820
6674
|
* + false (默认) 不生效
|
|
5821
6675
|
*/
|
|
5822
|
-
attributes:
|
|
6676
|
+
attributes: undefined,
|
|
5823
6677
|
/**
|
|
5824
6678
|
* 一个用于声明哪些属性名会被监听的数组。如果不声明该属性,所有属性的变化都将触发通知
|
|
5825
6679
|
*/
|
|
5826
|
-
attributeFilter:
|
|
6680
|
+
attributeFilter: undefined,
|
|
5827
6681
|
/**
|
|
5828
6682
|
* + true 记录上一次被监听的节点的属性变化;可查阅 MutationObserver 中的 Monitoring attribute values 了解关于观察属性变化和属性值记录的详情
|
|
5829
6683
|
* + false (默认) 不生效
|
|
5830
6684
|
*/
|
|
5831
|
-
attributeOldValue:
|
|
6685
|
+
attributeOldValue: undefined,
|
|
5832
6686
|
/**
|
|
5833
6687
|
* + true 监听声明的 target 节点上所有字符的变化。默认值为 true,如果声明了 characterDataOldValue
|
|
5834
6688
|
* + false (默认) 不生效
|
|
5835
6689
|
*/
|
|
5836
|
-
characterData:
|
|
6690
|
+
characterData: undefined,
|
|
5837
6691
|
/**
|
|
5838
6692
|
* + true 记录前一个被监听的节点中发生的文本变化
|
|
5839
6693
|
* + false (默认) 不生效
|
|
5840
6694
|
*/
|
|
5841
|
-
characterDataOldValue:
|
|
6695
|
+
characterDataOldValue: undefined,
|
|
5842
6696
|
},
|
|
5843
6697
|
immediate: false,
|
|
5844
6698
|
};
|
|
@@ -6413,7 +7267,7 @@ class Utils {
|
|
|
6413
7267
|
}
|
|
6414
7268
|
return new Promise((resolve) => {
|
|
6415
7269
|
setTimeout(() => {
|
|
6416
|
-
resolve(
|
|
7270
|
+
resolve(undefined);
|
|
6417
7271
|
}, delayTime);
|
|
6418
7272
|
});
|
|
6419
7273
|
}
|
|
@@ -6788,7 +7642,7 @@ class Utils {
|
|
|
6788
7642
|
}
|
|
6789
7643
|
waitNode(...args) {
|
|
6790
7644
|
// 过滤掉undefined
|
|
6791
|
-
args = args.filter((arg) => arg !==
|
|
7645
|
+
args = args.filter((arg) => arg !== undefined);
|
|
6792
7646
|
let UtilsContext = this;
|
|
6793
7647
|
// 选择器
|
|
6794
7648
|
let selector = args[0];
|
|
@@ -6877,7 +7731,7 @@ class Utils {
|
|
|
6877
7731
|
}
|
|
6878
7732
|
waitAnyNode(...args) {
|
|
6879
7733
|
// 过滤掉undefined
|
|
6880
|
-
args = args.filter((arg) => arg !==
|
|
7734
|
+
args = args.filter((arg) => arg !== undefined);
|
|
6881
7735
|
let UtilsContext = this;
|
|
6882
7736
|
// 选择器
|
|
6883
7737
|
let selectorList = args[0];
|
|
@@ -6933,7 +7787,7 @@ class Utils {
|
|
|
6933
7787
|
}
|
|
6934
7788
|
waitNodeList(...args) {
|
|
6935
7789
|
// 过滤掉undefined
|
|
6936
|
-
args = args.filter((arg) => arg !==
|
|
7790
|
+
args = args.filter((arg) => arg !== undefined);
|
|
6937
7791
|
let UtilsContext = this;
|
|
6938
7792
|
// 选择器数组
|
|
6939
7793
|
let selector = args[0];
|
|
@@ -7020,7 +7874,7 @@ class Utils {
|
|
|
7020
7874
|
}
|
|
7021
7875
|
waitAnyNodeList(...args) {
|
|
7022
7876
|
// 过滤掉undefined
|
|
7023
|
-
args = args.filter((arg) => arg !==
|
|
7877
|
+
args = args.filter((arg) => arg !== undefined);
|
|
7024
7878
|
let UtilsContext = this;
|
|
7025
7879
|
// 选择器数组
|
|
7026
7880
|
let selectorList = args[0];
|
|
@@ -7318,6 +8172,7 @@ class Utils {
|
|
|
7318
8172
|
* > "测试"
|
|
7319
8173
|
*/
|
|
7320
8174
|
Vue = Vue;
|
|
8175
|
+
ModuleRaid = ModuleRaid;
|
|
7321
8176
|
}
|
|
7322
8177
|
let utils = new Utils();
|
|
7323
8178
|
|