@whitesev/utils 2.11.11 → 2.11.13
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 +220 -62
- package/dist/index.amd.js.map +1 -1
- package/dist/index.amd.min.js +1 -1
- package/dist/index.amd.min.js.map +1 -1
- package/dist/index.cjs.js +220 -62
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.cjs.min.js +1 -1
- package/dist/index.cjs.min.js.map +1 -1
- package/dist/index.esm.js +220 -62
- package/dist/index.esm.js.map +1 -1
- package/dist/index.esm.min.js +1 -1
- package/dist/index.esm.min.js.map +1 -1
- package/dist/index.iife.js +220 -62
- package/dist/index.iife.js.map +1 -1
- package/dist/index.iife.min.js +1 -1
- package/dist/index.iife.min.js.map +1 -1
- package/dist/index.system.js +220 -62
- package/dist/index.system.js.map +1 -1
- package/dist/index.system.min.js +1 -1
- package/dist/index.system.min.js.map +1 -1
- package/dist/index.umd.js +220 -62
- package/dist/index.umd.js.map +1 -1
- package/dist/index.umd.min.js +1 -1
- package/dist/index.umd.min.js.map +1 -1
- package/dist/types/src/Dictionary.d.ts +13 -2
- package/dist/types/src/Utils.d.ts +37 -11
- package/dist/types/src/ajaxHooker/ajaxHooker.d.ts +8 -2
- package/dist/types/src/ajaxHooker/ajaxHooker1.2.4.d.ts +8 -2
- package/dist/types/src/types/Httpx.d.ts +16 -16
- package/dist/types/src/types/ajaxHooker.d.ts +92 -56
- package/package.json +3 -4
- package/src/Dictionary.ts +24 -3
- package/src/Httpx.ts +18 -18
- package/src/LockFunction.ts +3 -6
- package/src/Utils.ts +85 -53
- package/src/ajaxHooker/ajaxHooker.js +55 -5
- package/src/ajaxHooker/ajaxHooker1.2.4.js +58 -14
- package/src/types/Httpx.d.ts +16 -16
- package/src/types/ajaxHooker.d.ts +92 -56
package/dist/index.iife.js
CHANGED
|
@@ -240,7 +240,7 @@ var Utils = (function () {
|
|
|
240
240
|
const setInterval$1 = (...args) => loadOrReturnBroker().setInterval(...args);
|
|
241
241
|
const setTimeout$1 = (...args) => loadOrReturnBroker().setTimeout(...args);
|
|
242
242
|
|
|
243
|
-
const version = "2.11.
|
|
243
|
+
const version = "2.11.13";
|
|
244
244
|
|
|
245
245
|
/* eslint-disable */
|
|
246
246
|
// ==UserScript==
|
|
@@ -375,8 +375,12 @@ var Utils = (function () {
|
|
|
375
375
|
}));
|
|
376
376
|
}
|
|
377
377
|
waitForRequestKeys() {
|
|
378
|
+
/**
|
|
379
|
+
* @type {Set<typeof hookInst>}
|
|
380
|
+
*/
|
|
381
|
+
const winHookInsts = win.__ajaxHooker.hookInsts;
|
|
378
382
|
if (!this.request.async) {
|
|
379
|
-
|
|
383
|
+
winHookInsts.forEach(({ hookFns, filters }) => {
|
|
380
384
|
if (this.shouldFilter(filters))
|
|
381
385
|
return;
|
|
382
386
|
hookFns.forEach((fn) => {
|
|
@@ -392,10 +396,10 @@ var Utils = (function () {
|
|
|
392
396
|
}
|
|
393
397
|
const promises = [];
|
|
394
398
|
const ignoreKeys = new Set(["type", "async", "response"]);
|
|
395
|
-
|
|
399
|
+
winHookInsts.forEach(({ hookFns, filters }) => {
|
|
396
400
|
if (this.shouldFilter(filters))
|
|
397
401
|
return;
|
|
398
|
-
promises.push(Promise.all(hookFns.map((fn) => catchError(fn, this.request))).then(() => {
|
|
402
|
+
promises.push(Promise.all(hookFns.map((fn, index) => catchError(fn, this.request, index))).then(() => {
|
|
399
403
|
const requestKeys = [];
|
|
400
404
|
for (const key in this.request)
|
|
401
405
|
!ignoreKeys.has(key) && requestKeys.push(key);
|
|
@@ -817,11 +821,52 @@ var Utils = (function () {
|
|
|
817
821
|
});
|
|
818
822
|
});
|
|
819
823
|
}
|
|
824
|
+
/**
|
|
825
|
+
*
|
|
826
|
+
* @type {import("./../types/ajaxHooker.d.ts").UtilsAjaxHookResult["removeHook"]}
|
|
827
|
+
*/
|
|
828
|
+
const removeHook = (fn, onlyRemove = false) => {
|
|
829
|
+
let flag = false;
|
|
830
|
+
for (let index = hookInst.hookFns.length - 1; index >= 0; index--) {
|
|
831
|
+
const __fn__ = hookInst.hookFns[index];
|
|
832
|
+
if (fn === __fn__) {
|
|
833
|
+
hookInst.hookFns.splice(index, 1);
|
|
834
|
+
flag = true;
|
|
835
|
+
if (onlyRemove) {
|
|
836
|
+
break;
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
return flag;
|
|
841
|
+
};
|
|
842
|
+
/**
|
|
843
|
+
*
|
|
844
|
+
* @type {import("./../types/ajaxHooker.d.ts").UtilsAjaxHookResult["removeFilter"]}
|
|
845
|
+
*/
|
|
846
|
+
const removeFilter = () => {
|
|
847
|
+
if (Array.isArray(hookInst.filters)) {
|
|
848
|
+
hookInst.filters.length = 0;
|
|
849
|
+
}
|
|
850
|
+
else {
|
|
851
|
+
hookInst.filters = [];
|
|
852
|
+
}
|
|
853
|
+
};
|
|
820
854
|
return {
|
|
821
|
-
hook: (fn) =>
|
|
855
|
+
hook: (fn) => {
|
|
856
|
+
hookInst.hookFns.push(fn);
|
|
857
|
+
return {
|
|
858
|
+
remove: () => {
|
|
859
|
+
return removeHook(fn, true);
|
|
860
|
+
}
|
|
861
|
+
};
|
|
862
|
+
},
|
|
822
863
|
filter: (arr) => {
|
|
823
|
-
if (Array.isArray(arr))
|
|
864
|
+
if (Array.isArray(arr)) {
|
|
824
865
|
hookInst.filters = arr;
|
|
866
|
+
}
|
|
867
|
+
return {
|
|
868
|
+
remove: removeFilter
|
|
869
|
+
};
|
|
825
870
|
},
|
|
826
871
|
protect: () => {
|
|
827
872
|
readonly(win, "XMLHttpRequest", winAh.fakeXHR);
|
|
@@ -837,6 +882,8 @@ var Utils = (function () {
|
|
|
837
882
|
delete win.__ajaxHooker;
|
|
838
883
|
}
|
|
839
884
|
},
|
|
885
|
+
removeHook: removeHook,
|
|
886
|
+
removeFilter: removeFilter
|
|
840
887
|
};
|
|
841
888
|
};
|
|
842
889
|
|
|
@@ -1235,10 +1282,50 @@ var Utils = (function () {
|
|
|
1235
1282
|
Object.keys(realXhr).forEach((key) => (fakeXhr[key] = realXhr[key]));
|
|
1236
1283
|
fakeXhr.prototype = realXhr.prototype;
|
|
1237
1284
|
win.fetch = fakeFetch;
|
|
1285
|
+
/**
|
|
1286
|
+
*
|
|
1287
|
+
* @type {import("./../types/ajaxHooker.d.ts").UtilsAjaxHookResult["removeHook"]}
|
|
1288
|
+
*/
|
|
1289
|
+
const removeHook = (fn, onlyRemove = false) => {
|
|
1290
|
+
let flag = false;
|
|
1291
|
+
for (let index = hookFns.length - 1; index >= 0; index--) {
|
|
1292
|
+
const __fn__ = hookFns[index];
|
|
1293
|
+
if (fn === __fn__) {
|
|
1294
|
+
hookFns.splice(index, 1);
|
|
1295
|
+
flag = true;
|
|
1296
|
+
if (onlyRemove) {
|
|
1297
|
+
break;
|
|
1298
|
+
}
|
|
1299
|
+
}
|
|
1300
|
+
}
|
|
1301
|
+
return flag;
|
|
1302
|
+
};
|
|
1303
|
+
/**
|
|
1304
|
+
*
|
|
1305
|
+
* @type {import("./../types/ajaxHooker.d.ts").UtilsAjaxHookResult["removeFilter"]}
|
|
1306
|
+
*/
|
|
1307
|
+
const removeFilter = () => {
|
|
1308
|
+
if (Array.isArray(filter)) {
|
|
1309
|
+
filter.length = 0;
|
|
1310
|
+
}
|
|
1311
|
+
else {
|
|
1312
|
+
filter = void 0;
|
|
1313
|
+
}
|
|
1314
|
+
};
|
|
1238
1315
|
return {
|
|
1239
|
-
hook: (fn) =>
|
|
1316
|
+
hook: (fn) => {
|
|
1317
|
+
hookFns.push(fn);
|
|
1318
|
+
return {
|
|
1319
|
+
remove: () => {
|
|
1320
|
+
return removeHook(fn, true);
|
|
1321
|
+
}
|
|
1322
|
+
};
|
|
1323
|
+
},
|
|
1240
1324
|
filter: (arr) => {
|
|
1241
1325
|
filter = Array.isArray(arr) && arr.map(toFilterObj);
|
|
1326
|
+
return {
|
|
1327
|
+
remove: removeFilter
|
|
1328
|
+
};
|
|
1242
1329
|
},
|
|
1243
1330
|
protect: () => {
|
|
1244
1331
|
readonly(win, "XMLHttpRequest", fakeXhr);
|
|
@@ -1248,6 +1335,8 @@ var Utils = (function () {
|
|
|
1248
1335
|
writable(win, "XMLHttpRequest", realXhr);
|
|
1249
1336
|
writable(win, "fetch", realFetch);
|
|
1250
1337
|
},
|
|
1338
|
+
removeHook: removeHook,
|
|
1339
|
+
removeFilter: removeFilter
|
|
1251
1340
|
};
|
|
1252
1341
|
})();
|
|
1253
1342
|
};
|
|
@@ -1832,13 +1921,25 @@ var Utils = (function () {
|
|
|
1832
1921
|
}
|
|
1833
1922
|
/**
|
|
1834
1923
|
* 迭代字典
|
|
1835
|
-
* @param
|
|
1924
|
+
* @param cb 回调函数
|
|
1836
1925
|
*/
|
|
1837
|
-
forEach(
|
|
1926
|
+
forEach(cb) {
|
|
1838
1927
|
this.items.forEach((value, key) => {
|
|
1839
|
-
|
|
1928
|
+
cb(value, key, this);
|
|
1840
1929
|
});
|
|
1841
1930
|
}
|
|
1931
|
+
/**
|
|
1932
|
+
* 找到字典中对应的键和值
|
|
1933
|
+
* @param cb 回调函数
|
|
1934
|
+
*/
|
|
1935
|
+
find(cb) {
|
|
1936
|
+
for (const [key, value] of this.items.entries()) {
|
|
1937
|
+
const result = cb(value, key, this);
|
|
1938
|
+
if (result) {
|
|
1939
|
+
return result;
|
|
1940
|
+
}
|
|
1941
|
+
}
|
|
1942
|
+
}
|
|
1842
1943
|
/**
|
|
1843
1944
|
* 检查已有的键中是否以xx开头
|
|
1844
1945
|
* @param key 需要匹配的键
|
|
@@ -2672,42 +2773,42 @@ var Utils = (function () {
|
|
|
2672
2773
|
const method = requestOption.method;
|
|
2673
2774
|
if (method === "GET" || method === "HEAD") {
|
|
2674
2775
|
// GET类型,data如果有,那么需要转为searchParams
|
|
2675
|
-
const
|
|
2776
|
+
const urlInst = new URL(requestOption.url);
|
|
2676
2777
|
let urlSearch = "";
|
|
2677
|
-
let
|
|
2778
|
+
let deleteData = false;
|
|
2678
2779
|
if (typeof requestOption.data === "string") {
|
|
2679
|
-
|
|
2780
|
+
deleteData = true;
|
|
2680
2781
|
urlSearch = requestOption.data;
|
|
2681
2782
|
}
|
|
2682
2783
|
else if (typeof requestOption.data === "object") {
|
|
2683
|
-
|
|
2784
|
+
deleteData = true;
|
|
2684
2785
|
// URLSearchParams参数可以转普通的string:string,包括FormData
|
|
2685
2786
|
const searchParams = new URLSearchParams(requestOption.data);
|
|
2686
2787
|
urlSearch = searchParams.toString();
|
|
2687
2788
|
}
|
|
2688
|
-
if (
|
|
2789
|
+
if (deleteData) {
|
|
2689
2790
|
// GET/HEAD请求不支持data参数
|
|
2690
2791
|
// 对data进行处理了才可以删除
|
|
2691
2792
|
Reflect.deleteProperty(requestOption, "data");
|
|
2692
2793
|
}
|
|
2693
|
-
if (urlSearch != "") {
|
|
2694
|
-
if (
|
|
2794
|
+
if (urlSearch.trim() != "") {
|
|
2795
|
+
if (urlInst.search.trim() === "") {
|
|
2695
2796
|
// url没有search参数,直接覆盖
|
|
2696
|
-
|
|
2797
|
+
urlInst.search = urlSearch;
|
|
2697
2798
|
}
|
|
2698
2799
|
else {
|
|
2699
2800
|
// 有search参数
|
|
2700
|
-
if (
|
|
2801
|
+
if (urlInst.search.trim().endsWith("&")) {
|
|
2701
2802
|
// xxx=xxx&
|
|
2702
|
-
|
|
2803
|
+
urlInst.search = urlInst.search + urlSearch;
|
|
2703
2804
|
}
|
|
2704
2805
|
else {
|
|
2705
2806
|
// xxx=xxx&xxx=
|
|
2706
|
-
|
|
2807
|
+
urlInst.search = `${urlInst.search}&${urlSearch}`;
|
|
2707
2808
|
}
|
|
2708
2809
|
}
|
|
2709
2810
|
}
|
|
2710
|
-
requestOption.url =
|
|
2811
|
+
requestOption.url = urlInst.toString();
|
|
2711
2812
|
}
|
|
2712
2813
|
else if (method === "POST" && requestOption.headers != null) {
|
|
2713
2814
|
// POST类型,data如果是FormData,那么需要转为string
|
|
@@ -2717,10 +2818,10 @@ var Utils = (function () {
|
|
|
2717
2818
|
typeof requestOption.headers[headerKey] === "string");
|
|
2718
2819
|
});
|
|
2719
2820
|
if (ContentTypeIndex !== -1) {
|
|
2720
|
-
const
|
|
2721
|
-
const
|
|
2821
|
+
const contentTypeKey = headersKeyList[ContentTypeIndex];
|
|
2822
|
+
const contentType = requestOption.headers[contentTypeKey].toLowerCase();
|
|
2722
2823
|
// 设置了Content-Type
|
|
2723
|
-
if (
|
|
2824
|
+
if (contentType.includes("application/json")) {
|
|
2724
2825
|
// application/json
|
|
2725
2826
|
if (requestOption.data instanceof FormData) {
|
|
2726
2827
|
const entries = {};
|
|
@@ -2733,16 +2834,16 @@ var Utils = (function () {
|
|
|
2733
2834
|
requestOption.data = JSON.stringify(requestOption.data);
|
|
2734
2835
|
}
|
|
2735
2836
|
}
|
|
2736
|
-
else if (
|
|
2837
|
+
else if (contentType.includes("application/x-www-form-urlencoded")) {
|
|
2737
2838
|
// application/x-www-form-urlencoded
|
|
2738
2839
|
if (typeof requestOption.data === "object") {
|
|
2739
2840
|
requestOption.data = new URLSearchParams(requestOption.data).toString();
|
|
2740
2841
|
}
|
|
2741
2842
|
}
|
|
2742
|
-
else if (
|
|
2843
|
+
else if (contentType.includes("multipart/form-data")) {
|
|
2743
2844
|
// multipart/form-data
|
|
2744
2845
|
if (requestOption.data instanceof FormData) {
|
|
2745
|
-
Reflect.deleteProperty(requestOption.headers,
|
|
2846
|
+
Reflect.deleteProperty(requestOption.headers, contentTypeKey);
|
|
2746
2847
|
}
|
|
2747
2848
|
}
|
|
2748
2849
|
}
|
|
@@ -5700,20 +5801,25 @@ var Utils = (function () {
|
|
|
5700
5801
|
}
|
|
5701
5802
|
/**
|
|
5702
5803
|
* ajax劫持库,支持xhr和fetch劫持。
|
|
5703
|
-
* +
|
|
5704
|
-
* +
|
|
5705
|
-
* +
|
|
5706
|
-
* +
|
|
5707
|
-
* +
|
|
5708
|
-
|
|
5709
|
-
|
|
5710
|
-
|
|
5711
|
-
|
|
5712
|
-
|
|
5713
|
-
|
|
5714
|
-
|
|
5715
|
-
|
|
5716
|
-
|
|
5804
|
+
* + 来源: https://bbs.tampermonkey.net.cn/thread-3284-1-1.html
|
|
5805
|
+
* + 作者: cxxjackie
|
|
5806
|
+
* + 实现方式: Proxy
|
|
5807
|
+
* + 版本: `1.4.8`
|
|
5808
|
+
* + 文档: https://scriptcat.org/zh-CN/script-show-page/637/
|
|
5809
|
+
*/
|
|
5810
|
+
ajaxHooker = () => {
|
|
5811
|
+
return ajaxHooker();
|
|
5812
|
+
};
|
|
5813
|
+
/**
|
|
5814
|
+
* ajax劫持库,支持xhr和fetch劫持。
|
|
5815
|
+
* + 来源: https://bbs.tampermonkey.net.cn/thread-3284-1-1.html
|
|
5816
|
+
* + 作者: cxxjackie
|
|
5817
|
+
* + 实现方式: Object.defineProperty
|
|
5818
|
+
* + 版本: `1.2.4`
|
|
5819
|
+
* + 文档: https://scriptcat.org/zh-CN/script-show-page/637/
|
|
5820
|
+
*/
|
|
5821
|
+
oldAjaxHooker = () => {
|
|
5822
|
+
return AjaxHooker1_2_4();
|
|
5717
5823
|
};
|
|
5718
5824
|
canvasClickByPosition(canvasElement, clientX = 0, clientY = 0, view = this.windowApi.window) {
|
|
5719
5825
|
if (!(canvasElement instanceof HTMLCanvasElement)) {
|
|
@@ -7238,6 +7344,26 @@ var Utils = (function () {
|
|
|
7238
7344
|
}
|
|
7239
7345
|
return content;
|
|
7240
7346
|
}
|
|
7347
|
+
/**
|
|
7348
|
+
* 监听页面元素改变并处理
|
|
7349
|
+
* @param target 需要监听的元素,如果不存在,可以等待它出现
|
|
7350
|
+
* @param observer_config MutationObserver的配置
|
|
7351
|
+
* @example
|
|
7352
|
+
Utils.mutationObserver(document.querySelector("div.xxxx"),{
|
|
7353
|
+
"callback":(mutations, observer)=>{},
|
|
7354
|
+
"config":{childList:true,attributes:true}
|
|
7355
|
+
});
|
|
7356
|
+
* @example
|
|
7357
|
+
Utils.mutationObserver(document.querySelectorAll("div.xxxx"),{
|
|
7358
|
+
"callback":(mutations, observer)=>{},
|
|
7359
|
+
"config":{childList:true,attributes:true}}
|
|
7360
|
+
);
|
|
7361
|
+
* @example
|
|
7362
|
+
Utils.mutationObserver($("div.xxxx"),{
|
|
7363
|
+
"callback":(mutations, observer)=>{},
|
|
7364
|
+
"config":{childList:true,attributes:true}}
|
|
7365
|
+
);
|
|
7366
|
+
**/
|
|
7241
7367
|
mutationObserver(target, observer_config) {
|
|
7242
7368
|
const that = this;
|
|
7243
7369
|
const default_obverser_config = {
|
|
@@ -7280,16 +7406,24 @@ var Utils = (function () {
|
|
|
7280
7406
|
characterDataOldValue: void 0,
|
|
7281
7407
|
},
|
|
7282
7408
|
immediate: false,
|
|
7409
|
+
once: false,
|
|
7283
7410
|
};
|
|
7284
7411
|
observer_config = that.assign(default_obverser_config, observer_config);
|
|
7285
7412
|
const windowMutationObserver = this.windowApi.window.MutationObserver ||
|
|
7286
7413
|
this.windowApi.window.webkitMutationObserver ||
|
|
7287
7414
|
this.windowApi.window.MozMutationObserver;
|
|
7288
7415
|
// 观察者对象
|
|
7289
|
-
const
|
|
7416
|
+
const handler = (mutations, observer) => {
|
|
7417
|
+
if (observer_config.once) {
|
|
7418
|
+
// 仅触发一次
|
|
7419
|
+
observer.disconnect();
|
|
7420
|
+
}
|
|
7290
7421
|
if (typeof observer_config.callback === "function") {
|
|
7291
7422
|
observer_config.callback(mutations, observer);
|
|
7292
7423
|
}
|
|
7424
|
+
};
|
|
7425
|
+
const mutationObserver = new windowMutationObserver(function (mutations, observer) {
|
|
7426
|
+
handler(mutations, observer);
|
|
7293
7427
|
});
|
|
7294
7428
|
if (Array.isArray(target) || target instanceof NodeList) {
|
|
7295
7429
|
// 传入的是数组或者元素数组
|
|
@@ -7298,7 +7432,7 @@ var Utils = (function () {
|
|
|
7298
7432
|
});
|
|
7299
7433
|
}
|
|
7300
7434
|
else if (that.isJQuery(target)) {
|
|
7301
|
-
|
|
7435
|
+
// 传入的参数是jQuery对象
|
|
7302
7436
|
target.each((_, item) => {
|
|
7303
7437
|
mutationObserver.observe(item, observer_config.config);
|
|
7304
7438
|
});
|
|
@@ -7307,16 +7441,14 @@ var Utils = (function () {
|
|
|
7307
7441
|
mutationObserver.observe(target, observer_config.config);
|
|
7308
7442
|
}
|
|
7309
7443
|
if (observer_config.immediate) {
|
|
7310
|
-
|
|
7311
|
-
|
|
7312
|
-
observer_config.callback([], mutationObserver);
|
|
7313
|
-
}
|
|
7444
|
+
// 主动触发一次
|
|
7445
|
+
handler([], mutationObserver);
|
|
7314
7446
|
}
|
|
7315
7447
|
return mutationObserver;
|
|
7316
7448
|
}
|
|
7317
7449
|
/**
|
|
7318
7450
|
* 使用观察器观察元素出现在视图内,出现的话触发回调
|
|
7319
|
-
* @param
|
|
7451
|
+
* @param $el 目标元素
|
|
7320
7452
|
* @param callback 触发的回调
|
|
7321
7453
|
* @param options 观察器配置
|
|
7322
7454
|
* @example
|
|
@@ -7324,34 +7456,47 @@ var Utils = (function () {
|
|
|
7324
7456
|
* console.log("该元素出现在视图内");
|
|
7325
7457
|
* }))
|
|
7326
7458
|
*/
|
|
7327
|
-
mutationVisible(
|
|
7459
|
+
mutationVisible($el, callback, options) {
|
|
7328
7460
|
if (typeof IntersectionObserver === "undefined") {
|
|
7329
7461
|
throw new TypeError("IntersectionObserver is not defined");
|
|
7330
7462
|
}
|
|
7331
|
-
if (
|
|
7463
|
+
if ($el == null) {
|
|
7332
7464
|
throw new TypeError("mutatuinVisible target is null");
|
|
7333
7465
|
}
|
|
7466
|
+
options = options || {};
|
|
7334
7467
|
let defaultOptions = {
|
|
7335
7468
|
root: null,
|
|
7336
7469
|
rootMargin: "0px 0px 0px 0px",
|
|
7337
7470
|
threshold: [0.01, 0.99],
|
|
7338
7471
|
};
|
|
7339
|
-
defaultOptions = this.assign(defaultOptions, options
|
|
7472
|
+
defaultOptions = this.assign(defaultOptions, options);
|
|
7473
|
+
const handler = (entries, observer) => {
|
|
7474
|
+
if (options.once) {
|
|
7475
|
+
// 仅触发一次
|
|
7476
|
+
observer.disconnect();
|
|
7477
|
+
}
|
|
7478
|
+
if (typeof callback === "function") {
|
|
7479
|
+
callback(entries, observer);
|
|
7480
|
+
}
|
|
7481
|
+
};
|
|
7340
7482
|
const intersectionObserver = new IntersectionObserver((entries, observer) => {
|
|
7341
7483
|
if (entries[0].isIntersecting) {
|
|
7342
|
-
|
|
7343
|
-
callback(entries, observer);
|
|
7344
|
-
}
|
|
7484
|
+
handler(entries, observer);
|
|
7345
7485
|
}
|
|
7346
7486
|
}, defaultOptions);
|
|
7347
|
-
if (Array.isArray(
|
|
7348
|
-
|
|
7349
|
-
intersectionObserver.observe(
|
|
7487
|
+
if (Array.isArray($el)) {
|
|
7488
|
+
$el.forEach(($elItem) => {
|
|
7489
|
+
intersectionObserver.observe($elItem);
|
|
7350
7490
|
});
|
|
7351
7491
|
}
|
|
7352
7492
|
else {
|
|
7353
|
-
intersectionObserver.observe(
|
|
7493
|
+
intersectionObserver.observe($el);
|
|
7354
7494
|
}
|
|
7495
|
+
if (options.immediate) {
|
|
7496
|
+
// 立即触发
|
|
7497
|
+
handler([], intersectionObserver);
|
|
7498
|
+
}
|
|
7499
|
+
return intersectionObserver;
|
|
7355
7500
|
}
|
|
7356
7501
|
/**
|
|
7357
7502
|
* 去除全局window下的Utils,返回控制权
|
|
@@ -8140,12 +8285,25 @@ var Utils = (function () {
|
|
|
8140
8285
|
}
|
|
8141
8286
|
/**
|
|
8142
8287
|
* 将UrlSearchParams格式的字符串转为对象
|
|
8288
|
+
* @param searhParamsStr 字符串或对象
|
|
8289
|
+
* @example
|
|
8290
|
+
* Utils.searchParamStrToObj("xxx=xx&xx2=xx2")
|
|
8291
|
+
* @example
|
|
8292
|
+
* Utils.searchParamStrToObj(new URLSearchParams({
|
|
8293
|
+
* test1: 1,
|
|
8294
|
+
* test2: 2
|
|
8295
|
+
* }))
|
|
8143
8296
|
*/
|
|
8144
8297
|
searchParamStrToObj(searhParamsStr) {
|
|
8145
|
-
|
|
8146
|
-
|
|
8298
|
+
const params = {};
|
|
8299
|
+
if (searhParamsStr == null) {
|
|
8300
|
+
return params;
|
|
8147
8301
|
}
|
|
8148
|
-
|
|
8302
|
+
const urlSearchParams = searhParamsStr instanceof URLSearchParams ? searhParamsStr : new URLSearchParams(searhParamsStr);
|
|
8303
|
+
urlSearchParams.forEach((value, key) => {
|
|
8304
|
+
Reflect.set(params, key, value);
|
|
8305
|
+
});
|
|
8306
|
+
return params;
|
|
8149
8307
|
}
|
|
8150
8308
|
/**
|
|
8151
8309
|
* 提供一个封装了 try-catch 的函数,可以执行传入的函数并捕获其可能抛出的错误,并通过传入的错误处理函数进行处理。
|