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