@whitesev/utils 2.3.2 → 2.3.3

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.
@@ -949,6 +949,26 @@ export declare interface HttpxDetails {
949
949
  * 自定义Cookie,可为空
950
950
  */
951
951
  cookie?: string;
952
+ /**
953
+ * TamperMonkey5.2+
954
+ *
955
+ * @link https://developer.mozilla.org/zh-CN/docs/Mozilla/Add-ons/WebExtensions/API/cookies#storage_partitioning
956
+ */
957
+ cookiePartition?: {
958
+ /**
959
+ * 设置顶级站点
960
+ *
961
+ * @example
962
+ * http://*.example.com/
963
+ *
964
+ * @example
965
+ * http://www.example.com/
966
+ *
967
+ * @example
968
+ * *://*.example.com/
969
+ */
970
+ topLevelSite?: string;
971
+ };
952
972
  /**
953
973
  * 以二进制模式发送数据字符串,可为空
954
974
  */
@@ -1206,68 +1226,98 @@ declare class Httpx {
1206
1226
  /**
1207
1227
  * GET 请求
1208
1228
  * @param url 网址
1229
+ */
1230
+ get(url: string): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
1231
+ /**
1232
+ * GET 请求
1209
1233
  * @param details 配置
1210
1234
  */
1211
- get<T extends HttpxDetails>(url: string, details?: T): HttpxPromise<HttpxAsyncResult<T>>;
1235
+ get(details: HttpxDetails): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
1212
1236
  /**
1213
1237
  * GET 请求
1238
+ * @param url 网址
1214
1239
  * @param details 配置
1215
1240
  */
1216
- get<T extends HttpxDetails>(details: T): HttpxPromise<HttpxAsyncResult<T>>;
1241
+ get(url: string, details: HttpxDetails): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
1217
1242
  /**
1218
1243
  * POST 请求
1219
1244
  * @param details 配置
1220
1245
  */
1221
- post<T extends HttpxDetails>(details: T): HttpxPromise<HttpxAsyncResult<T>>;
1246
+ post(details: HttpxDetails): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
1247
+ /**
1248
+ * POST 请求
1249
+ * @param url 网址
1250
+ */
1251
+ post(url: string): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
1222
1252
  /**
1223
1253
  * POST 请求
1224
1254
  * @param url 网址
1225
1255
  * @param details 配置
1226
1256
  */
1227
- post<T extends HttpxDetails>(url: string, details?: T): HttpxPromise<HttpxAsyncResult<T>>;
1257
+ post(url: string, details: HttpxDetails): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
1228
1258
  /**
1229
1259
  * HEAD 请求
1230
1260
  * @param details 配置
1231
1261
  */
1232
- head<T extends HttpxDetails>(details: T): HttpxPromise<HttpxAsyncResult<T>>;
1262
+ head(details: HttpxDetails): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
1263
+ /**
1264
+ * HEAD 请求
1265
+ * @param url 网址
1266
+ */
1267
+ head(url: string): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
1233
1268
  /**
1234
1269
  * HEAD 请求
1235
1270
  * @param url 网址
1236
1271
  * @param details 配置
1237
1272
  */
1238
- head<T extends HttpxDetails>(url: string, details?: T): HttpxPromise<HttpxAsyncResult<T>>;
1273
+ head(url: string, details: HttpxDetails): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
1239
1274
  /**
1240
1275
  * OPTIONS 请求
1241
1276
  * @param details 配置
1242
1277
  */
1243
- options<T extends HttpxDetails>(details: T): HttpxPromise<HttpxAsyncResult<T>>;
1278
+ options(details: HttpxDetails): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
1279
+ /**
1280
+ * OPTIONS 请求
1281
+ * @param url 网址
1282
+ */
1283
+ options(url: string): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
1244
1284
  /**
1245
1285
  * OPTIONS 请求
1246
1286
  * @param url 网址
1247
1287
  * @param details 配置
1248
1288
  */
1249
- options<T extends HttpxDetails>(url: string, details?: T): HttpxPromise<HttpxAsyncResult<T>>;
1289
+ options(url: string, details: HttpxDetails): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
1250
1290
  /**
1251
1291
  * DELETE 请求
1252
1292
  * @param details 配置
1253
1293
  */
1254
- delete<T extends HttpxDetails>(details: T): HttpxPromise<HttpxAsyncResult<T>>;
1294
+ delete(details: HttpxDetails): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
1295
+ /**
1296
+ * DELETE 请求
1297
+ * @param url 网址
1298
+ */
1299
+ delete(url: string): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
1255
1300
  /**
1256
1301
  * DELETE 请求
1257
1302
  * @param url 网址
1258
1303
  * @param details 配置
1259
1304
  */
1260
- delete<T extends HttpxDetails>(url: string, details?: T): HttpxPromise<HttpxAsyncResult<T>>;
1305
+ delete(url: string, details: HttpxDetails): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
1261
1306
  /**
1262
1307
  * PUT 请求
1263
1308
  * @param details 配置
1264
1309
  */
1265
- put<T extends HttpxDetails>(details: T): HttpxPromise<HttpxAsyncResult<T>>;
1310
+ put(details: HttpxDetails): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
1311
+ /**
1312
+ * PUT 请求
1313
+ * @param url 网址
1314
+ */
1315
+ put(url: string): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
1266
1316
  /**
1267
1317
  * PUT 请求
1268
1318
  * @param url 网址
1269
1319
  * @param details 配置
1270
1320
  */
1271
- put<T extends HttpxDetails>(url: string, details?: T): HttpxPromise<HttpxAsyncResult<T>>;
1321
+ put(url: string, details: HttpxDetails): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
1272
1322
  }
1273
1323
  export { Httpx };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whitesev/utils",
3
- "version": "2.3.2",
3
+ "version": "2.3.3",
4
4
  "description": "一个常用的工具库",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.js",
package/src/Httpx.ts CHANGED
@@ -1047,6 +1047,26 @@ export declare interface HttpxDetails {
1047
1047
  * 自定义Cookie,可为空
1048
1048
  */
1049
1049
  cookie?: string;
1050
+ /**
1051
+ * TamperMonkey5.2+
1052
+ *
1053
+ * @link https://developer.mozilla.org/zh-CN/docs/Mozilla/Add-ons/WebExtensions/API/cookies#storage_partitioning
1054
+ */
1055
+ cookiePartition?: {
1056
+ /**
1057
+ * 设置顶级站点
1058
+ *
1059
+ * @example
1060
+ * http://*.example.com/
1061
+ *
1062
+ * @example
1063
+ * http://www.example.com/
1064
+ *
1065
+ * @example
1066
+ * *://*.example.com/
1067
+ */
1068
+ topLevelSite?: string;
1069
+ };
1050
1070
  /**
1051
1071
  * 以二进制模式发送数据字符串,可为空
1052
1072
  */
@@ -1509,6 +1529,9 @@ class Httpx {
1509
1529
  data: details.data || this.context.#defaultDetails.data,
1510
1530
  redirect: details.redirect || this.context.#defaultDetails.redirect,
1511
1531
  cookie: details.cookie || this.context.#defaultDetails.cookie,
1532
+ cookiePartition:
1533
+ details.cookiePartition ||
1534
+ this.context.#defaultDetails.cookiePartition,
1512
1535
  binary: details.binary || this.context.#defaultDetails.binary,
1513
1536
  nocache: details.nocache || this.context.#defaultDetails.nocache,
1514
1537
  revalidate:
@@ -1661,6 +1684,20 @@ class Httpx {
1661
1684
  } else {
1662
1685
  (result as any).fetchInit = details.fetchInit;
1663
1686
  }
1687
+
1688
+ // 处理新的cookiePartition
1689
+ if (
1690
+ typeof result.cookiePartition === "object" &&
1691
+ result.cookiePartition != null
1692
+ ) {
1693
+ if (
1694
+ Reflect.has(result.cookiePartition, "topLevelSite") &&
1695
+ typeof result.cookiePartition.topLevelSite !== "string"
1696
+ ) {
1697
+ // topLevelSite必须是字符串
1698
+ Reflect.deleteProperty(result.cookiePartition, "topLevelSite");
1699
+ }
1700
+ }
1664
1701
  return result;
1665
1702
  },
1666
1703
  /**
@@ -2220,6 +2257,7 @@ class Httpx {
2220
2257
  data: void 0,
2221
2258
  redirect: void 0,
2222
2259
  cookie: void 0,
2260
+ cookiePartition: void 0,
2223
2261
  binary: void 0,
2224
2262
  nocache: void 0,
2225
2263
  revalidate: void 0,
@@ -2362,26 +2400,33 @@ class Httpx {
2362
2400
  /**
2363
2401
  * GET 请求
2364
2402
  * @param url 网址
2403
+ */
2404
+ async get(
2405
+ url: string // @ts-ignore
2406
+ ): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
2407
+ /**
2408
+ * GET 请求
2365
2409
  * @param details 配置
2366
2410
  */
2367
- async get<T extends HttpxDetails>(
2368
- url: string,
2369
- details?: T // @ts-ignore
2370
- ): HttpxPromise<HttpxAsyncResult<T>>;
2411
+ async get(
2412
+ details: HttpxDetails // @ts-ignore
2413
+ ): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
2371
2414
  /**
2372
2415
  * GET 请求
2416
+ * @param url 网址
2373
2417
  * @param details 配置
2374
2418
  */
2375
- async get<T extends HttpxDetails>(
2376
- details: T // @ts-ignore
2377
- ): HttpxPromise<HttpxAsyncResult<T>>;
2419
+ async get(
2420
+ url: string,
2421
+ details: HttpxDetails // @ts-ignore
2422
+ ): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
2378
2423
  /**
2379
2424
  * GET 请求
2380
2425
  * @param url 网址
2381
2426
  * @param details 配置
2382
2427
  */
2383
2428
  async get(
2384
- ...args: (HttpxDetails | string)[] // @ts-ignore
2429
+ ...args: (string | HttpxDetails)[] // @ts-ignore
2385
2430
  ): HttpxPromise<HttpxAsyncResult<HttpxDetails>> {
2386
2431
  let details = this.HttpxRequestDetails.handleBeforeRequestDetails(...args);
2387
2432
  let abortFn: Function | null = null;
@@ -2420,18 +2465,24 @@ class Httpx {
2420
2465
  * POST 请求
2421
2466
  * @param details 配置
2422
2467
  */
2423
- async post<T extends HttpxDetails>(
2424
- details: T // @ts-ignore
2425
- ): HttpxPromise<HttpxAsyncResult<T>>;
2468
+ async post(
2469
+ details: HttpxDetails // @ts-ignore
2470
+ ): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
2471
+ /**
2472
+ * POST 请求
2473
+ * @param url 网址
2474
+ */
2475
+ // @ts-ignore
2476
+ async post(url: string): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
2426
2477
  /**
2427
2478
  * POST 请求
2428
2479
  * @param url 网址
2429
2480
  * @param details 配置
2430
2481
  */
2431
- async post<T extends HttpxDetails>(
2482
+ async post(
2432
2483
  url: string,
2433
- details?: T // @ts-ignore
2434
- ): HttpxPromise<HttpxAsyncResult<T>>;
2484
+ details: HttpxDetails // @ts-ignore
2485
+ ): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
2435
2486
  /**
2436
2487
  * POST 请求
2437
2488
  */
@@ -2474,18 +2525,25 @@ class Httpx {
2474
2525
  * HEAD 请求
2475
2526
  * @param details 配置
2476
2527
  */
2477
- async head<T extends HttpxDetails>(
2478
- details: T // @ts-ignore
2479
- ): HttpxPromise<HttpxAsyncResult<T>>;
2528
+ async head(
2529
+ details: HttpxDetails // @ts-ignore
2530
+ ): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
2531
+ /**
2532
+ * HEAD 请求
2533
+ * @param url 网址
2534
+ */
2535
+ async head(
2536
+ url: string // @ts-ignore
2537
+ ): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
2480
2538
  /**
2481
2539
  * HEAD 请求
2482
2540
  * @param url 网址
2483
2541
  * @param details 配置
2484
2542
  */
2485
- async head<T extends HttpxDetails>(
2543
+ async head(
2486
2544
  url: string,
2487
- details?: T // @ts-ignore
2488
- ): HttpxPromise<HttpxAsyncResult<T>>;
2545
+ details: HttpxDetails // @ts-ignore
2546
+ ): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
2489
2547
  /**
2490
2548
  * HEAD 请求
2491
2549
  */
@@ -2533,18 +2591,25 @@ class Httpx {
2533
2591
  * OPTIONS 请求
2534
2592
  * @param details 配置
2535
2593
  */
2536
- options<T extends HttpxDetails>(
2537
- details: T // @ts-ignore
2538
- ): HttpxPromise<HttpxAsyncResult<T>>;
2594
+ options(
2595
+ details: HttpxDetails // @ts-ignore
2596
+ ): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
2597
+ /**
2598
+ * OPTIONS 请求
2599
+ * @param url 网址
2600
+ */
2601
+ options(
2602
+ url: string // @ts-ignore
2603
+ ): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
2539
2604
  /**
2540
2605
  * OPTIONS 请求
2541
2606
  * @param url 网址
2542
2607
  * @param details 配置
2543
2608
  */
2544
- options<T extends HttpxDetails>(
2609
+ options(
2545
2610
  url: string,
2546
- details?: T // @ts-ignore
2547
- ): HttpxPromise<HttpxAsyncResult<T>>;
2611
+ details: HttpxDetails // @ts-ignore
2612
+ ): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
2548
2613
  /**
2549
2614
  * OPTIONS 请求
2550
2615
  */
@@ -2589,18 +2654,25 @@ class Httpx {
2589
2654
  * DELETE 请求
2590
2655
  * @param details 配置
2591
2656
  */
2592
- async delete<T extends HttpxDetails>(
2593
- details: T // @ts-ignore
2594
- ): HttpxPromise<HttpxAsyncResult<T>>;
2657
+ async delete(
2658
+ details: HttpxDetails // @ts-ignore
2659
+ ): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
2660
+ /**
2661
+ * DELETE 请求
2662
+ * @param url 网址
2663
+ */
2664
+ async delete(
2665
+ url: string // @ts-ignore
2666
+ ): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
2595
2667
  /**
2596
2668
  * DELETE 请求
2597
2669
  * @param url 网址
2598
2670
  * @param details 配置
2599
2671
  */
2600
- async delete<T extends HttpxDetails>(
2672
+ async delete(
2601
2673
  url: string,
2602
- details?: T // @ts-ignore
2603
- ): HttpxPromise<HttpxAsyncResult<T>>;
2674
+ details: HttpxDetails // @ts-ignore
2675
+ ): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
2604
2676
  /**
2605
2677
  * DELETE 请求
2606
2678
  */
@@ -2646,18 +2718,25 @@ class Httpx {
2646
2718
  * PUT 请求
2647
2719
  * @param details 配置
2648
2720
  */
2649
- async put<T extends HttpxDetails>(
2650
- details: T // @ts-ignore
2651
- ): HttpxPromise<HttpxAsyncResult<T>>;
2721
+ async put(
2722
+ details: HttpxDetails // @ts-ignore
2723
+ ): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
2724
+ /**
2725
+ * PUT 请求
2726
+ * @param url 网址
2727
+ */
2728
+ async put(
2729
+ url: string // @ts-ignore
2730
+ ): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
2652
2731
  /**
2653
2732
  * PUT 请求
2654
2733
  * @param url 网址
2655
2734
  * @param details 配置
2656
2735
  */
2657
- async put<T extends HttpxDetails>(
2736
+ async put(
2658
2737
  url: string,
2659
- details?: T // @ts-ignore
2660
- ): HttpxPromise<HttpxAsyncResult<T>>;
2738
+ details: HttpxDetails // @ts-ignore
2739
+ ): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
2661
2740
  /**
2662
2741
  * PUT 请求
2663
2742
  */
package/src/Utils.ts CHANGED
@@ -53,7 +53,7 @@ class Utils {
53
53
  this.windowApi = new WindowApi(option);
54
54
  }
55
55
  /** 版本号 */
56
- version = "2024.9.10";
56
+ version = "2024.9.28";
57
57
 
58
58
  /**
59
59
  * 在页面中增加style元素,如果html节点存在子节点,添加子节点第一个,反之,添加到html节点的子节点最后一个