@whitesev/utils 2.2.1 → 2.2.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.
- package/dist/index.amd.js +177 -40
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +177 -40
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +177 -40
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +177 -40
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +177 -40
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +177 -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 +8 -1
- package/package.json +1 -1
- package/src/Httpx.ts +239 -104
- package/src/Utils.ts +48 -1
package/dist/index.system.js
CHANGED
|
@@ -2175,11 +2175,11 @@ System.register('Utils', [], (function (exports) {
|
|
|
2175
2175
|
}
|
|
2176
2176
|
if (details.fetch) {
|
|
2177
2177
|
const { fetchDetails, fetchRequestInit, abortController } = this.context.HttpxRequestDetails.handleFetchDetail(details);
|
|
2178
|
-
this.fetch(fetchDetails, fetchRequestInit, abortController);
|
|
2178
|
+
return this.fetch(fetchDetails, fetchRequestInit, abortController);
|
|
2179
2179
|
}
|
|
2180
2180
|
else {
|
|
2181
2181
|
Reflect.deleteProperty(details, "fetchInit");
|
|
2182
|
-
this.xmlHttpRequest(details);
|
|
2182
|
+
return this.xmlHttpRequest(details);
|
|
2183
2183
|
}
|
|
2184
2184
|
},
|
|
2185
2185
|
/**
|
|
@@ -2187,7 +2187,7 @@ System.register('Utils', [], (function (exports) {
|
|
|
2187
2187
|
* @param details
|
|
2188
2188
|
*/
|
|
2189
2189
|
xmlHttpRequest(details) {
|
|
2190
|
-
this.context.GM_Api.xmlHttpRequest(details);
|
|
2190
|
+
return this.context.GM_Api.xmlHttpRequest(details);
|
|
2191
2191
|
},
|
|
2192
2192
|
/**
|
|
2193
2193
|
* 使用fetch发送请求
|
|
@@ -2338,6 +2338,10 @@ System.register('Utils', [], (function (exports) {
|
|
|
2338
2338
|
* 当前使用请求时,输出请求的配置
|
|
2339
2339
|
*/
|
|
2340
2340
|
#LOG_DETAILS = false;
|
|
2341
|
+
/**
|
|
2342
|
+
* 实例化,可传入GM_xmlhttpRequest,未传入则使用window.fetch
|
|
2343
|
+
* @param __xmlHttpRequest__
|
|
2344
|
+
*/
|
|
2341
2345
|
constructor(__xmlHttpRequest__) {
|
|
2342
2346
|
if (typeof __xmlHttpRequest__ !== "function") {
|
|
2343
2347
|
console.warn("Httpx未传入GM_xmlhttpRequest函数或传入的GM_xmlhttpRequest不是Function,强制使用window.fetch");
|
|
@@ -2433,79 +2437,177 @@ System.register('Utils', [], (function (exports) {
|
|
|
2433
2437
|
}
|
|
2434
2438
|
/**
|
|
2435
2439
|
* GET 请求
|
|
2440
|
+
* @param url 网址
|
|
2441
|
+
* @param details 配置
|
|
2436
2442
|
*/
|
|
2437
|
-
async get(...args
|
|
2438
|
-
|
|
2443
|
+
async get(...args // @ts-ignore
|
|
2444
|
+
) {
|
|
2439
2445
|
let details = this.HttpxRequestDetails.handleBeforeRequestDetails(...args);
|
|
2440
|
-
|
|
2441
|
-
|
|
2446
|
+
let abortFn = null;
|
|
2447
|
+
const promise = new Promise((resolve, reject) => {
|
|
2448
|
+
let requestDetails = this.HttpxRequestDetails.getDetails("GET", details, resolve, reject);
|
|
2442
2449
|
Reflect.deleteProperty(requestDetails, "onprogress");
|
|
2443
|
-
|
|
2444
|
-
|
|
2450
|
+
// @ts-ignore
|
|
2451
|
+
requestDetails = this.HttpxRequestDetails.handle(requestDetails);
|
|
2452
|
+
const requestResult = this.HttpxRequest.request(requestDetails);
|
|
2453
|
+
if (requestResult != null &&
|
|
2454
|
+
typeof requestResult.abort === "function") {
|
|
2455
|
+
abortFn = requestResult.abort;
|
|
2456
|
+
}
|
|
2445
2457
|
});
|
|
2458
|
+
Object.defineProperty(promise, "abort", {
|
|
2459
|
+
value: () => {
|
|
2460
|
+
return () => {
|
|
2461
|
+
if (typeof abortFn === "function") {
|
|
2462
|
+
abortFn();
|
|
2463
|
+
}
|
|
2464
|
+
};
|
|
2465
|
+
},
|
|
2466
|
+
});
|
|
2467
|
+
return promise;
|
|
2446
2468
|
}
|
|
2447
2469
|
/**
|
|
2448
2470
|
* POST 请求
|
|
2449
2471
|
*/
|
|
2450
|
-
async post(...args
|
|
2451
|
-
|
|
2472
|
+
async post(...args // @ts-ignore
|
|
2473
|
+
) {
|
|
2452
2474
|
let details = this.HttpxRequestDetails.handleBeforeRequestDetails(...args);
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
requestDetails =
|
|
2456
|
-
|
|
2475
|
+
let abortFn = null;
|
|
2476
|
+
const promise = new Promise((resolve, reject) => {
|
|
2477
|
+
let requestDetails = this.HttpxRequestDetails.getDetails("POST", details, resolve, reject);
|
|
2478
|
+
// @ts-ignore
|
|
2479
|
+
requestDetails = this.HttpxRequestDetails.handle(requestDetails);
|
|
2480
|
+
const requestResult = this.HttpxRequest.request(requestDetails);
|
|
2481
|
+
if (requestResult != null &&
|
|
2482
|
+
typeof requestResult.abort === "function") {
|
|
2483
|
+
abortFn = requestResult.abort;
|
|
2484
|
+
}
|
|
2457
2485
|
});
|
|
2486
|
+
Object.defineProperty(promise, "abort", {
|
|
2487
|
+
value: () => {
|
|
2488
|
+
return () => {
|
|
2489
|
+
if (typeof abortFn === "function") {
|
|
2490
|
+
abortFn();
|
|
2491
|
+
}
|
|
2492
|
+
};
|
|
2493
|
+
},
|
|
2494
|
+
});
|
|
2495
|
+
return promise;
|
|
2458
2496
|
}
|
|
2459
2497
|
/**
|
|
2460
2498
|
* HEAD 请求
|
|
2461
2499
|
*/
|
|
2462
|
-
async head(...args
|
|
2463
|
-
|
|
2500
|
+
async head(...args // @ts-ignore
|
|
2501
|
+
) {
|
|
2464
2502
|
let details = this.HttpxRequestDetails.handleBeforeRequestDetails(...args);
|
|
2465
|
-
|
|
2466
|
-
|
|
2503
|
+
let abortFn = null;
|
|
2504
|
+
const promise = new Promise((resolve, reject) => {
|
|
2505
|
+
let requestDetails = this.HttpxRequestDetails.getDetails("HEAD", details, resolve, reject);
|
|
2467
2506
|
Reflect.deleteProperty(requestDetails, "onprogress");
|
|
2468
|
-
|
|
2469
|
-
|
|
2507
|
+
// @ts-ignore
|
|
2508
|
+
requestDetails = this.HttpxRequestDetails.handle(requestDetails);
|
|
2509
|
+
const requestResult = this.HttpxRequest.request(requestDetails);
|
|
2510
|
+
if (requestResult != null &&
|
|
2511
|
+
typeof requestResult.abort === "function") {
|
|
2512
|
+
abortFn = requestResult.abort;
|
|
2513
|
+
}
|
|
2514
|
+
});
|
|
2515
|
+
Object.defineProperty(promise, "abort", {
|
|
2516
|
+
value: () => {
|
|
2517
|
+
return () => {
|
|
2518
|
+
if (typeof abortFn === "function") {
|
|
2519
|
+
abortFn();
|
|
2520
|
+
}
|
|
2521
|
+
};
|
|
2522
|
+
},
|
|
2470
2523
|
});
|
|
2524
|
+
return promise;
|
|
2471
2525
|
}
|
|
2472
2526
|
/**
|
|
2473
2527
|
* OPTIONS 请求
|
|
2474
2528
|
*/
|
|
2475
|
-
async options(...args
|
|
2476
|
-
|
|
2529
|
+
async options(...args // @ts-ignore
|
|
2530
|
+
) {
|
|
2477
2531
|
let details = this.HttpxRequestDetails.handleBeforeRequestDetails(...args);
|
|
2478
|
-
|
|
2479
|
-
|
|
2532
|
+
let abortFn = null;
|
|
2533
|
+
const promise = new Promise((resolve, reject) => {
|
|
2534
|
+
let requestDetails = this.HttpxRequestDetails.getDetails("OPTIONS", details, resolve, reject);
|
|
2480
2535
|
Reflect.deleteProperty(requestDetails, "onprogress");
|
|
2481
|
-
|
|
2482
|
-
|
|
2536
|
+
// @ts-ignore
|
|
2537
|
+
requestDetails = this.HttpxRequestDetails.handle(requestDetails);
|
|
2538
|
+
const requestResult = this.HttpxRequest.request(requestDetails);
|
|
2539
|
+
if (requestResult != null &&
|
|
2540
|
+
typeof requestResult.abort === "function") {
|
|
2541
|
+
abortFn = requestResult.abort;
|
|
2542
|
+
}
|
|
2483
2543
|
});
|
|
2544
|
+
Object.defineProperty(promise, "abort", {
|
|
2545
|
+
value: () => {
|
|
2546
|
+
return () => {
|
|
2547
|
+
if (typeof abortFn === "function") {
|
|
2548
|
+
abortFn();
|
|
2549
|
+
}
|
|
2550
|
+
};
|
|
2551
|
+
},
|
|
2552
|
+
});
|
|
2553
|
+
return promise;
|
|
2484
2554
|
}
|
|
2485
2555
|
/**
|
|
2486
2556
|
* DELETE 请求
|
|
2487
2557
|
*/
|
|
2488
|
-
async delete(...args
|
|
2489
|
-
|
|
2558
|
+
async delete(...args // @ts-ignore
|
|
2559
|
+
) {
|
|
2490
2560
|
let details = this.HttpxRequestDetails.handleBeforeRequestDetails(...args);
|
|
2491
|
-
|
|
2492
|
-
|
|
2561
|
+
let abortFn = null;
|
|
2562
|
+
const promise = new Promise((resolve, reject) => {
|
|
2563
|
+
let requestDetails = this.HttpxRequestDetails.getDetails("DELETE", details, resolve, reject);
|
|
2493
2564
|
Reflect.deleteProperty(requestDetails, "onprogress");
|
|
2494
|
-
|
|
2495
|
-
|
|
2565
|
+
// @ts-ignore
|
|
2566
|
+
requestDetails = this.HttpxRequestDetails.handle(requestDetails);
|
|
2567
|
+
const requestResult = this.HttpxRequest.request(requestDetails);
|
|
2568
|
+
if (requestResult != null &&
|
|
2569
|
+
typeof requestResult.abort === "function") {
|
|
2570
|
+
abortFn = requestResult.abort;
|
|
2571
|
+
}
|
|
2572
|
+
});
|
|
2573
|
+
Object.defineProperty(promise, "abort", {
|
|
2574
|
+
value: () => {
|
|
2575
|
+
return () => {
|
|
2576
|
+
if (typeof abortFn === "function") {
|
|
2577
|
+
abortFn();
|
|
2578
|
+
}
|
|
2579
|
+
};
|
|
2580
|
+
},
|
|
2496
2581
|
});
|
|
2582
|
+
return promise;
|
|
2497
2583
|
}
|
|
2498
2584
|
/**
|
|
2499
2585
|
* PUT 请求
|
|
2500
2586
|
*/
|
|
2501
|
-
async put(...args
|
|
2502
|
-
|
|
2587
|
+
async put(...args // @ts-ignore
|
|
2588
|
+
) {
|
|
2503
2589
|
let details = this.HttpxRequestDetails.handleBeforeRequestDetails(...args);
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
requestDetails =
|
|
2507
|
-
|
|
2590
|
+
let abortFn = null;
|
|
2591
|
+
const promise = new Promise((resolve, reject) => {
|
|
2592
|
+
let requestDetails = this.HttpxRequestDetails.getDetails("PUT", details, resolve, reject);
|
|
2593
|
+
// @ts-ignore
|
|
2594
|
+
requestDetails = this.HttpxRequestDetails.handle(requestDetails);
|
|
2595
|
+
const requestResult = this.HttpxRequest.request(requestDetails);
|
|
2596
|
+
if (requestResult != null &&
|
|
2597
|
+
typeof requestResult.abort === "function") {
|
|
2598
|
+
abortFn = requestResult.abort;
|
|
2599
|
+
}
|
|
2600
|
+
});
|
|
2601
|
+
Object.defineProperty(promise, "abort", {
|
|
2602
|
+
value: () => {
|
|
2603
|
+
return () => {
|
|
2604
|
+
if (typeof abortFn === "function") {
|
|
2605
|
+
abortFn();
|
|
2606
|
+
}
|
|
2607
|
+
};
|
|
2608
|
+
},
|
|
2508
2609
|
});
|
|
2610
|
+
return promise;
|
|
2509
2611
|
}
|
|
2510
2612
|
}
|
|
2511
2613
|
|
|
@@ -3554,7 +3656,7 @@ System.register('Utils', [], (function (exports) {
|
|
|
3554
3656
|
this.windowApi = new WindowApi(option);
|
|
3555
3657
|
}
|
|
3556
3658
|
/** 版本号 */
|
|
3557
|
-
version = "2024.9.
|
|
3659
|
+
version = "2024.9.4";
|
|
3558
3660
|
addStyle(cssText) {
|
|
3559
3661
|
if (typeof cssText !== "string") {
|
|
3560
3662
|
throw new Error("Utils.addStyle 参数cssText 必须为String类型");
|
|
@@ -5189,6 +5291,41 @@ System.register('Utils', [], (function (exports) {
|
|
|
5189
5291
|
}
|
|
5190
5292
|
return mutationObserver;
|
|
5191
5293
|
}
|
|
5294
|
+
/**
|
|
5295
|
+
* 使用观察器观察元素出现在视图内,出现的话触发回调
|
|
5296
|
+
* @param target 目标元素
|
|
5297
|
+
* @param callback 触发的回调
|
|
5298
|
+
* @param options 观察器配置
|
|
5299
|
+
*/
|
|
5300
|
+
mutatuinVisible(target, callback, options) {
|
|
5301
|
+
if (typeof IntersectionObserver === "undefined") {
|
|
5302
|
+
throw new TypeError("IntersectionObserver is not defined");
|
|
5303
|
+
}
|
|
5304
|
+
if (target == null) {
|
|
5305
|
+
throw new TypeError("mutatuinVisible target is null");
|
|
5306
|
+
}
|
|
5307
|
+
let defaultOptions = {
|
|
5308
|
+
root: null,
|
|
5309
|
+
rootMargin: "0px 0px 0px 0px",
|
|
5310
|
+
threshold: [0.01, 0.99],
|
|
5311
|
+
};
|
|
5312
|
+
defaultOptions = this.assign(defaultOptions, options || {});
|
|
5313
|
+
let intersectionObserver = new IntersectionObserver((entries, observer) => {
|
|
5314
|
+
if (entries[0].isIntersecting) {
|
|
5315
|
+
if (typeof callback === "function") {
|
|
5316
|
+
callback(entries, observer);
|
|
5317
|
+
}
|
|
5318
|
+
}
|
|
5319
|
+
}, defaultOptions);
|
|
5320
|
+
if (Array.isArray(target)) {
|
|
5321
|
+
target.forEach((item) => {
|
|
5322
|
+
intersectionObserver.observe(item);
|
|
5323
|
+
});
|
|
5324
|
+
}
|
|
5325
|
+
else {
|
|
5326
|
+
intersectionObserver.observe(target);
|
|
5327
|
+
}
|
|
5328
|
+
}
|
|
5192
5329
|
/**
|
|
5193
5330
|
* 去除全局window下的Utils,返回控制权
|
|
5194
5331
|
* @example
|