@whitesev/utils 2.5.7 → 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 +444 -45
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +444 -45
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +444 -45
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +444 -45
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +444 -45
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +444 -45
- 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 +4 -2
- package/package.json +1 -1
- package/src/ModuleRaid.js +397 -0
- package/src/Utils.ts +3 -1
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,411 @@ 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
|
+
|
|
4139
4537
|
class Utils {
|
|
4140
4538
|
windowApi;
|
|
4141
4539
|
constructor(option) {
|
|
4142
4540
|
this.windowApi = new WindowApi(option);
|
|
4143
4541
|
}
|
|
4144
4542
|
/** 版本号 */
|
|
4145
|
-
version = "2025.1.
|
|
4543
|
+
version = "2025.1.11";
|
|
4146
4544
|
addStyle(cssText) {
|
|
4147
4545
|
if (typeof cssText !== "string") {
|
|
4148
4546
|
throw new Error("Utils.addStyle 参数cssText 必须为String类型");
|
|
@@ -4365,8 +4763,8 @@ var Utils = (function () {
|
|
|
4365
4763
|
ColorConversion = ColorConversion;
|
|
4366
4764
|
deepClone(obj) {
|
|
4367
4765
|
let UtilsContext = this;
|
|
4368
|
-
if (obj ===
|
|
4369
|
-
return
|
|
4766
|
+
if (obj === undefined)
|
|
4767
|
+
return undefined;
|
|
4370
4768
|
if (obj === null)
|
|
4371
4769
|
return null;
|
|
4372
4770
|
let clone = obj instanceof Array ? [] : {};
|
|
@@ -5812,36 +6210,36 @@ var Utils = (function () {
|
|
|
5812
6210
|
* + true 监听以 target 为根节点的整个子树。包括子树中所有节点的属性,而不仅仅是针对 target
|
|
5813
6211
|
* + false (默认) 不生效
|
|
5814
6212
|
*/
|
|
5815
|
-
subtree:
|
|
6213
|
+
subtree: undefined,
|
|
5816
6214
|
/**
|
|
5817
6215
|
* + true 监听 target 节点中发生的节点的新增与删除(同时,如果 subtree 为 true,会针对整个子树生效)
|
|
5818
6216
|
* + false (默认) 不生效
|
|
5819
6217
|
*/
|
|
5820
|
-
childList:
|
|
6218
|
+
childList: undefined,
|
|
5821
6219
|
/**
|
|
5822
6220
|
* + true 观察所有监听的节点属性值的变化。默认值为 true,当声明了 attributeFilter 或 attributeOldValue
|
|
5823
6221
|
* + false (默认) 不生效
|
|
5824
6222
|
*/
|
|
5825
|
-
attributes:
|
|
6223
|
+
attributes: undefined,
|
|
5826
6224
|
/**
|
|
5827
6225
|
* 一个用于声明哪些属性名会被监听的数组。如果不声明该属性,所有属性的变化都将触发通知
|
|
5828
6226
|
*/
|
|
5829
|
-
attributeFilter:
|
|
6227
|
+
attributeFilter: undefined,
|
|
5830
6228
|
/**
|
|
5831
6229
|
* + true 记录上一次被监听的节点的属性变化;可查阅 MutationObserver 中的 Monitoring attribute values 了解关于观察属性变化和属性值记录的详情
|
|
5832
6230
|
* + false (默认) 不生效
|
|
5833
6231
|
*/
|
|
5834
|
-
attributeOldValue:
|
|
6232
|
+
attributeOldValue: undefined,
|
|
5835
6233
|
/**
|
|
5836
6234
|
* + true 监听声明的 target 节点上所有字符的变化。默认值为 true,如果声明了 characterDataOldValue
|
|
5837
6235
|
* + false (默认) 不生效
|
|
5838
6236
|
*/
|
|
5839
|
-
characterData:
|
|
6237
|
+
characterData: undefined,
|
|
5840
6238
|
/**
|
|
5841
6239
|
* + true 记录前一个被监听的节点中发生的文本变化
|
|
5842
6240
|
* + false (默认) 不生效
|
|
5843
6241
|
*/
|
|
5844
|
-
characterDataOldValue:
|
|
6242
|
+
characterDataOldValue: undefined,
|
|
5845
6243
|
},
|
|
5846
6244
|
immediate: false,
|
|
5847
6245
|
};
|
|
@@ -6416,7 +6814,7 @@ var Utils = (function () {
|
|
|
6416
6814
|
}
|
|
6417
6815
|
return new Promise((resolve) => {
|
|
6418
6816
|
setTimeout(() => {
|
|
6419
|
-
resolve(
|
|
6817
|
+
resolve(undefined);
|
|
6420
6818
|
}, delayTime);
|
|
6421
6819
|
});
|
|
6422
6820
|
}
|
|
@@ -6791,7 +7189,7 @@ var Utils = (function () {
|
|
|
6791
7189
|
}
|
|
6792
7190
|
waitNode(...args) {
|
|
6793
7191
|
// 过滤掉undefined
|
|
6794
|
-
args = args.filter((arg) => arg !==
|
|
7192
|
+
args = args.filter((arg) => arg !== undefined);
|
|
6795
7193
|
let UtilsContext = this;
|
|
6796
7194
|
// 选择器
|
|
6797
7195
|
let selector = args[0];
|
|
@@ -6880,7 +7278,7 @@ var Utils = (function () {
|
|
|
6880
7278
|
}
|
|
6881
7279
|
waitAnyNode(...args) {
|
|
6882
7280
|
// 过滤掉undefined
|
|
6883
|
-
args = args.filter((arg) => arg !==
|
|
7281
|
+
args = args.filter((arg) => arg !== undefined);
|
|
6884
7282
|
let UtilsContext = this;
|
|
6885
7283
|
// 选择器
|
|
6886
7284
|
let selectorList = args[0];
|
|
@@ -6936,7 +7334,7 @@ var Utils = (function () {
|
|
|
6936
7334
|
}
|
|
6937
7335
|
waitNodeList(...args) {
|
|
6938
7336
|
// 过滤掉undefined
|
|
6939
|
-
args = args.filter((arg) => arg !==
|
|
7337
|
+
args = args.filter((arg) => arg !== undefined);
|
|
6940
7338
|
let UtilsContext = this;
|
|
6941
7339
|
// 选择器数组
|
|
6942
7340
|
let selector = args[0];
|
|
@@ -7023,7 +7421,7 @@ var Utils = (function () {
|
|
|
7023
7421
|
}
|
|
7024
7422
|
waitAnyNodeList(...args) {
|
|
7025
7423
|
// 过滤掉undefined
|
|
7026
|
-
args = args.filter((arg) => arg !==
|
|
7424
|
+
args = args.filter((arg) => arg !== undefined);
|
|
7027
7425
|
let UtilsContext = this;
|
|
7028
7426
|
// 选择器数组
|
|
7029
7427
|
let selectorList = args[0];
|
|
@@ -7321,6 +7719,7 @@ var Utils = (function () {
|
|
|
7321
7719
|
* > "测试"
|
|
7322
7720
|
*/
|
|
7323
7721
|
Vue = Vue;
|
|
7722
|
+
ModuleRaid = ModuleRaid;
|
|
7324
7723
|
}
|
|
7325
7724
|
let utils = new Utils();
|
|
7326
7725
|
|