@whitesev/utils 2.2.1 → 2.2.2
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 +142 -40
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +142 -40
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +142 -40
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +142 -40
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +142 -40
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +142 -40
- package/dist/index.umd.js.map +1 -1
- package/dist/types/src/Httpx.d.ts +23 -13
- package/dist/types/src/Utils.d.ts +1 -1
- package/package.json +1 -1
- package/src/Httpx.ts +239 -104
- package/src/Utils.ts +7 -1
package/dist/index.umd.js
CHANGED
|
@@ -2176,11 +2176,11 @@
|
|
|
2176
2176
|
}
|
|
2177
2177
|
if (details.fetch) {
|
|
2178
2178
|
const { fetchDetails, fetchRequestInit, abortController } = this.context.HttpxRequestDetails.handleFetchDetail(details);
|
|
2179
|
-
this.fetch(fetchDetails, fetchRequestInit, abortController);
|
|
2179
|
+
return this.fetch(fetchDetails, fetchRequestInit, abortController);
|
|
2180
2180
|
}
|
|
2181
2181
|
else {
|
|
2182
2182
|
Reflect.deleteProperty(details, "fetchInit");
|
|
2183
|
-
this.xmlHttpRequest(details);
|
|
2183
|
+
return this.xmlHttpRequest(details);
|
|
2184
2184
|
}
|
|
2185
2185
|
},
|
|
2186
2186
|
/**
|
|
@@ -2188,7 +2188,7 @@
|
|
|
2188
2188
|
* @param details
|
|
2189
2189
|
*/
|
|
2190
2190
|
xmlHttpRequest(details) {
|
|
2191
|
-
this.context.GM_Api.xmlHttpRequest(details);
|
|
2191
|
+
return this.context.GM_Api.xmlHttpRequest(details);
|
|
2192
2192
|
},
|
|
2193
2193
|
/**
|
|
2194
2194
|
* 使用fetch发送请求
|
|
@@ -2339,6 +2339,10 @@
|
|
|
2339
2339
|
* 当前使用请求时,输出请求的配置
|
|
2340
2340
|
*/
|
|
2341
2341
|
#LOG_DETAILS = false;
|
|
2342
|
+
/**
|
|
2343
|
+
* 实例化,可传入GM_xmlhttpRequest,未传入则使用window.fetch
|
|
2344
|
+
* @param __xmlHttpRequest__
|
|
2345
|
+
*/
|
|
2342
2346
|
constructor(__xmlHttpRequest__) {
|
|
2343
2347
|
if (typeof __xmlHttpRequest__ !== "function") {
|
|
2344
2348
|
console.warn("Httpx未传入GM_xmlhttpRequest函数或传入的GM_xmlhttpRequest不是Function,强制使用window.fetch");
|
|
@@ -2434,79 +2438,177 @@
|
|
|
2434
2438
|
}
|
|
2435
2439
|
/**
|
|
2436
2440
|
* GET 请求
|
|
2441
|
+
* @param url 网址
|
|
2442
|
+
* @param details 配置
|
|
2437
2443
|
*/
|
|
2438
|
-
async get(...args
|
|
2439
|
-
|
|
2444
|
+
async get(...args // @ts-ignore
|
|
2445
|
+
) {
|
|
2440
2446
|
let details = this.HttpxRequestDetails.handleBeforeRequestDetails(...args);
|
|
2441
|
-
|
|
2442
|
-
|
|
2447
|
+
let abortFn = null;
|
|
2448
|
+
const promise = new Promise((resolve, reject) => {
|
|
2449
|
+
let requestDetails = this.HttpxRequestDetails.getDetails("GET", details, resolve, reject);
|
|
2443
2450
|
Reflect.deleteProperty(requestDetails, "onprogress");
|
|
2444
|
-
|
|
2445
|
-
|
|
2451
|
+
// @ts-ignore
|
|
2452
|
+
requestDetails = this.HttpxRequestDetails.handle(requestDetails);
|
|
2453
|
+
const requestResult = this.HttpxRequest.request(requestDetails);
|
|
2454
|
+
if (requestResult != null &&
|
|
2455
|
+
typeof requestResult.abort === "function") {
|
|
2456
|
+
abortFn = requestResult.abort;
|
|
2457
|
+
}
|
|
2446
2458
|
});
|
|
2459
|
+
Object.defineProperty(promise, "abort", {
|
|
2460
|
+
value: () => {
|
|
2461
|
+
return () => {
|
|
2462
|
+
if (typeof abortFn === "function") {
|
|
2463
|
+
abortFn();
|
|
2464
|
+
}
|
|
2465
|
+
};
|
|
2466
|
+
},
|
|
2467
|
+
});
|
|
2468
|
+
return promise;
|
|
2447
2469
|
}
|
|
2448
2470
|
/**
|
|
2449
2471
|
* POST 请求
|
|
2450
2472
|
*/
|
|
2451
|
-
async post(...args
|
|
2452
|
-
|
|
2473
|
+
async post(...args // @ts-ignore
|
|
2474
|
+
) {
|
|
2453
2475
|
let details = this.HttpxRequestDetails.handleBeforeRequestDetails(...args);
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
requestDetails =
|
|
2457
|
-
|
|
2476
|
+
let abortFn = null;
|
|
2477
|
+
const promise = new Promise((resolve, reject) => {
|
|
2478
|
+
let requestDetails = this.HttpxRequestDetails.getDetails("POST", details, resolve, reject);
|
|
2479
|
+
// @ts-ignore
|
|
2480
|
+
requestDetails = this.HttpxRequestDetails.handle(requestDetails);
|
|
2481
|
+
const requestResult = this.HttpxRequest.request(requestDetails);
|
|
2482
|
+
if (requestResult != null &&
|
|
2483
|
+
typeof requestResult.abort === "function") {
|
|
2484
|
+
abortFn = requestResult.abort;
|
|
2485
|
+
}
|
|
2486
|
+
});
|
|
2487
|
+
Object.defineProperty(promise, "abort", {
|
|
2488
|
+
value: () => {
|
|
2489
|
+
return () => {
|
|
2490
|
+
if (typeof abortFn === "function") {
|
|
2491
|
+
abortFn();
|
|
2492
|
+
}
|
|
2493
|
+
};
|
|
2494
|
+
},
|
|
2458
2495
|
});
|
|
2496
|
+
return promise;
|
|
2459
2497
|
}
|
|
2460
2498
|
/**
|
|
2461
2499
|
* HEAD 请求
|
|
2462
2500
|
*/
|
|
2463
|
-
async head(...args
|
|
2464
|
-
|
|
2501
|
+
async head(...args // @ts-ignore
|
|
2502
|
+
) {
|
|
2465
2503
|
let details = this.HttpxRequestDetails.handleBeforeRequestDetails(...args);
|
|
2466
|
-
|
|
2467
|
-
|
|
2504
|
+
let abortFn = null;
|
|
2505
|
+
const promise = new Promise((resolve, reject) => {
|
|
2506
|
+
let requestDetails = this.HttpxRequestDetails.getDetails("HEAD", details, resolve, reject);
|
|
2468
2507
|
Reflect.deleteProperty(requestDetails, "onprogress");
|
|
2469
|
-
|
|
2470
|
-
|
|
2508
|
+
// @ts-ignore
|
|
2509
|
+
requestDetails = this.HttpxRequestDetails.handle(requestDetails);
|
|
2510
|
+
const requestResult = this.HttpxRequest.request(requestDetails);
|
|
2511
|
+
if (requestResult != null &&
|
|
2512
|
+
typeof requestResult.abort === "function") {
|
|
2513
|
+
abortFn = requestResult.abort;
|
|
2514
|
+
}
|
|
2515
|
+
});
|
|
2516
|
+
Object.defineProperty(promise, "abort", {
|
|
2517
|
+
value: () => {
|
|
2518
|
+
return () => {
|
|
2519
|
+
if (typeof abortFn === "function") {
|
|
2520
|
+
abortFn();
|
|
2521
|
+
}
|
|
2522
|
+
};
|
|
2523
|
+
},
|
|
2471
2524
|
});
|
|
2525
|
+
return promise;
|
|
2472
2526
|
}
|
|
2473
2527
|
/**
|
|
2474
2528
|
* OPTIONS 请求
|
|
2475
2529
|
*/
|
|
2476
|
-
async options(...args
|
|
2477
|
-
|
|
2530
|
+
async options(...args // @ts-ignore
|
|
2531
|
+
) {
|
|
2478
2532
|
let details = this.HttpxRequestDetails.handleBeforeRequestDetails(...args);
|
|
2479
|
-
|
|
2480
|
-
|
|
2533
|
+
let abortFn = null;
|
|
2534
|
+
const promise = new Promise((resolve, reject) => {
|
|
2535
|
+
let requestDetails = this.HttpxRequestDetails.getDetails("OPTIONS", details, resolve, reject);
|
|
2481
2536
|
Reflect.deleteProperty(requestDetails, "onprogress");
|
|
2482
|
-
|
|
2483
|
-
|
|
2537
|
+
// @ts-ignore
|
|
2538
|
+
requestDetails = this.HttpxRequestDetails.handle(requestDetails);
|
|
2539
|
+
const requestResult = this.HttpxRequest.request(requestDetails);
|
|
2540
|
+
if (requestResult != null &&
|
|
2541
|
+
typeof requestResult.abort === "function") {
|
|
2542
|
+
abortFn = requestResult.abort;
|
|
2543
|
+
}
|
|
2484
2544
|
});
|
|
2545
|
+
Object.defineProperty(promise, "abort", {
|
|
2546
|
+
value: () => {
|
|
2547
|
+
return () => {
|
|
2548
|
+
if (typeof abortFn === "function") {
|
|
2549
|
+
abortFn();
|
|
2550
|
+
}
|
|
2551
|
+
};
|
|
2552
|
+
},
|
|
2553
|
+
});
|
|
2554
|
+
return promise;
|
|
2485
2555
|
}
|
|
2486
2556
|
/**
|
|
2487
2557
|
* DELETE 请求
|
|
2488
2558
|
*/
|
|
2489
|
-
async delete(...args
|
|
2490
|
-
|
|
2559
|
+
async delete(...args // @ts-ignore
|
|
2560
|
+
) {
|
|
2491
2561
|
let details = this.HttpxRequestDetails.handleBeforeRequestDetails(...args);
|
|
2492
|
-
|
|
2493
|
-
|
|
2562
|
+
let abortFn = null;
|
|
2563
|
+
const promise = new Promise((resolve, reject) => {
|
|
2564
|
+
let requestDetails = this.HttpxRequestDetails.getDetails("DELETE", details, resolve, reject);
|
|
2494
2565
|
Reflect.deleteProperty(requestDetails, "onprogress");
|
|
2495
|
-
|
|
2496
|
-
|
|
2566
|
+
// @ts-ignore
|
|
2567
|
+
requestDetails = this.HttpxRequestDetails.handle(requestDetails);
|
|
2568
|
+
const requestResult = this.HttpxRequest.request(requestDetails);
|
|
2569
|
+
if (requestResult != null &&
|
|
2570
|
+
typeof requestResult.abort === "function") {
|
|
2571
|
+
abortFn = requestResult.abort;
|
|
2572
|
+
}
|
|
2497
2573
|
});
|
|
2574
|
+
Object.defineProperty(promise, "abort", {
|
|
2575
|
+
value: () => {
|
|
2576
|
+
return () => {
|
|
2577
|
+
if (typeof abortFn === "function") {
|
|
2578
|
+
abortFn();
|
|
2579
|
+
}
|
|
2580
|
+
};
|
|
2581
|
+
},
|
|
2582
|
+
});
|
|
2583
|
+
return promise;
|
|
2498
2584
|
}
|
|
2499
2585
|
/**
|
|
2500
2586
|
* PUT 请求
|
|
2501
2587
|
*/
|
|
2502
|
-
async put(...args
|
|
2503
|
-
|
|
2588
|
+
async put(...args // @ts-ignore
|
|
2589
|
+
) {
|
|
2504
2590
|
let details = this.HttpxRequestDetails.handleBeforeRequestDetails(...args);
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
requestDetails =
|
|
2508
|
-
|
|
2591
|
+
let abortFn = null;
|
|
2592
|
+
const promise = new Promise((resolve, reject) => {
|
|
2593
|
+
let requestDetails = this.HttpxRequestDetails.getDetails("PUT", details, resolve, reject);
|
|
2594
|
+
// @ts-ignore
|
|
2595
|
+
requestDetails = this.HttpxRequestDetails.handle(requestDetails);
|
|
2596
|
+
const requestResult = this.HttpxRequest.request(requestDetails);
|
|
2597
|
+
if (requestResult != null &&
|
|
2598
|
+
typeof requestResult.abort === "function") {
|
|
2599
|
+
abortFn = requestResult.abort;
|
|
2600
|
+
}
|
|
2601
|
+
});
|
|
2602
|
+
Object.defineProperty(promise, "abort", {
|
|
2603
|
+
value: () => {
|
|
2604
|
+
return () => {
|
|
2605
|
+
if (typeof abortFn === "function") {
|
|
2606
|
+
abortFn();
|
|
2607
|
+
}
|
|
2608
|
+
};
|
|
2609
|
+
},
|
|
2509
2610
|
});
|
|
2611
|
+
return promise;
|
|
2510
2612
|
}
|
|
2511
2613
|
}
|
|
2512
2614
|
|
|
@@ -3555,7 +3657,7 @@
|
|
|
3555
3657
|
this.windowApi = new WindowApi(option);
|
|
3556
3658
|
}
|
|
3557
3659
|
/** 版本号 */
|
|
3558
|
-
version = "2024.9.
|
|
3660
|
+
version = "2024.9.4";
|
|
3559
3661
|
addStyle(cssText) {
|
|
3560
3662
|
if (typeof cssText !== "string") {
|
|
3561
3663
|
throw new Error("Utils.addStyle 参数cssText 必须为String类型");
|