@whitesev/utils 2.7.1 → 2.7.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 +260 -409
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +260 -409
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +260 -409
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +260 -409
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +260 -409
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +260 -409
- package/dist/index.umd.js.map +1 -1
- package/dist/types/src/ColorConversion.d.ts +3 -8
- package/dist/types/src/Dictionary.d.ts +21 -14
- package/dist/types/src/GBKEncoder.d.ts +1 -2
- package/dist/types/src/Hooks.d.ts +1 -2
- package/dist/types/src/Httpx.d.ts +45 -46
- package/dist/types/src/LockFunction.d.ts +1 -2
- package/dist/types/src/Log.d.ts +1 -2
- package/dist/types/src/Progress.d.ts +1 -2
- package/dist/types/src/Utils.d.ts +30 -2
- package/dist/types/src/UtilsGMMenu.d.ts +1 -2
- package/dist/types/src/WindowApi.d.ts +1 -2
- package/dist/types/src/indexedDB.d.ts +1 -2
- package/dist/types/src/types/Event.d.ts +1 -2
- package/dist/types/src/types/Httpx.d.ts +75 -86
- package/dist/types/src/types/ajaxHooker.d.ts +1 -5
- package/dist/types/src/types/env.d.ts +2 -0
- package/dist/types/src/types/global.d.ts +3 -0
- package/package.json +1 -1
- package/src/ColorConversion.ts +13 -37
- package/src/CommonUtil.ts +8 -31
- package/src/DOMUtils.ts +9 -24
- package/src/Dictionary.ts +37 -38
- package/src/GBKEncoder.ts +9 -18
- package/src/Hooks.ts +2 -7
- package/src/Httpx.ts +257 -412
- package/src/LockFunction.ts +1 -3
- package/src/Log.ts +8 -26
- package/src/Progress.ts +3 -13
- package/src/TryCatch.ts +4 -12
- package/src/Utils.ts +233 -595
- package/src/UtilsCommon.ts +5 -9
- package/src/UtilsGMCookie.ts +1 -4
- package/src/UtilsGMMenu.ts +29 -51
- package/src/Vue.ts +6 -18
- package/src/WindowApi.ts +2 -5
- package/src/indexedDB.ts +11 -20
- package/src/types/Event.d.ts +1 -2
- package/src/types/Httpx.d.ts +75 -86
- package/src/types/ajaxHooker.d.ts +1 -5
- package/src/types/env.d.ts +2 -0
- package/src/types/global.d.ts +3 -0
package/src/UtilsCommon.ts
CHANGED
|
@@ -5,14 +5,10 @@ export const GenerateUUID = function () {
|
|
|
5
5
|
if (typeof window?.crypto?.randomUUID === "function") {
|
|
6
6
|
return window.crypto.randomUUID();
|
|
7
7
|
} else {
|
|
8
|
-
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
charStr === "x" ? randomValue : (randomValue & 0x3) | 0x8;
|
|
14
|
-
return randomCharValue.toString(16);
|
|
15
|
-
}
|
|
16
|
-
);
|
|
8
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (charStr) {
|
|
9
|
+
var randomValue = (Math.random() * 16) | 0,
|
|
10
|
+
randomCharValue = charStr === "x" ? randomValue : (randomValue & 0x3) | 0x8;
|
|
11
|
+
return randomCharValue.toString(16);
|
|
12
|
+
});
|
|
17
13
|
}
|
|
18
14
|
};
|
package/src/UtilsGMCookie.ts
CHANGED
|
@@ -211,10 +211,7 @@ export class UtilsGMCookie {
|
|
|
211
211
|
* @param option 配置
|
|
212
212
|
* @param callback 删除操作后的回调(成功/失败)
|
|
213
213
|
*/
|
|
214
|
-
delete(
|
|
215
|
-
option: UtilsGMCookieDeleteOptions,
|
|
216
|
-
callback?: (error?: Error) => void
|
|
217
|
-
) {
|
|
214
|
+
delete(option: UtilsGMCookieDeleteOptions, callback?: (error?: Error) => void) {
|
|
218
215
|
let errorInfo;
|
|
219
216
|
try {
|
|
220
217
|
let defaultOption: Required<UtilsGMCookieDeleteOptions> = {
|
package/src/UtilsGMMenu.ts
CHANGED
|
@@ -5,7 +5,7 @@ import type {
|
|
|
5
5
|
UtilsGMMenuOptionData,
|
|
6
6
|
} from "./types/UtilsGMMenu";
|
|
7
7
|
|
|
8
|
-
class GMMenu {
|
|
8
|
+
export class GMMenu {
|
|
9
9
|
private GM_Api = {
|
|
10
10
|
/**
|
|
11
11
|
* 获取存储的数据
|
|
@@ -60,9 +60,7 @@ class GMMenu {
|
|
|
60
60
|
init() {
|
|
61
61
|
for (let index = 0; index < this.$data.data.length; index++) {
|
|
62
62
|
let menuOption = this.$data.data[index]["data"];
|
|
63
|
-
menuOption.enable = Boolean(
|
|
64
|
-
this.getLocalMenuData(menuOption.key, menuOption.enable as boolean)
|
|
65
|
-
);
|
|
63
|
+
menuOption.enable = Boolean(this.getLocalMenuData(menuOption.key, menuOption.enable as boolean));
|
|
66
64
|
if (typeof menuOption.showText !== "function") {
|
|
67
65
|
menuOption.showText = (menuText, menuEnable) => {
|
|
68
66
|
if (menuEnable) {
|
|
@@ -91,10 +89,7 @@ class GMMenu {
|
|
|
91
89
|
const { showText, clickCallBack } = this.handleMenuData(
|
|
92
90
|
cloneMenuOptionData as Required<UtilsGMMenuOption>
|
|
93
91
|
);
|
|
94
|
-
let menuId = that.context.GM_Api.registerMenuCommand(
|
|
95
|
-
showText,
|
|
96
|
-
clickCallBack
|
|
97
|
-
);
|
|
92
|
+
let menuId = that.context.GM_Api.registerMenuCommand(showText, clickCallBack);
|
|
98
93
|
menuOptions[index].id = menuId;
|
|
99
94
|
(cloneMenuOptionData as any).deleteMenu = function () {
|
|
100
95
|
that.context.GM_Api.unregisterMenuCommand(menuId);
|
|
@@ -130,9 +125,7 @@ class GMMenu {
|
|
|
130
125
|
* @param menuOption
|
|
131
126
|
*/
|
|
132
127
|
handleInitDetail(menuOption: Required<UtilsGMMenuOption>) {
|
|
133
|
-
menuOption.enable = Boolean(
|
|
134
|
-
this.getLocalMenuData(menuOption.key, menuOption.enable)
|
|
135
|
-
);
|
|
128
|
+
menuOption.enable = Boolean(this.getLocalMenuData(menuOption.key, menuOption.enable));
|
|
136
129
|
if (typeof menuOption.showText !== "function") {
|
|
137
130
|
menuOption.showText = (menuText, menuEnable) => {
|
|
138
131
|
if (menuEnable) {
|
|
@@ -152,48 +145,39 @@ class GMMenu {
|
|
|
152
145
|
let that = this;
|
|
153
146
|
let menuLocalDataItemKey = menuOption.key;
|
|
154
147
|
/* 菜单默认开启的状态 */
|
|
155
|
-
let defaultEnable = Boolean(
|
|
156
|
-
this.getLocalMenuData(menuLocalDataItemKey, menuOption.enable)
|
|
157
|
-
);
|
|
148
|
+
let defaultEnable = Boolean(this.getLocalMenuData(menuLocalDataItemKey, menuOption.enable));
|
|
158
149
|
/** 油猴菜单上显示的文本 */
|
|
159
150
|
let showText = menuOption.showText(menuOption.text, defaultEnable);
|
|
160
|
-
//
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
};
|
|
151
|
+
// const GMMenuOptions = {
|
|
152
|
+
// /**
|
|
153
|
+
// * 菜单的id
|
|
154
|
+
// */
|
|
155
|
+
// id: menuOption.id,
|
|
156
|
+
// /**
|
|
157
|
+
// * 点击菜单项后是否应关闭弹出菜单
|
|
158
|
+
// */
|
|
159
|
+
// autoClose: menuOption.autoClose,
|
|
160
|
+
// /**
|
|
161
|
+
// * 菜单项的可选访问键
|
|
162
|
+
// */
|
|
163
|
+
// accessKey: menuOption.accessKey,
|
|
164
|
+
// /**
|
|
165
|
+
// * 菜单项的鼠标悬浮上的工具提示
|
|
166
|
+
// */
|
|
167
|
+
// title: menuOption.title,
|
|
168
|
+
// };
|
|
179
169
|
/* 点击菜单后触发callback后的网页是否刷新 */
|
|
180
170
|
menuOption.autoReload =
|
|
181
|
-
typeof menuOption.autoReload !== "boolean"
|
|
182
|
-
? this.$default.autoReload
|
|
183
|
-
: menuOption.autoReload;
|
|
171
|
+
typeof menuOption.autoReload !== "boolean" ? this.$default.autoReload : menuOption.autoReload;
|
|
184
172
|
/* 点击菜单后触发callback后的网页是否存储值 */
|
|
185
173
|
menuOption.isStoreValue =
|
|
186
|
-
typeof menuOption.isStoreValue !== "boolean"
|
|
187
|
-
? this.$default.isStoreValue
|
|
188
|
-
: menuOption.isStoreValue;
|
|
174
|
+
typeof menuOption.isStoreValue !== "boolean" ? this.$default.isStoreValue : menuOption.isStoreValue;
|
|
189
175
|
/**
|
|
190
176
|
* 用户点击菜单后的回调函数
|
|
191
177
|
* @param event
|
|
192
178
|
*/
|
|
193
179
|
function clickCallBack(event: MouseEvent | PointerEvent) {
|
|
194
|
-
let localEnable = Boolean(
|
|
195
|
-
that.getLocalMenuData(menuLocalDataItemKey, defaultEnable)
|
|
196
|
-
);
|
|
180
|
+
let localEnable = Boolean(that.getLocalMenuData(menuLocalDataItemKey, defaultEnable));
|
|
197
181
|
if (menuOption.isStoreValue) {
|
|
198
182
|
that.setLocalMenuData(menuLocalDataItemKey, !localEnable);
|
|
199
183
|
}
|
|
@@ -240,8 +224,7 @@ class GMMenu {
|
|
|
240
224
|
* @param menuKey 菜单-键key
|
|
241
225
|
*/
|
|
242
226
|
getMenuHandledOption(menuKey: string) {
|
|
243
|
-
return this.$data.data.find((item) => item!.handleData!.key === menuKey)
|
|
244
|
-
?.handleData;
|
|
227
|
+
return this.$data.data.find((item) => item!.handleData!.key === menuKey)?.handleData;
|
|
245
228
|
},
|
|
246
229
|
};
|
|
247
230
|
constructor(details: UtilsGMMenuConstructorOptions) {
|
|
@@ -249,13 +232,10 @@ class GMMenu {
|
|
|
249
232
|
this.GM_Api.setValue = details.GM_setValue;
|
|
250
233
|
this.GM_Api.registerMenuCommand = details.GM_registerMenuCommand;
|
|
251
234
|
this.GM_Api.unregisterMenuCommand = details.GM_unregisterMenuCommand;
|
|
252
|
-
this.MenuHandle.$default.autoReload =
|
|
253
|
-
typeof details.autoReload === "boolean" ? details.autoReload : true;
|
|
235
|
+
this.MenuHandle.$default.autoReload = typeof details.autoReload === "boolean" ? details.autoReload : true;
|
|
254
236
|
for (const keyName of Object.keys(this.GM_Api)) {
|
|
255
237
|
if (typeof (this.GM_Api as any)[keyName] !== "function") {
|
|
256
|
-
throw new Error(
|
|
257
|
-
`Utils.GM_Menu 请在脚本开头加上 @grant ${keyName},且传入该对象`
|
|
258
|
-
);
|
|
238
|
+
throw new Error(`Utils.GM_Menu 请在脚本开头加上 @grant ${keyName},且传入该对象`);
|
|
259
239
|
}
|
|
260
240
|
}
|
|
261
241
|
this.add(details?.data || []);
|
|
@@ -472,5 +452,3 @@ class GMMenu {
|
|
|
472
452
|
this.MenuHandle.$data.key = keyName;
|
|
473
453
|
}
|
|
474
454
|
}
|
|
475
|
-
|
|
476
|
-
export { GMMenu };
|
package/src/Vue.ts
CHANGED
|
@@ -37,11 +37,10 @@ class ReactiveEffect {
|
|
|
37
37
|
deps: any[] = [];
|
|
38
38
|
private active = true;
|
|
39
39
|
private fn;
|
|
40
|
-
//
|
|
41
|
-
private scheduler;
|
|
40
|
+
// private scheduler;
|
|
42
41
|
constructor(fn: Function, scheduler: any) {
|
|
43
42
|
this.fn = fn;
|
|
44
|
-
this.scheduler = scheduler;
|
|
43
|
+
// this.scheduler = scheduler;
|
|
45
44
|
}
|
|
46
45
|
run(cb: (activeEffect: any) => void) {
|
|
47
46
|
if (!this.active) {
|
|
@@ -107,8 +106,7 @@ export class Vue {
|
|
|
107
106
|
reactive<T extends object>(target: T): T {
|
|
108
107
|
const that = this;
|
|
109
108
|
if (!(typeof target === "object" && target !== null)) {
|
|
110
|
-
|
|
111
|
-
return;
|
|
109
|
+
return void 0 as any as T;
|
|
112
110
|
}
|
|
113
111
|
if (VueUtils.isReactive(target)) {
|
|
114
112
|
return target;
|
|
@@ -142,10 +140,7 @@ export class Vue {
|
|
|
142
140
|
* @param source 被观察的对象,这里采用函数返回对象
|
|
143
141
|
* @param changeCallBack 值改变的回调
|
|
144
142
|
*/
|
|
145
|
-
watch<T>(
|
|
146
|
-
source: () => T,
|
|
147
|
-
changeCallBack: (newValue: T | undefined, oldValue: T | undefined) => void
|
|
148
|
-
) {
|
|
143
|
+
watch<T>(source: () => T, changeCallBack: (newValue: T | undefined, oldValue: T | undefined) => void) {
|
|
149
144
|
let getter;
|
|
150
145
|
if (VueUtils.isReactive(source)) {
|
|
151
146
|
getter = () => this.traversal(source);
|
|
@@ -179,18 +174,11 @@ export class Vue {
|
|
|
179
174
|
toRefs(object: any) {
|
|
180
175
|
const result = VueUtils.isArray(object) ? new Array(object.length) : {};
|
|
181
176
|
for (let key in object) {
|
|
182
|
-
|
|
183
|
-
result[key] = this.toRef(object, key);
|
|
177
|
+
(result as any)[key as any] = this.toRef(object, key);
|
|
184
178
|
}
|
|
185
179
|
return result;
|
|
186
180
|
}
|
|
187
|
-
private trigger(
|
|
188
|
-
target: any,
|
|
189
|
-
type: string,
|
|
190
|
-
key: string | symbol,
|
|
191
|
-
oldValue: any,
|
|
192
|
-
value: any
|
|
193
|
-
) {
|
|
181
|
+
private trigger(target: any, type: string, key: string | symbol, oldValue: any, value: any) {
|
|
194
182
|
const depsMap = this.targetMap.get(target);
|
|
195
183
|
if (!depsMap) return;
|
|
196
184
|
const effects = depsMap.get(key);
|
package/src/WindowApi.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { WindowApiOption } from "./types/WindowApi";
|
|
2
2
|
|
|
3
|
-
class WindowApi {
|
|
3
|
+
export class WindowApi {
|
|
4
4
|
/** 默认的配置 */
|
|
5
5
|
private defaultApi: Required<WindowApiOption> = {
|
|
6
6
|
document: document,
|
|
@@ -23,8 +23,7 @@ class WindowApi {
|
|
|
23
23
|
if (!option) {
|
|
24
24
|
option = Object.assign({}, this.defaultApi);
|
|
25
25
|
}
|
|
26
|
-
|
|
27
|
-
this.api = Object.assign({}, option);
|
|
26
|
+
this.api = Object.assign({}, option as Required<WindowApiOption>);
|
|
28
27
|
}
|
|
29
28
|
get document() {
|
|
30
29
|
return this.api.document;
|
|
@@ -42,5 +41,3 @@ class WindowApi {
|
|
|
42
41
|
return this.api.top;
|
|
43
42
|
}
|
|
44
43
|
}
|
|
45
|
-
|
|
46
|
-
export { WindowApi };
|
package/src/indexedDB.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* indexedDB 错误结果
|
|
3
|
+
*/
|
|
1
4
|
declare interface UtilsIDBOpenErrorResult {
|
|
2
5
|
code: number;
|
|
3
6
|
msg: string;
|
|
@@ -6,13 +9,13 @@ declare interface UtilsIDBOpenErrorResult {
|
|
|
6
9
|
target: IDBRequest;
|
|
7
10
|
} & Event;
|
|
8
11
|
}
|
|
9
|
-
|
|
12
|
+
|
|
13
|
+
export class indexedDB {
|
|
10
14
|
#dbName: string;
|
|
11
15
|
#storeName: string;
|
|
12
16
|
#dbVersion: number;
|
|
13
17
|
/* websql的版本号,由于ios的问题,版本号的写法不一样 */
|
|
14
|
-
//
|
|
15
|
-
#slqVersion = "1";
|
|
18
|
+
// #slqVersion = "1";
|
|
16
19
|
/* 监听IndexDB */
|
|
17
20
|
#indexedDB =
|
|
18
21
|
window.indexedDB ||
|
|
@@ -23,8 +26,7 @@ class indexedDB {
|
|
|
23
26
|
#db: {
|
|
24
27
|
[key: string]: IDBDatabase;
|
|
25
28
|
} = {};
|
|
26
|
-
//
|
|
27
|
-
#store: IDBObjectStore = null as any;
|
|
29
|
+
// #store: IDBObjectStore = null as any;
|
|
28
30
|
/** 状态码 */
|
|
29
31
|
#statusCode = {
|
|
30
32
|
operationSuccess: {
|
|
@@ -51,11 +53,7 @@ class indexedDB {
|
|
|
51
53
|
* @param storeName 表名,默认为:default_form
|
|
52
54
|
* @param dbVersion indexDB的版本号,默认为:1
|
|
53
55
|
*/
|
|
54
|
-
constructor(
|
|
55
|
-
dbName = "default_db",
|
|
56
|
-
storeName = "default_form",
|
|
57
|
-
dbVersion = 1
|
|
58
|
-
) {
|
|
56
|
+
constructor(dbName = "default_db", storeName = "default_form", dbVersion = 1) {
|
|
59
57
|
this.#dbName = dbName;
|
|
60
58
|
this.#storeName = storeName;
|
|
61
59
|
this.#dbVersion = dbVersion;
|
|
@@ -70,13 +68,10 @@ class indexedDB {
|
|
|
70
68
|
*/
|
|
71
69
|
createStore(dbName: string) {
|
|
72
70
|
let txn, store;
|
|
73
|
-
txn = this.#db[dbName].transaction(
|
|
74
|
-
this.#storeName,
|
|
75
|
-
"readwrite"
|
|
76
|
-
) as IDBTransaction;
|
|
71
|
+
txn = this.#db[dbName].transaction(this.#storeName, "readwrite") as IDBTransaction;
|
|
77
72
|
/* IndexDB的读写权限 */
|
|
78
73
|
store = txn.objectStore(this.#storeName) as IDBObjectStore;
|
|
79
|
-
this.#store = store;
|
|
74
|
+
// this.#store = store;
|
|
80
75
|
return store;
|
|
81
76
|
}
|
|
82
77
|
/**
|
|
@@ -365,9 +360,7 @@ class indexedDB {
|
|
|
365
360
|
} else {
|
|
366
361
|
let request = idbStore.getAll();
|
|
367
362
|
request.onsuccess = function (event: any) {
|
|
368
|
-
let target = event.target as IDBRequest<
|
|
369
|
-
{ key: string; value: T }[]
|
|
370
|
-
>;
|
|
363
|
+
let target = event.target as IDBRequest<{ key: string; value: T }[]>;
|
|
371
364
|
let result = target.result;
|
|
372
365
|
if (result.length !== 0) {
|
|
373
366
|
result.forEach((dataItem, index) => {
|
|
@@ -507,5 +500,3 @@ class indexedDB {
|
|
|
507
500
|
});
|
|
508
501
|
}
|
|
509
502
|
}
|
|
510
|
-
|
|
511
|
-
export { indexedDB };
|
package/src/types/Event.d.ts
CHANGED
|
@@ -40,8 +40,7 @@ declare interface DOMUtils_Frame_Object_Event {
|
|
|
40
40
|
scroll: Event;
|
|
41
41
|
unload: Event;
|
|
42
42
|
}
|
|
43
|
-
declare type DOMUtils_Frame_Object_EventType =
|
|
44
|
-
keyof DOMUtils_Frame_Object_Event;
|
|
43
|
+
declare type DOMUtils_Frame_Object_EventType = keyof DOMUtils_Frame_Object_Event;
|
|
45
44
|
/**
|
|
46
45
|
* 表单事件
|
|
47
46
|
*/
|