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