@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.esm.js
CHANGED
|
@@ -243,7 +243,7 @@ class UtilsGMCookie {
|
|
|
243
243
|
throw new TypeError("Utils.GMCookie.get 参数cookieName 必须为字符串");
|
|
244
244
|
}
|
|
245
245
|
let cookies = this.windowApi.document.cookie.split(";");
|
|
246
|
-
let findValue =
|
|
246
|
+
let findValue = undefined;
|
|
247
247
|
for (const cookieItem of cookies) {
|
|
248
248
|
let item = cookieItem.trim();
|
|
249
249
|
let itemSplit = item.split("=");
|
|
@@ -1277,14 +1277,14 @@ class GMMenu {
|
|
|
1277
1277
|
const option = menuOption[index];
|
|
1278
1278
|
this.MenuHandle.$data.data.push({
|
|
1279
1279
|
data: option,
|
|
1280
|
-
id:
|
|
1280
|
+
id: undefined,
|
|
1281
1281
|
});
|
|
1282
1282
|
}
|
|
1283
1283
|
}
|
|
1284
1284
|
else {
|
|
1285
1285
|
this.MenuHandle.$data.data.push({
|
|
1286
1286
|
data: menuOption,
|
|
1287
|
-
id:
|
|
1287
|
+
id: undefined,
|
|
1288
1288
|
});
|
|
1289
1289
|
}
|
|
1290
1290
|
}
|
|
@@ -2412,13 +2412,13 @@ class Httpx {
|
|
|
2412
2412
|
status: fetchResponse.status,
|
|
2413
2413
|
statusText: fetchResponse.statusText,
|
|
2414
2414
|
// @ts-ignore
|
|
2415
|
-
response:
|
|
2415
|
+
response: undefined,
|
|
2416
2416
|
responseFetchHeaders: fetchResponse.headers,
|
|
2417
2417
|
responseHeaders: "",
|
|
2418
2418
|
// @ts-ignore
|
|
2419
|
-
responseText:
|
|
2419
|
+
responseText: undefined,
|
|
2420
2420
|
responseType: option.responseType,
|
|
2421
|
-
responseXML:
|
|
2421
|
+
responseXML: undefined,
|
|
2422
2422
|
};
|
|
2423
2423
|
Object.assign(httpxResponse, option.context || {});
|
|
2424
2424
|
// 把headers转为字符串
|
|
@@ -2530,30 +2530,30 @@ class Httpx {
|
|
|
2530
2530
|
* 默认配置
|
|
2531
2531
|
*/
|
|
2532
2532
|
#defaultDetails = {
|
|
2533
|
-
url:
|
|
2533
|
+
url: undefined,
|
|
2534
2534
|
timeout: 5000,
|
|
2535
2535
|
async: false,
|
|
2536
|
-
responseType:
|
|
2537
|
-
headers:
|
|
2538
|
-
data:
|
|
2539
|
-
redirect:
|
|
2540
|
-
cookie:
|
|
2541
|
-
cookiePartition:
|
|
2542
|
-
binary:
|
|
2543
|
-
nocache:
|
|
2544
|
-
revalidate:
|
|
2545
|
-
context:
|
|
2546
|
-
overrideMimeType:
|
|
2547
|
-
anonymous:
|
|
2548
|
-
fetch:
|
|
2549
|
-
fetchInit:
|
|
2536
|
+
responseType: undefined,
|
|
2537
|
+
headers: undefined,
|
|
2538
|
+
data: undefined,
|
|
2539
|
+
redirect: undefined,
|
|
2540
|
+
cookie: undefined,
|
|
2541
|
+
cookiePartition: undefined,
|
|
2542
|
+
binary: undefined,
|
|
2543
|
+
nocache: undefined,
|
|
2544
|
+
revalidate: undefined,
|
|
2545
|
+
context: undefined,
|
|
2546
|
+
overrideMimeType: undefined,
|
|
2547
|
+
anonymous: undefined,
|
|
2548
|
+
fetch: undefined,
|
|
2549
|
+
fetchInit: undefined,
|
|
2550
2550
|
allowInterceptConfig: {
|
|
2551
2551
|
beforeRequest: true,
|
|
2552
2552
|
afterResponseSuccess: true,
|
|
2553
2553
|
afterResponseError: true,
|
|
2554
2554
|
},
|
|
2555
|
-
user:
|
|
2556
|
-
password:
|
|
2555
|
+
user: undefined,
|
|
2556
|
+
password: undefined,
|
|
2557
2557
|
onabort() { },
|
|
2558
2558
|
onerror() { },
|
|
2559
2559
|
ontimeout() { },
|
|
@@ -3037,7 +3037,7 @@ class indexedDB {
|
|
|
3037
3037
|
success: false,
|
|
3038
3038
|
code: that.#statusCode.getFailed.code,
|
|
3039
3039
|
msg: that.#statusCode.getFailed.msg,
|
|
3040
|
-
data:
|
|
3040
|
+
data: undefined,
|
|
3041
3041
|
});
|
|
3042
3042
|
}
|
|
3043
3043
|
else {
|
|
@@ -3047,7 +3047,7 @@ class indexedDB {
|
|
|
3047
3047
|
let result = target.result;
|
|
3048
3048
|
/* result 返回的是 {key: string, value: any} */
|
|
3049
3049
|
/* 键值对存储 */
|
|
3050
|
-
let data = result ? result.value :
|
|
3050
|
+
let data = result ? result.value : undefined;
|
|
3051
3051
|
if (data == null) {
|
|
3052
3052
|
resolve({
|
|
3053
3053
|
success: true,
|
|
@@ -3074,7 +3074,7 @@ class indexedDB {
|
|
|
3074
3074
|
success: false,
|
|
3075
3075
|
code: that.#statusCode.getFailed.code,
|
|
3076
3076
|
msg: that.#statusCode.getFailed.msg,
|
|
3077
|
-
data:
|
|
3077
|
+
data: undefined,
|
|
3078
3078
|
event: event,
|
|
3079
3079
|
});
|
|
3080
3080
|
};
|
|
@@ -3654,7 +3654,7 @@ const TryCatch = function (...args) {
|
|
|
3654
3654
|
context = __context__ || this;
|
|
3655
3655
|
let result = executeTryCatch(callbackFunction, handleError, context);
|
|
3656
3656
|
// @ts-ignore
|
|
3657
|
-
return result !==
|
|
3657
|
+
return result !== undefined ? result : TryCatchCore;
|
|
3658
3658
|
},
|
|
3659
3659
|
};
|
|
3660
3660
|
/**
|
|
@@ -3665,7 +3665,7 @@ const TryCatch = function (...args) {
|
|
|
3665
3665
|
* @returns 如果函数有返回值,则返回该返回值;否则返回 undefined。
|
|
3666
3666
|
*/
|
|
3667
3667
|
function executeTryCatch(callback, handleErrorFunc, funcThis) {
|
|
3668
|
-
let result =
|
|
3668
|
+
let result = undefined;
|
|
3669
3669
|
try {
|
|
3670
3670
|
if (typeof callback === "string") {
|
|
3671
3671
|
(function () {
|
|
@@ -3733,7 +3733,7 @@ class UtilsDictionary {
|
|
|
3733
3733
|
*/
|
|
3734
3734
|
getStartsWith(key) {
|
|
3735
3735
|
let allKeys = this.keys();
|
|
3736
|
-
let result =
|
|
3736
|
+
let result = undefined;
|
|
3737
3737
|
for (const keyName of allKeys) {
|
|
3738
3738
|
if (String(keyName).startsWith(String(key))) {
|
|
3739
3739
|
result = this.get(keyName);
|
|
@@ -3748,7 +3748,7 @@ class UtilsDictionary {
|
|
|
3748
3748
|
* @param val 值,默认为""
|
|
3749
3749
|
*/
|
|
3750
3750
|
set(key, val) {
|
|
3751
|
-
if (key ===
|
|
3751
|
+
if (key === undefined) {
|
|
3752
3752
|
throw new Error("Utils.Dictionary().set 参数 key 不能为空");
|
|
3753
3753
|
}
|
|
3754
3754
|
Reflect.set(this.items, key, val);
|
|
@@ -4133,13 +4133,411 @@ class Vue {
|
|
|
4133
4133
|
}
|
|
4134
4134
|
}
|
|
4135
4135
|
|
|
4136
|
+
// ==UserScript==
|
|
4137
|
+
// @name ModuleRaid.js
|
|
4138
|
+
// @namespace http://tampermonkey.net/
|
|
4139
|
+
// @version 6.2.0
|
|
4140
|
+
// @description 检索调用webpackJsonp模块,可指定检索的window
|
|
4141
|
+
// @author empyrealtear
|
|
4142
|
+
// @license MIT
|
|
4143
|
+
// @original-script https://github.com/pixeldesu/moduleRaid
|
|
4144
|
+
// ==/UserScript==
|
|
4145
|
+
|
|
4146
|
+
|
|
4147
|
+
/**
|
|
4148
|
+
* Main moduleRaid class
|
|
4149
|
+
* @link https://scriptcat.org/zh-CN/script-show-page/2628
|
|
4150
|
+
*/
|
|
4151
|
+
class ModuleRaid {
|
|
4152
|
+
/**
|
|
4153
|
+
* moduleRaid constructor
|
|
4154
|
+
*
|
|
4155
|
+
* @example
|
|
4156
|
+
* Constructing an instance without any arguments:
|
|
4157
|
+
* ```ts
|
|
4158
|
+
* const mR = new ModuleRaid()
|
|
4159
|
+
* ```
|
|
4160
|
+
*
|
|
4161
|
+
* Constructing an instance with the optional `opts` object:
|
|
4162
|
+
* ```ts
|
|
4163
|
+
* const mR = new ModuleRaid({ entrypoint: 'webpackChunk_custom_name' })
|
|
4164
|
+
* ```
|
|
4165
|
+
*
|
|
4166
|
+
* @param opts a object containing options to initialize moduleRaid with
|
|
4167
|
+
* - **opts:**
|
|
4168
|
+
* - _target_: the window object being searched for
|
|
4169
|
+
* - _entrypoint_: the Webpack entrypoint present on the global window object
|
|
4170
|
+
* - _debug_: whether debug mode is enabled or not
|
|
4171
|
+
* - _strict_: whether strict mode is enabled or not
|
|
4172
|
+
*/
|
|
4173
|
+
constructor(opts) {
|
|
4174
|
+
/**
|
|
4175
|
+
* A random generated module ID we use for injecting into Webpack
|
|
4176
|
+
*/
|
|
4177
|
+
this.moduleID = Math.random().toString(36).substring(7);
|
|
4178
|
+
/**
|
|
4179
|
+
* An array containing different argument injection methods for
|
|
4180
|
+
* Webpack (before version 4), and subsequently pulling out methods and modules
|
|
4181
|
+
* @internal
|
|
4182
|
+
*/
|
|
4183
|
+
this.functionArguments = [
|
|
4184
|
+
[
|
|
4185
|
+
[0],
|
|
4186
|
+
[
|
|
4187
|
+
(_e, _t, i) => {
|
|
4188
|
+
this.modules = i.c;
|
|
4189
|
+
this.constructors = i.m;
|
|
4190
|
+
this.get = i;
|
|
4191
|
+
},
|
|
4192
|
+
],
|
|
4193
|
+
],
|
|
4194
|
+
[
|
|
4195
|
+
[1e3],
|
|
4196
|
+
{
|
|
4197
|
+
[this.moduleID]: (_e, _t, i) => {
|
|
4198
|
+
this.modules = i.c;
|
|
4199
|
+
this.constructors = i.m;
|
|
4200
|
+
this.get = i;
|
|
4201
|
+
},
|
|
4202
|
+
},
|
|
4203
|
+
[[this.moduleID]],
|
|
4204
|
+
],
|
|
4205
|
+
];
|
|
4206
|
+
/**
|
|
4207
|
+
* An array containing different argument injection methods for
|
|
4208
|
+
* Webpack (after version 4), and subsequently pulling out methods and modules
|
|
4209
|
+
* @internal
|
|
4210
|
+
*/
|
|
4211
|
+
this.arrayArguments = [
|
|
4212
|
+
[
|
|
4213
|
+
[this.moduleID],
|
|
4214
|
+
{},
|
|
4215
|
+
(e) => {
|
|
4216
|
+
const mCac = e.m;
|
|
4217
|
+
Object.keys(mCac).forEach((mod) => {
|
|
4218
|
+
try {
|
|
4219
|
+
this.modules[mod] = e(mod);
|
|
4220
|
+
}
|
|
4221
|
+
catch (err) {
|
|
4222
|
+
this.log(`[arrayArguments/1] Failed to require(${mod}) with error:\n${err}\n${err.stack}`);
|
|
4223
|
+
}
|
|
4224
|
+
});
|
|
4225
|
+
this.get = e;
|
|
4226
|
+
},
|
|
4227
|
+
],
|
|
4228
|
+
this.functionArguments[1],
|
|
4229
|
+
];
|
|
4230
|
+
/**
|
|
4231
|
+
* Storage for the modules we extracted from Webpack
|
|
4232
|
+
*/
|
|
4233
|
+
this.modules = {};
|
|
4234
|
+
/**
|
|
4235
|
+
* Storage for the constructors we extracted from Webpack
|
|
4236
|
+
*/
|
|
4237
|
+
this.constructors = [];
|
|
4238
|
+
let options = {
|
|
4239
|
+
target: window,
|
|
4240
|
+
entrypoint: 'webpackJsonp',
|
|
4241
|
+
debug: false,
|
|
4242
|
+
strict: false,
|
|
4243
|
+
};
|
|
4244
|
+
if (typeof opts === 'object') {
|
|
4245
|
+
options = Object.assign(Object.assign({}, options), opts);
|
|
4246
|
+
}
|
|
4247
|
+
this.target = options.target;
|
|
4248
|
+
this.entrypoint = options.entrypoint;
|
|
4249
|
+
this.debug = options.debug;
|
|
4250
|
+
this.strict = options.strict;
|
|
4251
|
+
this.detectEntrypoint();
|
|
4252
|
+
this.fillModules();
|
|
4253
|
+
this.replaceGet();
|
|
4254
|
+
this.setupPushEvent();
|
|
4255
|
+
}
|
|
4256
|
+
/**
|
|
4257
|
+
* Debug logging method, outputs to the console when {@link ModuleRaid.debug} is true
|
|
4258
|
+
*
|
|
4259
|
+
* @param {*} message The message to be logged
|
|
4260
|
+
* @internal
|
|
4261
|
+
*/
|
|
4262
|
+
log(message) {
|
|
4263
|
+
if (this.debug) {
|
|
4264
|
+
console.warn(`[moduleRaid] ${message}`);
|
|
4265
|
+
}
|
|
4266
|
+
}
|
|
4267
|
+
/**
|
|
4268
|
+
* Method to set an alternative getter if we weren't able to extract __webpack_require__
|
|
4269
|
+
* from Webpack
|
|
4270
|
+
* @internal
|
|
4271
|
+
*/
|
|
4272
|
+
replaceGet() {
|
|
4273
|
+
if (this.get === null) {
|
|
4274
|
+
this.get = (key) => this.modules[key];
|
|
4275
|
+
}
|
|
4276
|
+
}
|
|
4277
|
+
/**
|
|
4278
|
+
* Method that will try to inject a module into Webpack or get modules
|
|
4279
|
+
* depending on it's success it might be more or less brute about it
|
|
4280
|
+
* @internal
|
|
4281
|
+
*/
|
|
4282
|
+
fillModules() {
|
|
4283
|
+
if (typeof this.target[this.entrypoint] === 'function') {
|
|
4284
|
+
this.functionArguments.forEach((argument, index) => {
|
|
4285
|
+
try {
|
|
4286
|
+
if (this.modules && Object.keys(this.modules).length > 0)
|
|
4287
|
+
return;
|
|
4288
|
+
this.target[this.entrypoint](...argument);
|
|
4289
|
+
}
|
|
4290
|
+
catch (err) {
|
|
4291
|
+
this.log(`moduleRaid.functionArguments[${index}] failed:\n${err}\n${err.stack}`);
|
|
4292
|
+
}
|
|
4293
|
+
});
|
|
4294
|
+
}
|
|
4295
|
+
else {
|
|
4296
|
+
this.arrayArguments.forEach((argument, index) => {
|
|
4297
|
+
try {
|
|
4298
|
+
if (this.modules && Object.keys(this.modules).length > 0)
|
|
4299
|
+
return;
|
|
4300
|
+
this.target[this.entrypoint].push(argument);
|
|
4301
|
+
}
|
|
4302
|
+
catch (err) {
|
|
4303
|
+
this.log(`Pushing moduleRaid.arrayArguments[${index}] into ${this.entrypoint} failed:\n${err}\n${err.stack}`);
|
|
4304
|
+
}
|
|
4305
|
+
});
|
|
4306
|
+
}
|
|
4307
|
+
if (this.modules && Object.keys(this.modules).length == 0) {
|
|
4308
|
+
let moduleEnd = false;
|
|
4309
|
+
let moduleIterator = 0;
|
|
4310
|
+
if (typeof this.target[this.entrypoint] != 'function' || !this.target[this.entrypoint]([], [], [moduleIterator])) {
|
|
4311
|
+
throw Error('Unknown Webpack structure');
|
|
4312
|
+
}
|
|
4313
|
+
while (!moduleEnd) {
|
|
4314
|
+
try {
|
|
4315
|
+
this.modules[moduleIterator] = this.target[this.entrypoint]([], [], [moduleIterator]);
|
|
4316
|
+
moduleIterator++;
|
|
4317
|
+
}
|
|
4318
|
+
catch (err) {
|
|
4319
|
+
moduleEnd = true;
|
|
4320
|
+
}
|
|
4321
|
+
}
|
|
4322
|
+
}
|
|
4323
|
+
}
|
|
4324
|
+
/**
|
|
4325
|
+
* Method to hook into `window[this.entrypoint].push` adding a listener for new
|
|
4326
|
+
* chunks being pushed into Webpack
|
|
4327
|
+
*
|
|
4328
|
+
* @example
|
|
4329
|
+
* You can listen for newly pushed packages using the `moduleraid:webpack-push` event
|
|
4330
|
+
* on `document`
|
|
4331
|
+
*
|
|
4332
|
+
* ```ts
|
|
4333
|
+
* document.addEventListener('moduleraid:webpack-push', (e) => {
|
|
4334
|
+
* // e.detail contains the arguments push() was called with
|
|
4335
|
+
* console.log(e.detail)
|
|
4336
|
+
* })
|
|
4337
|
+
* ```
|
|
4338
|
+
* @internal
|
|
4339
|
+
*/
|
|
4340
|
+
setupPushEvent() {
|
|
4341
|
+
const originalPush = this.target[this.entrypoint].push;
|
|
4342
|
+
this.target[this.entrypoint].push = (...args) => {
|
|
4343
|
+
const result = Reflect.apply(originalPush, this.target[this.entrypoint], args);
|
|
4344
|
+
document.dispatchEvent(new CustomEvent('moduleraid:webpack-push', { detail: args }));
|
|
4345
|
+
return result;
|
|
4346
|
+
};
|
|
4347
|
+
}
|
|
4348
|
+
/**
|
|
4349
|
+
* Method to try autodetecting a Webpack JSONP entrypoint based on common naming
|
|
4350
|
+
*
|
|
4351
|
+
* If the default entrypoint, or the entrypoint that's passed to the moduleRaid constructor
|
|
4352
|
+
* already matches, the method exits early
|
|
4353
|
+
*
|
|
4354
|
+
* If `options.strict` has been set in the constructor and the initial entrypoint cannot
|
|
4355
|
+
* be found, this method will error, demanding a strictly set entrypoint
|
|
4356
|
+
* @internal
|
|
4357
|
+
*/
|
|
4358
|
+
detectEntrypoint() {
|
|
4359
|
+
if (this.target[this.entrypoint] != undefined) {
|
|
4360
|
+
return;
|
|
4361
|
+
}
|
|
4362
|
+
if (this.strict) {
|
|
4363
|
+
throw Error(`Strict mode is enabled and entrypoint at window.${this.entrypoint} couldn't be found. Please specify the correct one!`);
|
|
4364
|
+
}
|
|
4365
|
+
let windowObjects = Object.keys(this.target);
|
|
4366
|
+
windowObjects = windowObjects
|
|
4367
|
+
.filter((object) => object.toLowerCase().includes('chunk') || object.toLowerCase().includes('webpack'))
|
|
4368
|
+
.filter((object) => typeof this.target[object] === 'function' || Array.isArray(this.target[object]));
|
|
4369
|
+
if (windowObjects.length > 1) {
|
|
4370
|
+
throw Error(`Multiple possible endpoints have been detected, please create a new moduleRaid instance with a specific one:\n${windowObjects.join(', ')}`);
|
|
4371
|
+
}
|
|
4372
|
+
if (windowObjects.length === 0) {
|
|
4373
|
+
throw Error('No Webpack JSONP entrypoints could be detected');
|
|
4374
|
+
}
|
|
4375
|
+
this.log(`Entrypoint has been detected at window.${windowObjects[0]} and set for injection`);
|
|
4376
|
+
this.entrypoint = windowObjects[0];
|
|
4377
|
+
}
|
|
4378
|
+
/**
|
|
4379
|
+
* Recursive object-search function for modules
|
|
4380
|
+
*
|
|
4381
|
+
* @param object the object to search through
|
|
4382
|
+
* @param query the query the object keys/values are searched for
|
|
4383
|
+
* @returns boolean state of `object` containing `query` somewhere in it
|
|
4384
|
+
* @internal
|
|
4385
|
+
*/
|
|
4386
|
+
searchObject(object, query) {
|
|
4387
|
+
for (const key in object) {
|
|
4388
|
+
const value = object[key];
|
|
4389
|
+
const lowerCaseQuery = query.toLowerCase();
|
|
4390
|
+
if (typeof value != 'object') {
|
|
4391
|
+
const lowerCaseKey = key.toString().toLowerCase();
|
|
4392
|
+
if (lowerCaseKey.includes(lowerCaseQuery))
|
|
4393
|
+
return true;
|
|
4394
|
+
if (typeof value != 'object') {
|
|
4395
|
+
const lowerCaseValue = value.toString().toLowerCase();
|
|
4396
|
+
if (lowerCaseValue.includes(lowerCaseQuery))
|
|
4397
|
+
return true;
|
|
4398
|
+
}
|
|
4399
|
+
else {
|
|
4400
|
+
if (this.searchObject(value, query))
|
|
4401
|
+
return true;
|
|
4402
|
+
}
|
|
4403
|
+
}
|
|
4404
|
+
}
|
|
4405
|
+
return false;
|
|
4406
|
+
}
|
|
4407
|
+
/**
|
|
4408
|
+
* Method to search through the module object, searching for the fitting content
|
|
4409
|
+
* if a string is supplied
|
|
4410
|
+
*
|
|
4411
|
+
* If query is supplied as a function, everything that returns true when passed
|
|
4412
|
+
* to the query function will be returned
|
|
4413
|
+
*
|
|
4414
|
+
* @example
|
|
4415
|
+
* With a string as query argument:
|
|
4416
|
+
* ```ts
|
|
4417
|
+
* const results = mR.findModule('feature')
|
|
4418
|
+
* // => Array of module results
|
|
4419
|
+
* ```
|
|
4420
|
+
*
|
|
4421
|
+
* With a function as query argument:
|
|
4422
|
+
* ```ts
|
|
4423
|
+
* const results = mR.findModule((module) => { typeof module === 'function' })
|
|
4424
|
+
* // => Array of module results
|
|
4425
|
+
* ```
|
|
4426
|
+
*
|
|
4427
|
+
* @param query query to search the module list for
|
|
4428
|
+
* @return a list of modules fitting the query
|
|
4429
|
+
*/
|
|
4430
|
+
findModule(query) {
|
|
4431
|
+
const results = [];
|
|
4432
|
+
const modules = Object.keys(this.modules);
|
|
4433
|
+
if (modules.length === 0) {
|
|
4434
|
+
throw new Error('There are no modules to search through!');
|
|
4435
|
+
}
|
|
4436
|
+
modules.forEach((key) => {
|
|
4437
|
+
const module = this.modules[key.toString()];
|
|
4438
|
+
if (module === undefined)
|
|
4439
|
+
return;
|
|
4440
|
+
try {
|
|
4441
|
+
if (typeof query === 'string') {
|
|
4442
|
+
query = query.toLowerCase();
|
|
4443
|
+
switch (typeof module) {
|
|
4444
|
+
case 'string':
|
|
4445
|
+
if (module.toLowerCase().includes(query))
|
|
4446
|
+
results.push(module);
|
|
4447
|
+
break;
|
|
4448
|
+
case 'function':
|
|
4449
|
+
if (module.toString().toLowerCase().includes(query))
|
|
4450
|
+
results.push(module);
|
|
4451
|
+
break;
|
|
4452
|
+
case 'object':
|
|
4453
|
+
if (this.searchObject(module, query))
|
|
4454
|
+
results.push(module);
|
|
4455
|
+
break;
|
|
4456
|
+
}
|
|
4457
|
+
}
|
|
4458
|
+
else if (typeof query === 'function') {
|
|
4459
|
+
if (query(module))
|
|
4460
|
+
results.push(module);
|
|
4461
|
+
}
|
|
4462
|
+
else {
|
|
4463
|
+
throw new TypeError(`findModule can only find via string and function, ${typeof query} was passed`);
|
|
4464
|
+
}
|
|
4465
|
+
}
|
|
4466
|
+
catch (err) {
|
|
4467
|
+
this.log(`There was an error while searching through module '${key}':\n${err}\n${err.stack}`);
|
|
4468
|
+
}
|
|
4469
|
+
});
|
|
4470
|
+
return results;
|
|
4471
|
+
}
|
|
4472
|
+
/**
|
|
4473
|
+
* Method to search through the constructor array, searching for the fitting content
|
|
4474
|
+
* if a string is supplied
|
|
4475
|
+
*
|
|
4476
|
+
* If query is supplied as a function, everything that returns true when passed
|
|
4477
|
+
* to the query function will be returned
|
|
4478
|
+
*
|
|
4479
|
+
* @example
|
|
4480
|
+
* With a string as query argument:
|
|
4481
|
+
* ```ts
|
|
4482
|
+
* const results = mR.findConstructor('feature')
|
|
4483
|
+
* // => Array of constructor/module tuples
|
|
4484
|
+
* ```
|
|
4485
|
+
*
|
|
4486
|
+
* With a function as query argument:
|
|
4487
|
+
* ```ts
|
|
4488
|
+
* const results = mR.findConstructor((constructor) => { constructor.prototype.value !== undefined })
|
|
4489
|
+
* // => Array of constructor/module tuples
|
|
4490
|
+
* ```
|
|
4491
|
+
*
|
|
4492
|
+
* Accessing the resulting data:
|
|
4493
|
+
* ```ts
|
|
4494
|
+
* // With array destructuring (ES6)
|
|
4495
|
+
* const [constructor, module] = results[0]
|
|
4496
|
+
*
|
|
4497
|
+
* // ...or...
|
|
4498
|
+
*
|
|
4499
|
+
* // regular access
|
|
4500
|
+
* const constructor = results[0][0]
|
|
4501
|
+
* const module = results[0][1]
|
|
4502
|
+
* ```
|
|
4503
|
+
*
|
|
4504
|
+
* @param query query to search the constructor list for
|
|
4505
|
+
* @returns a list of constructor/module tuples fitting the query
|
|
4506
|
+
*/
|
|
4507
|
+
findConstructor(query) {
|
|
4508
|
+
const results = [];
|
|
4509
|
+
const constructors = Object.keys(this.constructors);
|
|
4510
|
+
if (constructors.length === 0) {
|
|
4511
|
+
throw new Error('There are no constructors to search through!');
|
|
4512
|
+
}
|
|
4513
|
+
constructors.forEach((key) => {
|
|
4514
|
+
const constructor = this.constructors[key];
|
|
4515
|
+
try {
|
|
4516
|
+
if (typeof query === 'string') {
|
|
4517
|
+
query = query.toLowerCase();
|
|
4518
|
+
if (constructor.toString().toLowerCase().includes(query))
|
|
4519
|
+
results.push([this.constructors[key], this.modules[key]]);
|
|
4520
|
+
}
|
|
4521
|
+
else if (typeof query === 'function') {
|
|
4522
|
+
if (query(constructor))
|
|
4523
|
+
results.push([this.constructors[key], this.modules[key]]);
|
|
4524
|
+
}
|
|
4525
|
+
}
|
|
4526
|
+
catch (err) {
|
|
4527
|
+
this.log(`There was an error while searching through constructor '${key}':\n${err}\n${err.stack}`);
|
|
4528
|
+
}
|
|
4529
|
+
});
|
|
4530
|
+
return results;
|
|
4531
|
+
}
|
|
4532
|
+
}
|
|
4533
|
+
|
|
4136
4534
|
class Utils {
|
|
4137
4535
|
windowApi;
|
|
4138
4536
|
constructor(option) {
|
|
4139
4537
|
this.windowApi = new WindowApi(option);
|
|
4140
4538
|
}
|
|
4141
4539
|
/** 版本号 */
|
|
4142
|
-
version = "2025.1.
|
|
4540
|
+
version = "2025.1.11";
|
|
4143
4541
|
addStyle(cssText) {
|
|
4144
4542
|
if (typeof cssText !== "string") {
|
|
4145
4543
|
throw new Error("Utils.addStyle 参数cssText 必须为String类型");
|
|
@@ -4362,8 +4760,8 @@ class Utils {
|
|
|
4362
4760
|
ColorConversion = ColorConversion;
|
|
4363
4761
|
deepClone(obj) {
|
|
4364
4762
|
let UtilsContext = this;
|
|
4365
|
-
if (obj ===
|
|
4366
|
-
return
|
|
4763
|
+
if (obj === undefined)
|
|
4764
|
+
return undefined;
|
|
4367
4765
|
if (obj === null)
|
|
4368
4766
|
return null;
|
|
4369
4767
|
let clone = obj instanceof Array ? [] : {};
|
|
@@ -5809,36 +6207,36 @@ class Utils {
|
|
|
5809
6207
|
* + true 监听以 target 为根节点的整个子树。包括子树中所有节点的属性,而不仅仅是针对 target
|
|
5810
6208
|
* + false (默认) 不生效
|
|
5811
6209
|
*/
|
|
5812
|
-
subtree:
|
|
6210
|
+
subtree: undefined,
|
|
5813
6211
|
/**
|
|
5814
6212
|
* + true 监听 target 节点中发生的节点的新增与删除(同时,如果 subtree 为 true,会针对整个子树生效)
|
|
5815
6213
|
* + false (默认) 不生效
|
|
5816
6214
|
*/
|
|
5817
|
-
childList:
|
|
6215
|
+
childList: undefined,
|
|
5818
6216
|
/**
|
|
5819
6217
|
* + true 观察所有监听的节点属性值的变化。默认值为 true,当声明了 attributeFilter 或 attributeOldValue
|
|
5820
6218
|
* + false (默认) 不生效
|
|
5821
6219
|
*/
|
|
5822
|
-
attributes:
|
|
6220
|
+
attributes: undefined,
|
|
5823
6221
|
/**
|
|
5824
6222
|
* 一个用于声明哪些属性名会被监听的数组。如果不声明该属性,所有属性的变化都将触发通知
|
|
5825
6223
|
*/
|
|
5826
|
-
attributeFilter:
|
|
6224
|
+
attributeFilter: undefined,
|
|
5827
6225
|
/**
|
|
5828
6226
|
* + true 记录上一次被监听的节点的属性变化;可查阅 MutationObserver 中的 Monitoring attribute values 了解关于观察属性变化和属性值记录的详情
|
|
5829
6227
|
* + false (默认) 不生效
|
|
5830
6228
|
*/
|
|
5831
|
-
attributeOldValue:
|
|
6229
|
+
attributeOldValue: undefined,
|
|
5832
6230
|
/**
|
|
5833
6231
|
* + true 监听声明的 target 节点上所有字符的变化。默认值为 true,如果声明了 characterDataOldValue
|
|
5834
6232
|
* + false (默认) 不生效
|
|
5835
6233
|
*/
|
|
5836
|
-
characterData:
|
|
6234
|
+
characterData: undefined,
|
|
5837
6235
|
/**
|
|
5838
6236
|
* + true 记录前一个被监听的节点中发生的文本变化
|
|
5839
6237
|
* + false (默认) 不生效
|
|
5840
6238
|
*/
|
|
5841
|
-
characterDataOldValue:
|
|
6239
|
+
characterDataOldValue: undefined,
|
|
5842
6240
|
},
|
|
5843
6241
|
immediate: false,
|
|
5844
6242
|
};
|
|
@@ -6413,7 +6811,7 @@ class Utils {
|
|
|
6413
6811
|
}
|
|
6414
6812
|
return new Promise((resolve) => {
|
|
6415
6813
|
setTimeout(() => {
|
|
6416
|
-
resolve(
|
|
6814
|
+
resolve(undefined);
|
|
6417
6815
|
}, delayTime);
|
|
6418
6816
|
});
|
|
6419
6817
|
}
|
|
@@ -6788,7 +7186,7 @@ class Utils {
|
|
|
6788
7186
|
}
|
|
6789
7187
|
waitNode(...args) {
|
|
6790
7188
|
// 过滤掉undefined
|
|
6791
|
-
args = args.filter((arg) => arg !==
|
|
7189
|
+
args = args.filter((arg) => arg !== undefined);
|
|
6792
7190
|
let UtilsContext = this;
|
|
6793
7191
|
// 选择器
|
|
6794
7192
|
let selector = args[0];
|
|
@@ -6877,7 +7275,7 @@ class Utils {
|
|
|
6877
7275
|
}
|
|
6878
7276
|
waitAnyNode(...args) {
|
|
6879
7277
|
// 过滤掉undefined
|
|
6880
|
-
args = args.filter((arg) => arg !==
|
|
7278
|
+
args = args.filter((arg) => arg !== undefined);
|
|
6881
7279
|
let UtilsContext = this;
|
|
6882
7280
|
// 选择器
|
|
6883
7281
|
let selectorList = args[0];
|
|
@@ -6933,7 +7331,7 @@ class Utils {
|
|
|
6933
7331
|
}
|
|
6934
7332
|
waitNodeList(...args) {
|
|
6935
7333
|
// 过滤掉undefined
|
|
6936
|
-
args = args.filter((arg) => arg !==
|
|
7334
|
+
args = args.filter((arg) => arg !== undefined);
|
|
6937
7335
|
let UtilsContext = this;
|
|
6938
7336
|
// 选择器数组
|
|
6939
7337
|
let selector = args[0];
|
|
@@ -7020,7 +7418,7 @@ class Utils {
|
|
|
7020
7418
|
}
|
|
7021
7419
|
waitAnyNodeList(...args) {
|
|
7022
7420
|
// 过滤掉undefined
|
|
7023
|
-
args = args.filter((arg) => arg !==
|
|
7421
|
+
args = args.filter((arg) => arg !== undefined);
|
|
7024
7422
|
let UtilsContext = this;
|
|
7025
7423
|
// 选择器数组
|
|
7026
7424
|
let selectorList = args[0];
|
|
@@ -7318,6 +7716,7 @@ class Utils {
|
|
|
7318
7716
|
* > "测试"
|
|
7319
7717
|
*/
|
|
7320
7718
|
Vue = Vue;
|
|
7719
|
+
ModuleRaid = ModuleRaid;
|
|
7321
7720
|
}
|
|
7322
7721
|
let utils = new Utils();
|
|
7323
7722
|
|