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