@whitesev/utils 2.5.6 → 2.5.8
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 +541 -135
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +541 -135
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +541 -135
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +541 -135
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +541 -135
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +541 -135
- 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 +69 -20
- package/dist/types/src/types/global.d.ts +1 -0
- package/package.json +1 -1
- package/src/ModuleRaid.js +397 -0
- package/src/Utils.ts +205 -113
- package/src/types/global.d.ts +1 -0
package/dist/index.umd.js
CHANGED
|
@@ -249,7 +249,7 @@
|
|
|
249
249
|
throw new TypeError("Utils.GMCookie.get 参数cookieName 必须为字符串");
|
|
250
250
|
}
|
|
251
251
|
let cookies = this.windowApi.document.cookie.split(";");
|
|
252
|
-
let findValue =
|
|
252
|
+
let findValue = undefined;
|
|
253
253
|
for (const cookieItem of cookies) {
|
|
254
254
|
let item = cookieItem.trim();
|
|
255
255
|
let itemSplit = item.split("=");
|
|
@@ -1283,14 +1283,14 @@
|
|
|
1283
1283
|
const option = menuOption[index];
|
|
1284
1284
|
this.MenuHandle.$data.data.push({
|
|
1285
1285
|
data: option,
|
|
1286
|
-
id:
|
|
1286
|
+
id: undefined,
|
|
1287
1287
|
});
|
|
1288
1288
|
}
|
|
1289
1289
|
}
|
|
1290
1290
|
else {
|
|
1291
1291
|
this.MenuHandle.$data.data.push({
|
|
1292
1292
|
data: menuOption,
|
|
1293
|
-
id:
|
|
1293
|
+
id: undefined,
|
|
1294
1294
|
});
|
|
1295
1295
|
}
|
|
1296
1296
|
}
|
|
@@ -2418,13 +2418,13 @@
|
|
|
2418
2418
|
status: fetchResponse.status,
|
|
2419
2419
|
statusText: fetchResponse.statusText,
|
|
2420
2420
|
// @ts-ignore
|
|
2421
|
-
response:
|
|
2421
|
+
response: undefined,
|
|
2422
2422
|
responseFetchHeaders: fetchResponse.headers,
|
|
2423
2423
|
responseHeaders: "",
|
|
2424
2424
|
// @ts-ignore
|
|
2425
|
-
responseText:
|
|
2425
|
+
responseText: undefined,
|
|
2426
2426
|
responseType: option.responseType,
|
|
2427
|
-
responseXML:
|
|
2427
|
+
responseXML: undefined,
|
|
2428
2428
|
};
|
|
2429
2429
|
Object.assign(httpxResponse, option.context || {});
|
|
2430
2430
|
// 把headers转为字符串
|
|
@@ -2536,30 +2536,30 @@
|
|
|
2536
2536
|
* 默认配置
|
|
2537
2537
|
*/
|
|
2538
2538
|
#defaultDetails = {
|
|
2539
|
-
url:
|
|
2539
|
+
url: undefined,
|
|
2540
2540
|
timeout: 5000,
|
|
2541
2541
|
async: false,
|
|
2542
|
-
responseType:
|
|
2543
|
-
headers:
|
|
2544
|
-
data:
|
|
2545
|
-
redirect:
|
|
2546
|
-
cookie:
|
|
2547
|
-
cookiePartition:
|
|
2548
|
-
binary:
|
|
2549
|
-
nocache:
|
|
2550
|
-
revalidate:
|
|
2551
|
-
context:
|
|
2552
|
-
overrideMimeType:
|
|
2553
|
-
anonymous:
|
|
2554
|
-
fetch:
|
|
2555
|
-
fetchInit:
|
|
2542
|
+
responseType: undefined,
|
|
2543
|
+
headers: undefined,
|
|
2544
|
+
data: undefined,
|
|
2545
|
+
redirect: undefined,
|
|
2546
|
+
cookie: undefined,
|
|
2547
|
+
cookiePartition: undefined,
|
|
2548
|
+
binary: undefined,
|
|
2549
|
+
nocache: undefined,
|
|
2550
|
+
revalidate: undefined,
|
|
2551
|
+
context: undefined,
|
|
2552
|
+
overrideMimeType: undefined,
|
|
2553
|
+
anonymous: undefined,
|
|
2554
|
+
fetch: undefined,
|
|
2555
|
+
fetchInit: undefined,
|
|
2556
2556
|
allowInterceptConfig: {
|
|
2557
2557
|
beforeRequest: true,
|
|
2558
2558
|
afterResponseSuccess: true,
|
|
2559
2559
|
afterResponseError: true,
|
|
2560
2560
|
},
|
|
2561
|
-
user:
|
|
2562
|
-
password:
|
|
2561
|
+
user: undefined,
|
|
2562
|
+
password: undefined,
|
|
2563
2563
|
onabort() { },
|
|
2564
2564
|
onerror() { },
|
|
2565
2565
|
ontimeout() { },
|
|
@@ -3043,7 +3043,7 @@
|
|
|
3043
3043
|
success: false,
|
|
3044
3044
|
code: that.#statusCode.getFailed.code,
|
|
3045
3045
|
msg: that.#statusCode.getFailed.msg,
|
|
3046
|
-
data:
|
|
3046
|
+
data: undefined,
|
|
3047
3047
|
});
|
|
3048
3048
|
}
|
|
3049
3049
|
else {
|
|
@@ -3053,7 +3053,7 @@
|
|
|
3053
3053
|
let result = target.result;
|
|
3054
3054
|
/* result 返回的是 {key: string, value: any} */
|
|
3055
3055
|
/* 键值对存储 */
|
|
3056
|
-
let data = result ? result.value :
|
|
3056
|
+
let data = result ? result.value : undefined;
|
|
3057
3057
|
if (data == null) {
|
|
3058
3058
|
resolve({
|
|
3059
3059
|
success: true,
|
|
@@ -3080,7 +3080,7 @@
|
|
|
3080
3080
|
success: false,
|
|
3081
3081
|
code: that.#statusCode.getFailed.code,
|
|
3082
3082
|
msg: that.#statusCode.getFailed.msg,
|
|
3083
|
-
data:
|
|
3083
|
+
data: undefined,
|
|
3084
3084
|
event: event,
|
|
3085
3085
|
});
|
|
3086
3086
|
};
|
|
@@ -3660,7 +3660,7 @@
|
|
|
3660
3660
|
context = __context__ || this;
|
|
3661
3661
|
let result = executeTryCatch(callbackFunction, handleError, context);
|
|
3662
3662
|
// @ts-ignore
|
|
3663
|
-
return result !==
|
|
3663
|
+
return result !== undefined ? result : TryCatchCore;
|
|
3664
3664
|
},
|
|
3665
3665
|
};
|
|
3666
3666
|
/**
|
|
@@ -3671,7 +3671,7 @@
|
|
|
3671
3671
|
* @returns 如果函数有返回值,则返回该返回值;否则返回 undefined。
|
|
3672
3672
|
*/
|
|
3673
3673
|
function executeTryCatch(callback, handleErrorFunc, funcThis) {
|
|
3674
|
-
let result =
|
|
3674
|
+
let result = undefined;
|
|
3675
3675
|
try {
|
|
3676
3676
|
if (typeof callback === "string") {
|
|
3677
3677
|
(function () {
|
|
@@ -3739,7 +3739,7 @@
|
|
|
3739
3739
|
*/
|
|
3740
3740
|
getStartsWith(key) {
|
|
3741
3741
|
let allKeys = this.keys();
|
|
3742
|
-
let result =
|
|
3742
|
+
let result = undefined;
|
|
3743
3743
|
for (const keyName of allKeys) {
|
|
3744
3744
|
if (String(keyName).startsWith(String(key))) {
|
|
3745
3745
|
result = this.get(keyName);
|
|
@@ -3754,7 +3754,7 @@
|
|
|
3754
3754
|
* @param val 值,默认为""
|
|
3755
3755
|
*/
|
|
3756
3756
|
set(key, val) {
|
|
3757
|
-
if (key ===
|
|
3757
|
+
if (key === undefined) {
|
|
3758
3758
|
throw new Error("Utils.Dictionary().set 参数 key 不能为空");
|
|
3759
3759
|
}
|
|
3760
3760
|
Reflect.set(this.items, key, val);
|
|
@@ -4139,13 +4139,411 @@
|
|
|
4139
4139
|
}
|
|
4140
4140
|
}
|
|
4141
4141
|
|
|
4142
|
+
// ==UserScript==
|
|
4143
|
+
// @name ModuleRaid.js
|
|
4144
|
+
// @namespace http://tampermonkey.net/
|
|
4145
|
+
// @version 6.2.0
|
|
4146
|
+
// @description 检索调用webpackJsonp模块,可指定检索的window
|
|
4147
|
+
// @author empyrealtear
|
|
4148
|
+
// @license MIT
|
|
4149
|
+
// @original-script https://github.com/pixeldesu/moduleRaid
|
|
4150
|
+
// ==/UserScript==
|
|
4151
|
+
|
|
4152
|
+
|
|
4153
|
+
/**
|
|
4154
|
+
* Main moduleRaid class
|
|
4155
|
+
* @link https://scriptcat.org/zh-CN/script-show-page/2628
|
|
4156
|
+
*/
|
|
4157
|
+
class ModuleRaid {
|
|
4158
|
+
/**
|
|
4159
|
+
* moduleRaid constructor
|
|
4160
|
+
*
|
|
4161
|
+
* @example
|
|
4162
|
+
* Constructing an instance without any arguments:
|
|
4163
|
+
* ```ts
|
|
4164
|
+
* const mR = new ModuleRaid()
|
|
4165
|
+
* ```
|
|
4166
|
+
*
|
|
4167
|
+
* Constructing an instance with the optional `opts` object:
|
|
4168
|
+
* ```ts
|
|
4169
|
+
* const mR = new ModuleRaid({ entrypoint: 'webpackChunk_custom_name' })
|
|
4170
|
+
* ```
|
|
4171
|
+
*
|
|
4172
|
+
* @param opts a object containing options to initialize moduleRaid with
|
|
4173
|
+
* - **opts:**
|
|
4174
|
+
* - _target_: the window object being searched for
|
|
4175
|
+
* - _entrypoint_: the Webpack entrypoint present on the global window object
|
|
4176
|
+
* - _debug_: whether debug mode is enabled or not
|
|
4177
|
+
* - _strict_: whether strict mode is enabled or not
|
|
4178
|
+
*/
|
|
4179
|
+
constructor(opts) {
|
|
4180
|
+
/**
|
|
4181
|
+
* A random generated module ID we use for injecting into Webpack
|
|
4182
|
+
*/
|
|
4183
|
+
this.moduleID = Math.random().toString(36).substring(7);
|
|
4184
|
+
/**
|
|
4185
|
+
* An array containing different argument injection methods for
|
|
4186
|
+
* Webpack (before version 4), and subsequently pulling out methods and modules
|
|
4187
|
+
* @internal
|
|
4188
|
+
*/
|
|
4189
|
+
this.functionArguments = [
|
|
4190
|
+
[
|
|
4191
|
+
[0],
|
|
4192
|
+
[
|
|
4193
|
+
(_e, _t, i) => {
|
|
4194
|
+
this.modules = i.c;
|
|
4195
|
+
this.constructors = i.m;
|
|
4196
|
+
this.get = i;
|
|
4197
|
+
},
|
|
4198
|
+
],
|
|
4199
|
+
],
|
|
4200
|
+
[
|
|
4201
|
+
[1e3],
|
|
4202
|
+
{
|
|
4203
|
+
[this.moduleID]: (_e, _t, i) => {
|
|
4204
|
+
this.modules = i.c;
|
|
4205
|
+
this.constructors = i.m;
|
|
4206
|
+
this.get = i;
|
|
4207
|
+
},
|
|
4208
|
+
},
|
|
4209
|
+
[[this.moduleID]],
|
|
4210
|
+
],
|
|
4211
|
+
];
|
|
4212
|
+
/**
|
|
4213
|
+
* An array containing different argument injection methods for
|
|
4214
|
+
* Webpack (after version 4), and subsequently pulling out methods and modules
|
|
4215
|
+
* @internal
|
|
4216
|
+
*/
|
|
4217
|
+
this.arrayArguments = [
|
|
4218
|
+
[
|
|
4219
|
+
[this.moduleID],
|
|
4220
|
+
{},
|
|
4221
|
+
(e) => {
|
|
4222
|
+
const mCac = e.m;
|
|
4223
|
+
Object.keys(mCac).forEach((mod) => {
|
|
4224
|
+
try {
|
|
4225
|
+
this.modules[mod] = e(mod);
|
|
4226
|
+
}
|
|
4227
|
+
catch (err) {
|
|
4228
|
+
this.log(`[arrayArguments/1] Failed to require(${mod}) with error:\n${err}\n${err.stack}`);
|
|
4229
|
+
}
|
|
4230
|
+
});
|
|
4231
|
+
this.get = e;
|
|
4232
|
+
},
|
|
4233
|
+
],
|
|
4234
|
+
this.functionArguments[1],
|
|
4235
|
+
];
|
|
4236
|
+
/**
|
|
4237
|
+
* Storage for the modules we extracted from Webpack
|
|
4238
|
+
*/
|
|
4239
|
+
this.modules = {};
|
|
4240
|
+
/**
|
|
4241
|
+
* Storage for the constructors we extracted from Webpack
|
|
4242
|
+
*/
|
|
4243
|
+
this.constructors = [];
|
|
4244
|
+
let options = {
|
|
4245
|
+
target: window,
|
|
4246
|
+
entrypoint: 'webpackJsonp',
|
|
4247
|
+
debug: false,
|
|
4248
|
+
strict: false,
|
|
4249
|
+
};
|
|
4250
|
+
if (typeof opts === 'object') {
|
|
4251
|
+
options = Object.assign(Object.assign({}, options), opts);
|
|
4252
|
+
}
|
|
4253
|
+
this.target = options.target;
|
|
4254
|
+
this.entrypoint = options.entrypoint;
|
|
4255
|
+
this.debug = options.debug;
|
|
4256
|
+
this.strict = options.strict;
|
|
4257
|
+
this.detectEntrypoint();
|
|
4258
|
+
this.fillModules();
|
|
4259
|
+
this.replaceGet();
|
|
4260
|
+
this.setupPushEvent();
|
|
4261
|
+
}
|
|
4262
|
+
/**
|
|
4263
|
+
* Debug logging method, outputs to the console when {@link ModuleRaid.debug} is true
|
|
4264
|
+
*
|
|
4265
|
+
* @param {*} message The message to be logged
|
|
4266
|
+
* @internal
|
|
4267
|
+
*/
|
|
4268
|
+
log(message) {
|
|
4269
|
+
if (this.debug) {
|
|
4270
|
+
console.warn(`[moduleRaid] ${message}`);
|
|
4271
|
+
}
|
|
4272
|
+
}
|
|
4273
|
+
/**
|
|
4274
|
+
* Method to set an alternative getter if we weren't able to extract __webpack_require__
|
|
4275
|
+
* from Webpack
|
|
4276
|
+
* @internal
|
|
4277
|
+
*/
|
|
4278
|
+
replaceGet() {
|
|
4279
|
+
if (this.get === null) {
|
|
4280
|
+
this.get = (key) => this.modules[key];
|
|
4281
|
+
}
|
|
4282
|
+
}
|
|
4283
|
+
/**
|
|
4284
|
+
* Method that will try to inject a module into Webpack or get modules
|
|
4285
|
+
* depending on it's success it might be more or less brute about it
|
|
4286
|
+
* @internal
|
|
4287
|
+
*/
|
|
4288
|
+
fillModules() {
|
|
4289
|
+
if (typeof this.target[this.entrypoint] === 'function') {
|
|
4290
|
+
this.functionArguments.forEach((argument, index) => {
|
|
4291
|
+
try {
|
|
4292
|
+
if (this.modules && Object.keys(this.modules).length > 0)
|
|
4293
|
+
return;
|
|
4294
|
+
this.target[this.entrypoint](...argument);
|
|
4295
|
+
}
|
|
4296
|
+
catch (err) {
|
|
4297
|
+
this.log(`moduleRaid.functionArguments[${index}] failed:\n${err}\n${err.stack}`);
|
|
4298
|
+
}
|
|
4299
|
+
});
|
|
4300
|
+
}
|
|
4301
|
+
else {
|
|
4302
|
+
this.arrayArguments.forEach((argument, index) => {
|
|
4303
|
+
try {
|
|
4304
|
+
if (this.modules && Object.keys(this.modules).length > 0)
|
|
4305
|
+
return;
|
|
4306
|
+
this.target[this.entrypoint].push(argument);
|
|
4307
|
+
}
|
|
4308
|
+
catch (err) {
|
|
4309
|
+
this.log(`Pushing moduleRaid.arrayArguments[${index}] into ${this.entrypoint} failed:\n${err}\n${err.stack}`);
|
|
4310
|
+
}
|
|
4311
|
+
});
|
|
4312
|
+
}
|
|
4313
|
+
if (this.modules && Object.keys(this.modules).length == 0) {
|
|
4314
|
+
let moduleEnd = false;
|
|
4315
|
+
let moduleIterator = 0;
|
|
4316
|
+
if (typeof this.target[this.entrypoint] != 'function' || !this.target[this.entrypoint]([], [], [moduleIterator])) {
|
|
4317
|
+
throw Error('Unknown Webpack structure');
|
|
4318
|
+
}
|
|
4319
|
+
while (!moduleEnd) {
|
|
4320
|
+
try {
|
|
4321
|
+
this.modules[moduleIterator] = this.target[this.entrypoint]([], [], [moduleIterator]);
|
|
4322
|
+
moduleIterator++;
|
|
4323
|
+
}
|
|
4324
|
+
catch (err) {
|
|
4325
|
+
moduleEnd = true;
|
|
4326
|
+
}
|
|
4327
|
+
}
|
|
4328
|
+
}
|
|
4329
|
+
}
|
|
4330
|
+
/**
|
|
4331
|
+
* Method to hook into `window[this.entrypoint].push` adding a listener for new
|
|
4332
|
+
* chunks being pushed into Webpack
|
|
4333
|
+
*
|
|
4334
|
+
* @example
|
|
4335
|
+
* You can listen for newly pushed packages using the `moduleraid:webpack-push` event
|
|
4336
|
+
* on `document`
|
|
4337
|
+
*
|
|
4338
|
+
* ```ts
|
|
4339
|
+
* document.addEventListener('moduleraid:webpack-push', (e) => {
|
|
4340
|
+
* // e.detail contains the arguments push() was called with
|
|
4341
|
+
* console.log(e.detail)
|
|
4342
|
+
* })
|
|
4343
|
+
* ```
|
|
4344
|
+
* @internal
|
|
4345
|
+
*/
|
|
4346
|
+
setupPushEvent() {
|
|
4347
|
+
const originalPush = this.target[this.entrypoint].push;
|
|
4348
|
+
this.target[this.entrypoint].push = (...args) => {
|
|
4349
|
+
const result = Reflect.apply(originalPush, this.target[this.entrypoint], args);
|
|
4350
|
+
document.dispatchEvent(new CustomEvent('moduleraid:webpack-push', { detail: args }));
|
|
4351
|
+
return result;
|
|
4352
|
+
};
|
|
4353
|
+
}
|
|
4354
|
+
/**
|
|
4355
|
+
* Method to try autodetecting a Webpack JSONP entrypoint based on common naming
|
|
4356
|
+
*
|
|
4357
|
+
* If the default entrypoint, or the entrypoint that's passed to the moduleRaid constructor
|
|
4358
|
+
* already matches, the method exits early
|
|
4359
|
+
*
|
|
4360
|
+
* If `options.strict` has been set in the constructor and the initial entrypoint cannot
|
|
4361
|
+
* be found, this method will error, demanding a strictly set entrypoint
|
|
4362
|
+
* @internal
|
|
4363
|
+
*/
|
|
4364
|
+
detectEntrypoint() {
|
|
4365
|
+
if (this.target[this.entrypoint] != undefined) {
|
|
4366
|
+
return;
|
|
4367
|
+
}
|
|
4368
|
+
if (this.strict) {
|
|
4369
|
+
throw Error(`Strict mode is enabled and entrypoint at window.${this.entrypoint} couldn't be found. Please specify the correct one!`);
|
|
4370
|
+
}
|
|
4371
|
+
let windowObjects = Object.keys(this.target);
|
|
4372
|
+
windowObjects = windowObjects
|
|
4373
|
+
.filter((object) => object.toLowerCase().includes('chunk') || object.toLowerCase().includes('webpack'))
|
|
4374
|
+
.filter((object) => typeof this.target[object] === 'function' || Array.isArray(this.target[object]));
|
|
4375
|
+
if (windowObjects.length > 1) {
|
|
4376
|
+
throw Error(`Multiple possible endpoints have been detected, please create a new moduleRaid instance with a specific one:\n${windowObjects.join(', ')}`);
|
|
4377
|
+
}
|
|
4378
|
+
if (windowObjects.length === 0) {
|
|
4379
|
+
throw Error('No Webpack JSONP entrypoints could be detected');
|
|
4380
|
+
}
|
|
4381
|
+
this.log(`Entrypoint has been detected at window.${windowObjects[0]} and set for injection`);
|
|
4382
|
+
this.entrypoint = windowObjects[0];
|
|
4383
|
+
}
|
|
4384
|
+
/**
|
|
4385
|
+
* Recursive object-search function for modules
|
|
4386
|
+
*
|
|
4387
|
+
* @param object the object to search through
|
|
4388
|
+
* @param query the query the object keys/values are searched for
|
|
4389
|
+
* @returns boolean state of `object` containing `query` somewhere in it
|
|
4390
|
+
* @internal
|
|
4391
|
+
*/
|
|
4392
|
+
searchObject(object, query) {
|
|
4393
|
+
for (const key in object) {
|
|
4394
|
+
const value = object[key];
|
|
4395
|
+
const lowerCaseQuery = query.toLowerCase();
|
|
4396
|
+
if (typeof value != 'object') {
|
|
4397
|
+
const lowerCaseKey = key.toString().toLowerCase();
|
|
4398
|
+
if (lowerCaseKey.includes(lowerCaseQuery))
|
|
4399
|
+
return true;
|
|
4400
|
+
if (typeof value != 'object') {
|
|
4401
|
+
const lowerCaseValue = value.toString().toLowerCase();
|
|
4402
|
+
if (lowerCaseValue.includes(lowerCaseQuery))
|
|
4403
|
+
return true;
|
|
4404
|
+
}
|
|
4405
|
+
else {
|
|
4406
|
+
if (this.searchObject(value, query))
|
|
4407
|
+
return true;
|
|
4408
|
+
}
|
|
4409
|
+
}
|
|
4410
|
+
}
|
|
4411
|
+
return false;
|
|
4412
|
+
}
|
|
4413
|
+
/**
|
|
4414
|
+
* Method to search through the module object, searching for the fitting content
|
|
4415
|
+
* if a string is supplied
|
|
4416
|
+
*
|
|
4417
|
+
* If query is supplied as a function, everything that returns true when passed
|
|
4418
|
+
* to the query function will be returned
|
|
4419
|
+
*
|
|
4420
|
+
* @example
|
|
4421
|
+
* With a string as query argument:
|
|
4422
|
+
* ```ts
|
|
4423
|
+
* const results = mR.findModule('feature')
|
|
4424
|
+
* // => Array of module results
|
|
4425
|
+
* ```
|
|
4426
|
+
*
|
|
4427
|
+
* With a function as query argument:
|
|
4428
|
+
* ```ts
|
|
4429
|
+
* const results = mR.findModule((module) => { typeof module === 'function' })
|
|
4430
|
+
* // => Array of module results
|
|
4431
|
+
* ```
|
|
4432
|
+
*
|
|
4433
|
+
* @param query query to search the module list for
|
|
4434
|
+
* @return a list of modules fitting the query
|
|
4435
|
+
*/
|
|
4436
|
+
findModule(query) {
|
|
4437
|
+
const results = [];
|
|
4438
|
+
const modules = Object.keys(this.modules);
|
|
4439
|
+
if (modules.length === 0) {
|
|
4440
|
+
throw new Error('There are no modules to search through!');
|
|
4441
|
+
}
|
|
4442
|
+
modules.forEach((key) => {
|
|
4443
|
+
const module = this.modules[key.toString()];
|
|
4444
|
+
if (module === undefined)
|
|
4445
|
+
return;
|
|
4446
|
+
try {
|
|
4447
|
+
if (typeof query === 'string') {
|
|
4448
|
+
query = query.toLowerCase();
|
|
4449
|
+
switch (typeof module) {
|
|
4450
|
+
case 'string':
|
|
4451
|
+
if (module.toLowerCase().includes(query))
|
|
4452
|
+
results.push(module);
|
|
4453
|
+
break;
|
|
4454
|
+
case 'function':
|
|
4455
|
+
if (module.toString().toLowerCase().includes(query))
|
|
4456
|
+
results.push(module);
|
|
4457
|
+
break;
|
|
4458
|
+
case 'object':
|
|
4459
|
+
if (this.searchObject(module, query))
|
|
4460
|
+
results.push(module);
|
|
4461
|
+
break;
|
|
4462
|
+
}
|
|
4463
|
+
}
|
|
4464
|
+
else if (typeof query === 'function') {
|
|
4465
|
+
if (query(module))
|
|
4466
|
+
results.push(module);
|
|
4467
|
+
}
|
|
4468
|
+
else {
|
|
4469
|
+
throw new TypeError(`findModule can only find via string and function, ${typeof query} was passed`);
|
|
4470
|
+
}
|
|
4471
|
+
}
|
|
4472
|
+
catch (err) {
|
|
4473
|
+
this.log(`There was an error while searching through module '${key}':\n${err}\n${err.stack}`);
|
|
4474
|
+
}
|
|
4475
|
+
});
|
|
4476
|
+
return results;
|
|
4477
|
+
}
|
|
4478
|
+
/**
|
|
4479
|
+
* Method to search through the constructor array, searching for the fitting content
|
|
4480
|
+
* if a string is supplied
|
|
4481
|
+
*
|
|
4482
|
+
* If query is supplied as a function, everything that returns true when passed
|
|
4483
|
+
* to the query function will be returned
|
|
4484
|
+
*
|
|
4485
|
+
* @example
|
|
4486
|
+
* With a string as query argument:
|
|
4487
|
+
* ```ts
|
|
4488
|
+
* const results = mR.findConstructor('feature')
|
|
4489
|
+
* // => Array of constructor/module tuples
|
|
4490
|
+
* ```
|
|
4491
|
+
*
|
|
4492
|
+
* With a function as query argument:
|
|
4493
|
+
* ```ts
|
|
4494
|
+
* const results = mR.findConstructor((constructor) => { constructor.prototype.value !== undefined })
|
|
4495
|
+
* // => Array of constructor/module tuples
|
|
4496
|
+
* ```
|
|
4497
|
+
*
|
|
4498
|
+
* Accessing the resulting data:
|
|
4499
|
+
* ```ts
|
|
4500
|
+
* // With array destructuring (ES6)
|
|
4501
|
+
* const [constructor, module] = results[0]
|
|
4502
|
+
*
|
|
4503
|
+
* // ...or...
|
|
4504
|
+
*
|
|
4505
|
+
* // regular access
|
|
4506
|
+
* const constructor = results[0][0]
|
|
4507
|
+
* const module = results[0][1]
|
|
4508
|
+
* ```
|
|
4509
|
+
*
|
|
4510
|
+
* @param query query to search the constructor list for
|
|
4511
|
+
* @returns a list of constructor/module tuples fitting the query
|
|
4512
|
+
*/
|
|
4513
|
+
findConstructor(query) {
|
|
4514
|
+
const results = [];
|
|
4515
|
+
const constructors = Object.keys(this.constructors);
|
|
4516
|
+
if (constructors.length === 0) {
|
|
4517
|
+
throw new Error('There are no constructors to search through!');
|
|
4518
|
+
}
|
|
4519
|
+
constructors.forEach((key) => {
|
|
4520
|
+
const constructor = this.constructors[key];
|
|
4521
|
+
try {
|
|
4522
|
+
if (typeof query === 'string') {
|
|
4523
|
+
query = query.toLowerCase();
|
|
4524
|
+
if (constructor.toString().toLowerCase().includes(query))
|
|
4525
|
+
results.push([this.constructors[key], this.modules[key]]);
|
|
4526
|
+
}
|
|
4527
|
+
else if (typeof query === 'function') {
|
|
4528
|
+
if (query(constructor))
|
|
4529
|
+
results.push([this.constructors[key], this.modules[key]]);
|
|
4530
|
+
}
|
|
4531
|
+
}
|
|
4532
|
+
catch (err) {
|
|
4533
|
+
this.log(`There was an error while searching through constructor '${key}':\n${err}\n${err.stack}`);
|
|
4534
|
+
}
|
|
4535
|
+
});
|
|
4536
|
+
return results;
|
|
4537
|
+
}
|
|
4538
|
+
}
|
|
4539
|
+
|
|
4142
4540
|
class Utils {
|
|
4143
4541
|
windowApi;
|
|
4144
4542
|
constructor(option) {
|
|
4145
4543
|
this.windowApi = new WindowApi(option);
|
|
4146
4544
|
}
|
|
4147
4545
|
/** 版本号 */
|
|
4148
|
-
version = "
|
|
4546
|
+
version = "2025.1.11";
|
|
4149
4547
|
addStyle(cssText) {
|
|
4150
4548
|
if (typeof cssText !== "string") {
|
|
4151
4549
|
throw new Error("Utils.addStyle 参数cssText 必须为String类型");
|
|
@@ -4368,8 +4766,8 @@
|
|
|
4368
4766
|
ColorConversion = ColorConversion;
|
|
4369
4767
|
deepClone(obj) {
|
|
4370
4768
|
let UtilsContext = this;
|
|
4371
|
-
if (obj ===
|
|
4372
|
-
return
|
|
4769
|
+
if (obj === undefined)
|
|
4770
|
+
return undefined;
|
|
4373
4771
|
if (obj === null)
|
|
4374
4772
|
return null;
|
|
4375
4773
|
let clone = obj instanceof Array ? [] : {};
|
|
@@ -5815,36 +6213,36 @@
|
|
|
5815
6213
|
* + true 监听以 target 为根节点的整个子树。包括子树中所有节点的属性,而不仅仅是针对 target
|
|
5816
6214
|
* + false (默认) 不生效
|
|
5817
6215
|
*/
|
|
5818
|
-
subtree:
|
|
6216
|
+
subtree: undefined,
|
|
5819
6217
|
/**
|
|
5820
6218
|
* + true 监听 target 节点中发生的节点的新增与删除(同时,如果 subtree 为 true,会针对整个子树生效)
|
|
5821
6219
|
* + false (默认) 不生效
|
|
5822
6220
|
*/
|
|
5823
|
-
childList:
|
|
6221
|
+
childList: undefined,
|
|
5824
6222
|
/**
|
|
5825
6223
|
* + true 观察所有监听的节点属性值的变化。默认值为 true,当声明了 attributeFilter 或 attributeOldValue
|
|
5826
6224
|
* + false (默认) 不生效
|
|
5827
6225
|
*/
|
|
5828
|
-
attributes:
|
|
6226
|
+
attributes: undefined,
|
|
5829
6227
|
/**
|
|
5830
6228
|
* 一个用于声明哪些属性名会被监听的数组。如果不声明该属性,所有属性的变化都将触发通知
|
|
5831
6229
|
*/
|
|
5832
|
-
attributeFilter:
|
|
6230
|
+
attributeFilter: undefined,
|
|
5833
6231
|
/**
|
|
5834
6232
|
* + true 记录上一次被监听的节点的属性变化;可查阅 MutationObserver 中的 Monitoring attribute values 了解关于观察属性变化和属性值记录的详情
|
|
5835
6233
|
* + false (默认) 不生效
|
|
5836
6234
|
*/
|
|
5837
|
-
attributeOldValue:
|
|
6235
|
+
attributeOldValue: undefined,
|
|
5838
6236
|
/**
|
|
5839
6237
|
* + true 监听声明的 target 节点上所有字符的变化。默认值为 true,如果声明了 characterDataOldValue
|
|
5840
6238
|
* + false (默认) 不生效
|
|
5841
6239
|
*/
|
|
5842
|
-
characterData:
|
|
6240
|
+
characterData: undefined,
|
|
5843
6241
|
/**
|
|
5844
6242
|
* + true 记录前一个被监听的节点中发生的文本变化
|
|
5845
6243
|
* + false (默认) 不生效
|
|
5846
6244
|
*/
|
|
5847
|
-
characterDataOldValue:
|
|
6245
|
+
characterDataOldValue: undefined,
|
|
5848
6246
|
},
|
|
5849
6247
|
immediate: false,
|
|
5850
6248
|
};
|
|
@@ -6419,7 +6817,7 @@
|
|
|
6419
6817
|
}
|
|
6420
6818
|
return new Promise((resolve) => {
|
|
6421
6819
|
setTimeout(() => {
|
|
6422
|
-
resolve(
|
|
6820
|
+
resolve(undefined);
|
|
6423
6821
|
}, delayTime);
|
|
6424
6822
|
});
|
|
6425
6823
|
}
|
|
@@ -6759,9 +7157,42 @@
|
|
|
6759
7157
|
await UtilsContext.tryCatch(index, item).run(handleFunc);
|
|
6760
7158
|
}));
|
|
6761
7159
|
}
|
|
7160
|
+
wait(checkFn, timeout, parent) {
|
|
7161
|
+
const UtilsContext = this;
|
|
7162
|
+
let __timeout__ = typeof timeout === "number" ? timeout : 0;
|
|
7163
|
+
return new Promise((resolve) => {
|
|
7164
|
+
let observer = UtilsContext.mutationObserver(parent || UtilsContext.windowApi.document, {
|
|
7165
|
+
config: {
|
|
7166
|
+
subtree: true,
|
|
7167
|
+
childList: true,
|
|
7168
|
+
attributes: true,
|
|
7169
|
+
},
|
|
7170
|
+
immediate: true,
|
|
7171
|
+
callback(mutations, __observer__) {
|
|
7172
|
+
let result = checkFn();
|
|
7173
|
+
if (result.success) {
|
|
7174
|
+
// 取消观察器
|
|
7175
|
+
if (typeof __observer__?.disconnect === "function") {
|
|
7176
|
+
__observer__.disconnect();
|
|
7177
|
+
}
|
|
7178
|
+
resolve(result.data);
|
|
7179
|
+
}
|
|
7180
|
+
},
|
|
7181
|
+
});
|
|
7182
|
+
if (__timeout__ > 0) {
|
|
7183
|
+
setTimeout(() => {
|
|
7184
|
+
// 取消观察器
|
|
7185
|
+
if (typeof observer?.disconnect === "function") {
|
|
7186
|
+
observer.disconnect();
|
|
7187
|
+
}
|
|
7188
|
+
resolve(null);
|
|
7189
|
+
}, __timeout__);
|
|
7190
|
+
}
|
|
7191
|
+
});
|
|
7192
|
+
}
|
|
6762
7193
|
waitNode(...args) {
|
|
6763
7194
|
// 过滤掉undefined
|
|
6764
|
-
args = args.filter((arg) => arg !==
|
|
7195
|
+
args = args.filter((arg) => arg !== undefined);
|
|
6765
7196
|
let UtilsContext = this;
|
|
6766
7197
|
// 选择器
|
|
6767
7198
|
let selector = args[0];
|
|
@@ -6769,8 +7200,10 @@
|
|
|
6769
7200
|
let parent = UtilsContext.windowApi.document;
|
|
6770
7201
|
// 超时时间
|
|
6771
7202
|
let timeout = 0;
|
|
6772
|
-
if (typeof args[0] !== "string" &&
|
|
6773
|
-
|
|
7203
|
+
if (typeof args[0] !== "string" &&
|
|
7204
|
+
!Array.isArray(args[0]) &&
|
|
7205
|
+
typeof args[0] !== "function") {
|
|
7206
|
+
throw new TypeError("Utils.waitNode 第一个参数必须是string|string[]|Function");
|
|
6774
7207
|
}
|
|
6775
7208
|
if (args.length === 1) ;
|
|
6776
7209
|
else if (args.length === 2) {
|
|
@@ -6810,57 +7243,45 @@
|
|
|
6810
7243
|
else {
|
|
6811
7244
|
throw new TypeError("Utils.waitNode 参数个数错误");
|
|
6812
7245
|
}
|
|
6813
|
-
|
|
6814
|
-
|
|
6815
|
-
|
|
6816
|
-
|
|
6817
|
-
|
|
6818
|
-
|
|
6819
|
-
|
|
6820
|
-
result.push(node);
|
|
6821
|
-
}
|
|
6822
|
-
}
|
|
6823
|
-
if (result.length === selector.length) {
|
|
6824
|
-
return result;
|
|
7246
|
+
function getNode() {
|
|
7247
|
+
if (Array.isArray(selector)) {
|
|
7248
|
+
let result = [];
|
|
7249
|
+
for (let index = 0; index < selector.length; index++) {
|
|
7250
|
+
let node = parent.querySelector(selector[index]);
|
|
7251
|
+
if (node) {
|
|
7252
|
+
result.push(node);
|
|
6825
7253
|
}
|
|
6826
7254
|
}
|
|
6827
|
-
|
|
6828
|
-
return
|
|
7255
|
+
if (result.length === selector.length) {
|
|
7256
|
+
return result;
|
|
6829
7257
|
}
|
|
6830
7258
|
}
|
|
6831
|
-
|
|
6832
|
-
|
|
6833
|
-
subtree: true,
|
|
6834
|
-
childList: true,
|
|
6835
|
-
attributes: true,
|
|
6836
|
-
},
|
|
6837
|
-
callback() {
|
|
6838
|
-
let node = getNode();
|
|
6839
|
-
if (node) {
|
|
6840
|
-
// 取消观察器
|
|
6841
|
-
if (typeof observer?.disconnect === "function") {
|
|
6842
|
-
observer.disconnect();
|
|
6843
|
-
}
|
|
6844
|
-
resolve(node);
|
|
6845
|
-
return;
|
|
6846
|
-
}
|
|
6847
|
-
},
|
|
6848
|
-
immediate: true,
|
|
6849
|
-
});
|
|
6850
|
-
if (timeout > 0) {
|
|
6851
|
-
setTimeout(() => {
|
|
6852
|
-
// 取消观察器
|
|
6853
|
-
if (typeof observer?.disconnect === "function") {
|
|
6854
|
-
observer.disconnect();
|
|
6855
|
-
}
|
|
6856
|
-
resolve(null);
|
|
6857
|
-
}, timeout);
|
|
7259
|
+
else if (typeof selector === "function") {
|
|
7260
|
+
return selector();
|
|
6858
7261
|
}
|
|
6859
|
-
|
|
7262
|
+
else {
|
|
7263
|
+
return parent.querySelector(selector);
|
|
7264
|
+
}
|
|
7265
|
+
}
|
|
7266
|
+
return UtilsContext.wait(() => {
|
|
7267
|
+
let node = getNode();
|
|
7268
|
+
if (node) {
|
|
7269
|
+
return {
|
|
7270
|
+
success: true,
|
|
7271
|
+
data: node,
|
|
7272
|
+
};
|
|
7273
|
+
}
|
|
7274
|
+
else {
|
|
7275
|
+
return {
|
|
7276
|
+
success: false,
|
|
7277
|
+
data: node,
|
|
7278
|
+
};
|
|
7279
|
+
}
|
|
7280
|
+
}, timeout, parent);
|
|
6860
7281
|
}
|
|
6861
7282
|
waitAnyNode(...args) {
|
|
6862
7283
|
// 过滤掉undefined
|
|
6863
|
-
args = args.filter((arg) => arg !==
|
|
7284
|
+
args = args.filter((arg) => arg !== undefined);
|
|
6864
7285
|
let UtilsContext = this;
|
|
6865
7286
|
// 选择器
|
|
6866
7287
|
let selectorList = args[0];
|
|
@@ -6916,7 +7337,7 @@
|
|
|
6916
7337
|
}
|
|
6917
7338
|
waitNodeList(...args) {
|
|
6918
7339
|
// 过滤掉undefined
|
|
6919
|
-
args = args.filter((arg) => arg !==
|
|
7340
|
+
args = args.filter((arg) => arg !== undefined);
|
|
6920
7341
|
let UtilsContext = this;
|
|
6921
7342
|
// 选择器数组
|
|
6922
7343
|
let selector = args[0];
|
|
@@ -6965,61 +7386,45 @@
|
|
|
6965
7386
|
else {
|
|
6966
7387
|
throw new TypeError("Utils.waitNodeList 参数个数错误");
|
|
6967
7388
|
}
|
|
6968
|
-
|
|
6969
|
-
|
|
6970
|
-
|
|
6971
|
-
|
|
6972
|
-
|
|
6973
|
-
let nodeList = parent.querySelectorAll(selector[index]);
|
|
6974
|
-
if (nodeList.length) {
|
|
6975
|
-
result.push(nodeList);
|
|
6976
|
-
}
|
|
6977
|
-
}
|
|
6978
|
-
if (result.length === selector.length) {
|
|
6979
|
-
return result;
|
|
6980
|
-
}
|
|
6981
|
-
}
|
|
6982
|
-
else {
|
|
6983
|
-
let nodeList = parent.querySelectorAll(selector);
|
|
7389
|
+
function getNodeList() {
|
|
7390
|
+
if (Array.isArray(selector)) {
|
|
7391
|
+
let result = [];
|
|
7392
|
+
for (let index = 0; index < selector.length; index++) {
|
|
7393
|
+
let nodeList = parent.querySelectorAll(selector[index]);
|
|
6984
7394
|
if (nodeList.length) {
|
|
6985
|
-
|
|
7395
|
+
result.push(nodeList);
|
|
6986
7396
|
}
|
|
6987
7397
|
}
|
|
7398
|
+
if (result.length === selector.length) {
|
|
7399
|
+
return result;
|
|
7400
|
+
}
|
|
6988
7401
|
}
|
|
6989
|
-
|
|
6990
|
-
|
|
6991
|
-
|
|
6992
|
-
|
|
6993
|
-
|
|
6994
|
-
},
|
|
6995
|
-
callback() {
|
|
6996
|
-
let node = getNodeList();
|
|
6997
|
-
if (node) {
|
|
6998
|
-
// 取消观察器
|
|
6999
|
-
try {
|
|
7000
|
-
observer.disconnect();
|
|
7001
|
-
}
|
|
7002
|
-
catch (error) { }
|
|
7003
|
-
resolve(node);
|
|
7004
|
-
return;
|
|
7005
|
-
}
|
|
7006
|
-
},
|
|
7007
|
-
immediate: true,
|
|
7008
|
-
});
|
|
7009
|
-
if (timeout > 0) {
|
|
7010
|
-
setTimeout(() => {
|
|
7011
|
-
// 取消观察器
|
|
7012
|
-
if (typeof observer?.disconnect === "function") {
|
|
7013
|
-
observer.disconnect();
|
|
7014
|
-
}
|
|
7015
|
-
resolve(null);
|
|
7016
|
-
}, timeout);
|
|
7402
|
+
else {
|
|
7403
|
+
let nodeList = parent.querySelectorAll(selector);
|
|
7404
|
+
if (nodeList.length) {
|
|
7405
|
+
return nodeList;
|
|
7406
|
+
}
|
|
7017
7407
|
}
|
|
7018
|
-
}
|
|
7408
|
+
}
|
|
7409
|
+
return UtilsContext.wait(() => {
|
|
7410
|
+
let node = getNodeList();
|
|
7411
|
+
if (node) {
|
|
7412
|
+
return {
|
|
7413
|
+
success: true,
|
|
7414
|
+
data: node,
|
|
7415
|
+
};
|
|
7416
|
+
}
|
|
7417
|
+
else {
|
|
7418
|
+
return {
|
|
7419
|
+
success: false,
|
|
7420
|
+
data: node,
|
|
7421
|
+
};
|
|
7422
|
+
}
|
|
7423
|
+
}, timeout, parent);
|
|
7019
7424
|
}
|
|
7020
7425
|
waitAnyNodeList(...args) {
|
|
7021
7426
|
// 过滤掉undefined
|
|
7022
|
-
args = args.filter((arg) => arg !==
|
|
7427
|
+
args = args.filter((arg) => arg !== undefined);
|
|
7023
7428
|
let UtilsContext = this;
|
|
7024
7429
|
// 选择器数组
|
|
7025
7430
|
let selectorList = args[0];
|
|
@@ -7317,6 +7722,7 @@
|
|
|
7317
7722
|
* > "测试"
|
|
7318
7723
|
*/
|
|
7319
7724
|
Vue = Vue;
|
|
7725
|
+
ModuleRaid = ModuleRaid;
|
|
7320
7726
|
}
|
|
7321
7727
|
let utils = new Utils();
|
|
7322
7728
|
|