@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.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 = void 0;
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: void 0,
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: void 0,
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: void 0,
2421
+ response: undefined,
2422
2422
  responseFetchHeaders: fetchResponse.headers,
2423
2423
  responseHeaders: "",
2424
2424
  // @ts-ignore
2425
- responseText: void 0,
2425
+ responseText: undefined,
2426
2426
  responseType: option.responseType,
2427
- responseXML: void 0,
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: void 0,
2539
+ url: undefined,
2540
2540
  timeout: 5000,
2541
2541
  async: false,
2542
- responseType: void 0,
2543
- headers: void 0,
2544
- data: void 0,
2545
- redirect: void 0,
2546
- cookie: void 0,
2547
- cookiePartition: void 0,
2548
- binary: void 0,
2549
- nocache: void 0,
2550
- revalidate: void 0,
2551
- context: void 0,
2552
- overrideMimeType: void 0,
2553
- anonymous: void 0,
2554
- fetch: void 0,
2555
- fetchInit: void 0,
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: void 0,
2562
- password: void 0,
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: void 0,
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 : void 0;
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: void 0,
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 !== void 0 ? result : TryCatchCore;
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 = void 0;
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 = void 0;
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 === void 0) {
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,859 @@
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
+
4540
+ // ==UserScript==
4541
+ // @name ajaxHooker
4542
+ // @author cxxjackie
4543
+ // @version 1.2.4
4544
+ // @supportURL https://bbs.tampermonkey.net.cn/thread-3284-1-1.html
4545
+ // ==/UserScript==
4546
+
4547
+ const AjaxHooker1_2_4 = function () {
4548
+ return (function () {
4549
+ const win = window.unsafeWindow || document.defaultView || window;
4550
+ const hookFns = [];
4551
+ const realXhr = win.XMLHttpRequest;
4552
+ const resProto = win.Response.prototype;
4553
+ const toString = Object.prototype.toString;
4554
+ const realFetch = win.fetch;
4555
+ const xhrResponses = ["response", "responseText", "responseXML"];
4556
+ const fetchResponses = ["arrayBuffer", "blob", "formData", "json", "text"];
4557
+ const xhrAsyncEvents = ["readystatechange", "load", "loadend"];
4558
+ let filter;
4559
+ function emptyFn() {}
4560
+ function errorFn(err) {
4561
+ console.error(err);
4562
+ }
4563
+ function defineProp(obj, prop, getter, setter) {
4564
+ Object.defineProperty(obj, prop, {
4565
+ configurable: true,
4566
+ enumerable: true,
4567
+ get: getter,
4568
+ set: setter,
4569
+ });
4570
+ }
4571
+ function readonly(obj, prop, value = obj[prop]) {
4572
+ defineProp(obj, prop, () => value, emptyFn);
4573
+ }
4574
+ function writable(obj, prop, value = obj[prop]) {
4575
+ Object.defineProperty(obj, prop, {
4576
+ configurable: true,
4577
+ enumerable: true,
4578
+ writable: true,
4579
+ value: value,
4580
+ });
4581
+ }
4582
+ function toFilterObj(obj) {
4583
+ return {
4584
+ type: obj.type,
4585
+ url: obj.url,
4586
+ method: obj.method && obj.method.toUpperCase(),
4587
+ };
4588
+ }
4589
+ function shouldFilter(type, url, method) {
4590
+ return (
4591
+ filter &&
4592
+ !filter.find(
4593
+ (obj) =>
4594
+ (!obj.type || obj.type === type) &&
4595
+ (!obj.url ||
4596
+ (toString.call(obj.url) === "[object String]"
4597
+ ? url.includes(obj.url)
4598
+ : obj.url.test(url))) &&
4599
+ (!obj.method || obj.method === method.toUpperCase())
4600
+ )
4601
+ );
4602
+ }
4603
+ function lookupGetter(obj, prop) {
4604
+ let getter;
4605
+ let proto = obj;
4606
+ while (proto) {
4607
+ const descriptor = Object.getOwnPropertyDescriptor(proto, prop);
4608
+ getter = descriptor && descriptor.get;
4609
+ if (getter) break;
4610
+ proto = Object.getPrototypeOf(proto);
4611
+ }
4612
+ return getter ? getter.bind(obj) : emptyFn;
4613
+ }
4614
+ function waitForHookFns(request) {
4615
+ return Promise.all(
4616
+ hookFns.map((fn) => Promise.resolve(fn(request)).then(emptyFn, errorFn))
4617
+ );
4618
+ }
4619
+ function waitForRequestKeys(request, requestClone) {
4620
+ return Promise.all(
4621
+ ["url", "method", "abort", "headers", "data"].map((key) => {
4622
+ return Promise.resolve(request[key]).then(
4623
+ (val) => (request[key] = val),
4624
+ () => (request[key] = requestClone[key])
4625
+ );
4626
+ })
4627
+ );
4628
+ }
4629
+ function fakeEventSIP() {
4630
+ this.ajaxHooker_stopped = true;
4631
+ }
4632
+ function xhrDelegateEvent(e) {
4633
+ const xhr = e.target;
4634
+ e.stopImmediatePropagation = fakeEventSIP;
4635
+ xhr.__ajaxHooker.hookedEvents[e.type].forEach(
4636
+ (fn) => !e.ajaxHooker_stopped && fn.call(xhr, e)
4637
+ );
4638
+ const onEvent = xhr.__ajaxHooker.hookedEvents["on" + e.type];
4639
+ typeof onEvent === "function" && onEvent.call(xhr, e);
4640
+ }
4641
+ function xhrReadyStateChange(e) {
4642
+ if (e.target.readyState === 4) {
4643
+ e.target.dispatchEvent(
4644
+ new CustomEvent("ajaxHooker_responseReady", { detail: e })
4645
+ );
4646
+ } else {
4647
+ e.target.__ajaxHooker.delegateEvent(e);
4648
+ }
4649
+ }
4650
+ function xhrLoadAndLoadend(e) {
4651
+ e.target.__ajaxHooker.delegateEvent(e);
4652
+ }
4653
+ function fakeXhrOpen(method, url, ...args) {
4654
+ const ah = this.__ajaxHooker;
4655
+ ah.url = url.toString();
4656
+ ah.method = method.toUpperCase();
4657
+ ah.openArgs = args;
4658
+ ah.headers = {};
4659
+ return ah.originalMethods.open(method, url, ...args);
4660
+ }
4661
+ function fakeXhr() {
4662
+ const xhr = new realXhr();
4663
+ let ah = xhr.__ajaxHooker;
4664
+ if (!ah) {
4665
+ ah = xhr.__ajaxHooker = {
4666
+ headers: {},
4667
+ hookedEvents: {
4668
+ readystatechange: new Set(),
4669
+ load: new Set(),
4670
+ loadend: new Set(),
4671
+ },
4672
+ delegateEvent: xhrDelegateEvent,
4673
+ originalGetters: {},
4674
+ originalMethods: {},
4675
+ };
4676
+ xhr.addEventListener("readystatechange", xhrReadyStateChange);
4677
+ xhr.addEventListener("load", xhrLoadAndLoadend);
4678
+ xhr.addEventListener("loadend", xhrLoadAndLoadend);
4679
+ for (const key of xhrResponses) {
4680
+ ah.originalGetters[key] = lookupGetter(xhr, key);
4681
+ }
4682
+ for (const method of [
4683
+ "open",
4684
+ "setRequestHeader",
4685
+ "addEventListener",
4686
+ "removeEventListener",
4687
+ ]) {
4688
+ ah.originalMethods[method] = xhr[method].bind(xhr);
4689
+ }
4690
+ xhr.open = fakeXhrOpen;
4691
+ xhr.setRequestHeader = (header, value) => {
4692
+ ah.originalMethods.setRequestHeader(header, value);
4693
+ if (xhr.readyState === 1) {
4694
+ if (ah.headers[header]) {
4695
+ ah.headers[header] += ", " + value;
4696
+ } else {
4697
+ ah.headers[header] = value;
4698
+ }
4699
+ }
4700
+ };
4701
+ xhr.addEventListener = function (...args) {
4702
+ if (xhrAsyncEvents.includes(args[0])) {
4703
+ ah.hookedEvents[args[0]].add(args[1]);
4704
+ } else {
4705
+ ah.originalMethods.addEventListener(...args);
4706
+ }
4707
+ };
4708
+ xhr.removeEventListener = function (...args) {
4709
+ if (xhrAsyncEvents.includes(args[0])) {
4710
+ ah.hookedEvents[args[0]].delete(args[1]);
4711
+ } else {
4712
+ ah.originalMethods.removeEventListener(...args);
4713
+ }
4714
+ };
4715
+ xhrAsyncEvents.forEach((evt) => {
4716
+ const onEvt = "on" + evt;
4717
+ defineProp(
4718
+ xhr,
4719
+ onEvt,
4720
+ () => {
4721
+ return ah.hookedEvents[onEvt] || null;
4722
+ },
4723
+ (val) => {
4724
+ ah.hookedEvents[onEvt] = typeof val === "function" ? val : null;
4725
+ }
4726
+ );
4727
+ });
4728
+ }
4729
+ const realSend = xhr.send.bind(xhr);
4730
+ xhr.send = function (data) {
4731
+ if (xhr.readyState !== 1) return realSend(data);
4732
+ ah.delegateEvent = xhrDelegateEvent;
4733
+ xhrResponses.forEach((prop) => {
4734
+ delete xhr[prop]; // delete descriptor
4735
+ });
4736
+ if (shouldFilter("xhr", ah.url, ah.method)) {
4737
+ xhr.addEventListener("ajaxHooker_responseReady", (e) => {
4738
+ ah.delegateEvent(e.detail);
4739
+ });
4740
+ return realSend(data);
4741
+ }
4742
+ try {
4743
+ const request = {
4744
+ type: "xhr",
4745
+ url: ah.url,
4746
+ method: ah.method,
4747
+ abort: false,
4748
+ headers: ah.headers,
4749
+ data: data,
4750
+ response: null,
4751
+ };
4752
+ const requestClone = { ...request };
4753
+ waitForHookFns(request).then(() => {
4754
+ waitForRequestKeys(request, requestClone).then(() => {
4755
+ if (request.abort) return;
4756
+ ah.originalMethods.open(
4757
+ request.method,
4758
+ request.url,
4759
+ ...ah.openArgs
4760
+ );
4761
+ for (const header in request.headers) {
4762
+ ah.originalMethods.setRequestHeader(
4763
+ header,
4764
+ request.headers[header]
4765
+ );
4766
+ }
4767
+ data = request.data;
4768
+ xhr.addEventListener("ajaxHooker_responseReady", (e) => {
4769
+ try {
4770
+ if (typeof request.response === "function") {
4771
+ const arg = {
4772
+ finalUrl: xhr.responseURL,
4773
+ status: xhr.status,
4774
+ responseHeaders: {},
4775
+ };
4776
+ for (const line of xhr
4777
+ .getAllResponseHeaders()
4778
+ .trim()
4779
+ .split(/[\r\n]+/)) {
4780
+ const parts = line.split(/:\s*/);
4781
+ if (parts.length === 2) {
4782
+ const lheader = parts[0].toLowerCase();
4783
+ if (arg.responseHeaders[lheader]) {
4784
+ arg.responseHeaders[lheader] += ", " + parts[1];
4785
+ } else {
4786
+ arg.responseHeaders[lheader] = parts[1];
4787
+ }
4788
+ }
4789
+ }
4790
+ xhrResponses.forEach((prop) => {
4791
+ defineProp(
4792
+ arg,
4793
+ prop,
4794
+ () => {
4795
+ return (arg[prop] = ah.originalGetters[prop]());
4796
+ },
4797
+ (val) => {
4798
+ delete arg[prop];
4799
+ arg[prop] = val;
4800
+ }
4801
+ );
4802
+ defineProp(xhr, prop, () => {
4803
+ const val = ah.originalGetters[prop]();
4804
+ xhr.dispatchEvent(
4805
+ new CustomEvent("ajaxHooker_readResponse", {
4806
+ detail: { prop, val },
4807
+ })
4808
+ );
4809
+ return val;
4810
+ });
4811
+ });
4812
+ xhr.addEventListener("ajaxHooker_readResponse", (e) => {
4813
+ arg[e.detail.prop] = e.detail.val;
4814
+ });
4815
+ const resPromise = Promise.resolve(
4816
+ request.response(arg)
4817
+ ).then(() => {
4818
+ const task = [];
4819
+ xhrResponses.forEach((prop) => {
4820
+ const descriptor = Object.getOwnPropertyDescriptor(
4821
+ arg,
4822
+ prop
4823
+ );
4824
+ if (descriptor && "value" in descriptor) {
4825
+ task.push(
4826
+ Promise.resolve(descriptor.value).then((val) => {
4827
+ arg[prop] = val;
4828
+ defineProp(xhr, prop, () => {
4829
+ xhr.dispatchEvent(
4830
+ new CustomEvent("ajaxHooker_readResponse", {
4831
+ detail: { prop, val },
4832
+ })
4833
+ );
4834
+ return val;
4835
+ });
4836
+ }, emptyFn)
4837
+ );
4838
+ }
4839
+ });
4840
+ return Promise.all(task);
4841
+ }, errorFn);
4842
+ const eventsClone = {};
4843
+ xhrAsyncEvents.forEach((type) => {
4844
+ eventsClone[type] = new Set([...ah.hookedEvents[type]]);
4845
+ eventsClone["on" + type] = ah.hookedEvents["on" + type];
4846
+ });
4847
+ ah.delegateEvent = (event) =>
4848
+ resPromise.then(() => {
4849
+ event.stopImmediatePropagation = fakeEventSIP;
4850
+ eventsClone[event.type].forEach(
4851
+ (fn) =>
4852
+ !event.ajaxHooker_stopped && fn.call(xhr, event)
4853
+ );
4854
+ const onEvent = eventsClone["on" + event.type];
4855
+ typeof onEvent === "function" &&
4856
+ onEvent.call(xhr, event);
4857
+ });
4858
+ }
4859
+ } catch (err) {
4860
+ console.error(err);
4861
+ }
4862
+ ah.delegateEvent(e.detail);
4863
+ });
4864
+ realSend(data);
4865
+ });
4866
+ });
4867
+ } catch (err) {
4868
+ console.error(err);
4869
+ realSend(data);
4870
+ }
4871
+ };
4872
+ return xhr;
4873
+ }
4874
+ function hookFetchResponse(response, arg, callback) {
4875
+ fetchResponses.forEach((prop) => {
4876
+ response[prop] = () =>
4877
+ new Promise((resolve, reject) => {
4878
+ resProto[prop].call(response).then((res) => {
4879
+ if (prop in arg) {
4880
+ resolve(arg[prop]);
4881
+ } else {
4882
+ try {
4883
+ arg[prop] = res;
4884
+ Promise.resolve(callback(arg)).then(() => {
4885
+ if (prop in arg) {
4886
+ Promise.resolve(arg[prop]).then(
4887
+ (val) => resolve((arg[prop] = val)),
4888
+ () => resolve(res)
4889
+ );
4890
+ } else {
4891
+ resolve(res);
4892
+ }
4893
+ }, errorFn);
4894
+ } catch (err) {
4895
+ console.error(err);
4896
+ resolve(res);
4897
+ }
4898
+ }
4899
+ }, reject);
4900
+ });
4901
+ });
4902
+ }
4903
+ function fakeFetch(url, init) {
4904
+ if (url && typeof url.toString === "function") {
4905
+ url = url.toString();
4906
+ init = init || {};
4907
+ init.method = init.method || "GET";
4908
+ init.headers = init.headers || {};
4909
+ if (shouldFilter("fetch", url, init.method))
4910
+ return realFetch.call(win, url, init);
4911
+ const request = {
4912
+ type: "fetch",
4913
+ url: url,
4914
+ method: init.method.toUpperCase(),
4915
+ abort: false,
4916
+ headers: {},
4917
+ data: init.body,
4918
+ response: null,
4919
+ };
4920
+ if (toString.call(init.headers) === "[object Headers]") {
4921
+ for (const [key, val] of init.headers) {
4922
+ request.headers[key] = val;
4923
+ }
4924
+ } else {
4925
+ request.headers = { ...init.headers };
4926
+ }
4927
+ const requestClone = { ...request };
4928
+ return new Promise((resolve, reject) => {
4929
+ try {
4930
+ waitForHookFns(request).then(() => {
4931
+ waitForRequestKeys(request, requestClone).then(() => {
4932
+ if (request.abort) return reject("aborted");
4933
+ url = request.url;
4934
+ init.method = request.method;
4935
+ init.headers = request.headers;
4936
+ init.body = request.data;
4937
+ realFetch.call(win, url, init).then((response) => {
4938
+ if (typeof request.response === "function") {
4939
+ const arg = {
4940
+ finalUrl: response.url,
4941
+ status: response.status,
4942
+ responseHeaders: {},
4943
+ };
4944
+ for (const [key, val] of response.headers) {
4945
+ arg.responseHeaders[key] = val;
4946
+ }
4947
+ hookFetchResponse(response, arg, request.response);
4948
+ response.clone = () => {
4949
+ const resClone = resProto.clone.call(response);
4950
+ hookFetchResponse(resClone, arg, request.response);
4951
+ return resClone;
4952
+ };
4953
+ }
4954
+ resolve(response);
4955
+ }, reject);
4956
+ });
4957
+ });
4958
+ } catch (err) {
4959
+ console.error(err);
4960
+ return realFetch.call(win, url, init);
4961
+ }
4962
+ });
4963
+ } else {
4964
+ return realFetch.call(win, url, init);
4965
+ }
4966
+ }
4967
+ win.XMLHttpRequest = fakeXhr;
4968
+ Object.keys(realXhr).forEach((key) => (fakeXhr[key] = realXhr[key]));
4969
+ fakeXhr.prototype = realXhr.prototype;
4970
+ win.fetch = fakeFetch;
4971
+ return {
4972
+ hook: (fn) => hookFns.push(fn),
4973
+ filter: (arr) => {
4974
+ filter = Array.isArray(arr) && arr.map(toFilterObj);
4975
+ },
4976
+ protect: () => {
4977
+ readonly(win, "XMLHttpRequest", fakeXhr);
4978
+ readonly(win, "fetch", fakeFetch);
4979
+ },
4980
+ unhook: () => {
4981
+ writable(win, "XMLHttpRequest", realXhr);
4982
+ writable(win, "fetch", realFetch);
4983
+ },
4984
+ };
4985
+ })();
4986
+ };
4987
+
4142
4988
  class Utils {
4143
4989
  windowApi;
4144
4990
  constructor(option) {
4145
4991
  this.windowApi = new WindowApi(option);
4146
4992
  }
4147
4993
  /** 版本号 */
4148
- version = "2025.1.1";
4994
+ version = "2025.1.11";
4149
4995
  addStyle(cssText) {
4150
4996
  if (typeof cssText !== "string") {
4151
4997
  throw new Error("Utils.addStyle 参数cssText 必须为String类型");
@@ -4265,10 +5111,18 @@
4265
5111
  * ajax劫持库,支持xhr和fetch劫持。
4266
5112
  * + 来源:https://bbs.tampermonkey.net.cn/thread-3284-1-1.html
4267
5113
  * + 作者:cxxjackie
4268
- * + 版本:1.4.1
5114
+ * + 版本:1.4.3
4269
5115
  * + 文档:https://scriptcat.org/zh-CN/script-show-page/637/
5116
+ * @param useOldVersion 是否使用旧版本,默认false
4270
5117
  */
4271
- ajaxHooker = AjaxHooker;
5118
+ ajaxHooker = (useOldVersion = false) => {
5119
+ if (useOldVersion) {
5120
+ return AjaxHooker1_2_4();
5121
+ }
5122
+ else {
5123
+ return AjaxHooker();
5124
+ }
5125
+ };
4272
5126
  canvasClickByPosition(canvasElement, clientX = 0, clientY = 0, view = globalThis) {
4273
5127
  if (!(canvasElement instanceof HTMLCanvasElement)) {
4274
5128
  throw new Error("Utils.canvasClickByPosition 参数canvasElement必须是canvas元素");
@@ -4368,8 +5222,8 @@
4368
5222
  ColorConversion = ColorConversion;
4369
5223
  deepClone(obj) {
4370
5224
  let UtilsContext = this;
4371
- if (obj === void 0)
4372
- return void 0;
5225
+ if (obj === undefined)
5226
+ return undefined;
4373
5227
  if (obj === null)
4374
5228
  return null;
4375
5229
  let clone = obj instanceof Array ? [] : {};
@@ -5815,36 +6669,36 @@
5815
6669
  * + true 监听以 target 为根节点的整个子树。包括子树中所有节点的属性,而不仅仅是针对 target
5816
6670
  * + false (默认) 不生效
5817
6671
  */
5818
- subtree: void 0,
6672
+ subtree: undefined,
5819
6673
  /**
5820
6674
  * + true 监听 target 节点中发生的节点的新增与删除(同时,如果 subtree 为 true,会针对整个子树生效)
5821
6675
  * + false (默认) 不生效
5822
6676
  */
5823
- childList: void 0,
6677
+ childList: undefined,
5824
6678
  /**
5825
6679
  * + true 观察所有监听的节点属性值的变化。默认值为 true,当声明了 attributeFilter 或 attributeOldValue
5826
6680
  * + false (默认) 不生效
5827
6681
  */
5828
- attributes: void 0,
6682
+ attributes: undefined,
5829
6683
  /**
5830
6684
  * 一个用于声明哪些属性名会被监听的数组。如果不声明该属性,所有属性的变化都将触发通知
5831
6685
  */
5832
- attributeFilter: void 0,
6686
+ attributeFilter: undefined,
5833
6687
  /**
5834
6688
  * + true 记录上一次被监听的节点的属性变化;可查阅 MutationObserver 中的 Monitoring attribute values 了解关于观察属性变化和属性值记录的详情
5835
6689
  * + false (默认) 不生效
5836
6690
  */
5837
- attributeOldValue: void 0,
6691
+ attributeOldValue: undefined,
5838
6692
  /**
5839
6693
  * + true 监听声明的 target 节点上所有字符的变化。默认值为 true,如果声明了 characterDataOldValue
5840
6694
  * + false (默认) 不生效
5841
6695
  */
5842
- characterData: void 0,
6696
+ characterData: undefined,
5843
6697
  /**
5844
6698
  * + true 记录前一个被监听的节点中发生的文本变化
5845
6699
  * + false (默认) 不生效
5846
6700
  */
5847
- characterDataOldValue: void 0,
6701
+ characterDataOldValue: undefined,
5848
6702
  },
5849
6703
  immediate: false,
5850
6704
  };
@@ -6419,7 +7273,7 @@
6419
7273
  }
6420
7274
  return new Promise((resolve) => {
6421
7275
  setTimeout(() => {
6422
- resolve(void 0);
7276
+ resolve(undefined);
6423
7277
  }, delayTime);
6424
7278
  });
6425
7279
  }
@@ -6794,7 +7648,7 @@
6794
7648
  }
6795
7649
  waitNode(...args) {
6796
7650
  // 过滤掉undefined
6797
- args = args.filter((arg) => arg !== void 0);
7651
+ args = args.filter((arg) => arg !== undefined);
6798
7652
  let UtilsContext = this;
6799
7653
  // 选择器
6800
7654
  let selector = args[0];
@@ -6883,7 +7737,7 @@
6883
7737
  }
6884
7738
  waitAnyNode(...args) {
6885
7739
  // 过滤掉undefined
6886
- args = args.filter((arg) => arg !== void 0);
7740
+ args = args.filter((arg) => arg !== undefined);
6887
7741
  let UtilsContext = this;
6888
7742
  // 选择器
6889
7743
  let selectorList = args[0];
@@ -6939,7 +7793,7 @@
6939
7793
  }
6940
7794
  waitNodeList(...args) {
6941
7795
  // 过滤掉undefined
6942
- args = args.filter((arg) => arg !== void 0);
7796
+ args = args.filter((arg) => arg !== undefined);
6943
7797
  let UtilsContext = this;
6944
7798
  // 选择器数组
6945
7799
  let selector = args[0];
@@ -7026,7 +7880,7 @@
7026
7880
  }
7027
7881
  waitAnyNodeList(...args) {
7028
7882
  // 过滤掉undefined
7029
- args = args.filter((arg) => arg !== void 0);
7883
+ args = args.filter((arg) => arg !== undefined);
7030
7884
  let UtilsContext = this;
7031
7885
  // 选择器数组
7032
7886
  let selectorList = args[0];
@@ -7324,6 +8178,7 @@
7324
8178
  * > "测试"
7325
8179
  */
7326
8180
  Vue = Vue;
8181
+ ModuleRaid = ModuleRaid;
7327
8182
  }
7328
8183
  let utils = new Utils();
7329
8184