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