@whitesev/utils 2.7.2 → 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 +98 -203
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +98 -203
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +98 -203
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +98 -203
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +98 -203
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +98 -203
- package/dist/index.umd.js.map +1 -1
- package/dist/types/src/Utils.d.ts +30 -2
- package/dist/types/src/types/Event.d.ts +1 -2
- package/dist/types/src/types/Httpx.d.ts +4 -21
- package/dist/types/src/types/ajaxHooker.d.ts +1 -5
- package/package.json +1 -1
- package/src/ColorConversion.ts +5 -18
- package/src/CommonUtil.ts +8 -31
- package/src/DOMUtils.ts +9 -22
- package/src/Dictionary.ts +2 -7
- package/src/GBKEncoder.ts +1 -6
- package/src/Hooks.ts +1 -4
- package/src/Httpx.ts +102 -277
- package/src/LockFunction.ts +1 -3
- package/src/Log.ts +7 -23
- package/src/Progress.ts +2 -10
- package/src/TryCatch.ts +3 -11
- package/src/Utils.ts +209 -555
- package/src/UtilsCommon.ts +5 -9
- package/src/UtilsGMCookie.ts +1 -4
- package/src/UtilsGMMenu.ts +10 -29
- package/src/Vue.ts +2 -11
- package/src/indexedDB.ts +3 -12
- package/src/types/Event.d.ts +1 -2
- package/src/types/Httpx.d.ts +4 -21
- package/src/types/ajaxHooker.d.ts +1 -5
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
|
@@ -60,9 +60,7 @@ export 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 @@ export 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 @@ export 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,9 +145,7 @@ export 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
151
|
// const GMMenuOptions = {
|
|
@@ -177,22 +168,16 @@ export class GMMenu {
|
|
|
177
168
|
// };
|
|
178
169
|
/* 点击菜单后触发callback后的网页是否刷新 */
|
|
179
170
|
menuOption.autoReload =
|
|
180
|
-
typeof menuOption.autoReload !== "boolean"
|
|
181
|
-
? this.$default.autoReload
|
|
182
|
-
: menuOption.autoReload;
|
|
171
|
+
typeof menuOption.autoReload !== "boolean" ? this.$default.autoReload : menuOption.autoReload;
|
|
183
172
|
/* 点击菜单后触发callback后的网页是否存储值 */
|
|
184
173
|
menuOption.isStoreValue =
|
|
185
|
-
typeof menuOption.isStoreValue !== "boolean"
|
|
186
|
-
? this.$default.isStoreValue
|
|
187
|
-
: menuOption.isStoreValue;
|
|
174
|
+
typeof menuOption.isStoreValue !== "boolean" ? this.$default.isStoreValue : menuOption.isStoreValue;
|
|
188
175
|
/**
|
|
189
176
|
* 用户点击菜单后的回调函数
|
|
190
177
|
* @param event
|
|
191
178
|
*/
|
|
192
179
|
function clickCallBack(event: MouseEvent | PointerEvent) {
|
|
193
|
-
let localEnable = Boolean(
|
|
194
|
-
that.getLocalMenuData(menuLocalDataItemKey, defaultEnable)
|
|
195
|
-
);
|
|
180
|
+
let localEnable = Boolean(that.getLocalMenuData(menuLocalDataItemKey, defaultEnable));
|
|
196
181
|
if (menuOption.isStoreValue) {
|
|
197
182
|
that.setLocalMenuData(menuLocalDataItemKey, !localEnable);
|
|
198
183
|
}
|
|
@@ -239,8 +224,7 @@ export class GMMenu {
|
|
|
239
224
|
* @param menuKey 菜单-键key
|
|
240
225
|
*/
|
|
241
226
|
getMenuHandledOption(menuKey: string) {
|
|
242
|
-
return this.$data.data.find((item) => item!.handleData!.key === menuKey)
|
|
243
|
-
?.handleData;
|
|
227
|
+
return this.$data.data.find((item) => item!.handleData!.key === menuKey)?.handleData;
|
|
244
228
|
},
|
|
245
229
|
};
|
|
246
230
|
constructor(details: UtilsGMMenuConstructorOptions) {
|
|
@@ -248,13 +232,10 @@ export class GMMenu {
|
|
|
248
232
|
this.GM_Api.setValue = details.GM_setValue;
|
|
249
233
|
this.GM_Api.registerMenuCommand = details.GM_registerMenuCommand;
|
|
250
234
|
this.GM_Api.unregisterMenuCommand = details.GM_unregisterMenuCommand;
|
|
251
|
-
this.MenuHandle.$default.autoReload =
|
|
252
|
-
typeof details.autoReload === "boolean" ? details.autoReload : true;
|
|
235
|
+
this.MenuHandle.$default.autoReload = typeof details.autoReload === "boolean" ? details.autoReload : true;
|
|
253
236
|
for (const keyName of Object.keys(this.GM_Api)) {
|
|
254
237
|
if (typeof (this.GM_Api as any)[keyName] !== "function") {
|
|
255
|
-
throw new Error(
|
|
256
|
-
`Utils.GM_Menu 请在脚本开头加上 @grant ${keyName},且传入该对象`
|
|
257
|
-
);
|
|
238
|
+
throw new Error(`Utils.GM_Menu 请在脚本开头加上 @grant ${keyName},且传入该对象`);
|
|
258
239
|
}
|
|
259
240
|
}
|
|
260
241
|
this.add(details?.data || []);
|
package/src/Vue.ts
CHANGED
|
@@ -140,10 +140,7 @@ export class Vue {
|
|
|
140
140
|
* @param source 被观察的对象,这里采用函数返回对象
|
|
141
141
|
* @param changeCallBack 值改变的回调
|
|
142
142
|
*/
|
|
143
|
-
watch<T>(
|
|
144
|
-
source: () => T,
|
|
145
|
-
changeCallBack: (newValue: T | undefined, oldValue: T | undefined) => void
|
|
146
|
-
) {
|
|
143
|
+
watch<T>(source: () => T, changeCallBack: (newValue: T | undefined, oldValue: T | undefined) => void) {
|
|
147
144
|
let getter;
|
|
148
145
|
if (VueUtils.isReactive(source)) {
|
|
149
146
|
getter = () => this.traversal(source);
|
|
@@ -181,13 +178,7 @@ export class Vue {
|
|
|
181
178
|
}
|
|
182
179
|
return result;
|
|
183
180
|
}
|
|
184
|
-
private trigger(
|
|
185
|
-
target: any,
|
|
186
|
-
type: string,
|
|
187
|
-
key: string | symbol,
|
|
188
|
-
oldValue: any,
|
|
189
|
-
value: any
|
|
190
|
-
) {
|
|
181
|
+
private trigger(target: any, type: string, key: string | symbol, oldValue: any, value: any) {
|
|
191
182
|
const depsMap = this.targetMap.get(target);
|
|
192
183
|
if (!depsMap) return;
|
|
193
184
|
const effects = depsMap.get(key);
|
package/src/indexedDB.ts
CHANGED
|
@@ -53,11 +53,7 @@ export class indexedDB {
|
|
|
53
53
|
* @param storeName 表名,默认为:default_form
|
|
54
54
|
* @param dbVersion indexDB的版本号,默认为:1
|
|
55
55
|
*/
|
|
56
|
-
constructor(
|
|
57
|
-
dbName = "default_db",
|
|
58
|
-
storeName = "default_form",
|
|
59
|
-
dbVersion = 1
|
|
60
|
-
) {
|
|
56
|
+
constructor(dbName = "default_db", storeName = "default_form", dbVersion = 1) {
|
|
61
57
|
this.#dbName = dbName;
|
|
62
58
|
this.#storeName = storeName;
|
|
63
59
|
this.#dbVersion = dbVersion;
|
|
@@ -72,10 +68,7 @@ export class indexedDB {
|
|
|
72
68
|
*/
|
|
73
69
|
createStore(dbName: string) {
|
|
74
70
|
let txn, store;
|
|
75
|
-
txn = this.#db[dbName].transaction(
|
|
76
|
-
this.#storeName,
|
|
77
|
-
"readwrite"
|
|
78
|
-
) as IDBTransaction;
|
|
71
|
+
txn = this.#db[dbName].transaction(this.#storeName, "readwrite") as IDBTransaction;
|
|
79
72
|
/* IndexDB的读写权限 */
|
|
80
73
|
store = txn.objectStore(this.#storeName) as IDBObjectStore;
|
|
81
74
|
// this.#store = store;
|
|
@@ -367,9 +360,7 @@ export class indexedDB {
|
|
|
367
360
|
} else {
|
|
368
361
|
let request = idbStore.getAll();
|
|
369
362
|
request.onsuccess = function (event: any) {
|
|
370
|
-
let target = event.target as IDBRequest<
|
|
371
|
-
{ key: string; value: T }[]
|
|
372
|
-
>;
|
|
363
|
+
let target = event.target as IDBRequest<{ key: string; value: T }[]>;
|
|
373
364
|
let result = target.result;
|
|
374
365
|
if (result.length !== 0) {
|
|
375
366
|
result.forEach((dataItem, index) => {
|
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
|
*/
|
package/src/types/Httpx.d.ts
CHANGED
|
@@ -66,14 +66,7 @@ export type HttpxStatus =
|
|
|
66
66
|
* HTTP WebDav的请求方法
|
|
67
67
|
* + https://blog.csdn.net/weixin_48421613/article/details/128611546
|
|
68
68
|
*/
|
|
69
|
-
export type HttpxWebDavMethod =
|
|
70
|
-
| "PROPFIND"
|
|
71
|
-
| "PROPPATCH"
|
|
72
|
-
| "MKCOL"
|
|
73
|
-
| "MOVE"
|
|
74
|
-
| "COPY"
|
|
75
|
-
| "LOCK"
|
|
76
|
-
| "UNLOCK";
|
|
69
|
+
export type HttpxWebDavMethod = "PROPFIND" | "PROPPATCH" | "MKCOL" | "MOVE" | "COPY" | "LOCK" | "UNLOCK";
|
|
77
70
|
|
|
78
71
|
/**
|
|
79
72
|
* HTTP 请求方法
|
|
@@ -99,21 +92,12 @@ export type HttpxRedirect = "follow" | "error" | "manual";
|
|
|
99
92
|
/**
|
|
100
93
|
* 二进制数据
|
|
101
94
|
*/
|
|
102
|
-
export type HttpxBinary =
|
|
103
|
-
| Uint8ArrayConstructor
|
|
104
|
-
| ArrayBufferConstructor
|
|
105
|
-
| DataViewConstructor
|
|
106
|
-
| Blob
|
|
107
|
-
| File;
|
|
95
|
+
export type HttpxBinary = Uint8ArrayConstructor | ArrayBufferConstructor | DataViewConstructor | Blob | File;
|
|
108
96
|
|
|
109
97
|
/**
|
|
110
98
|
* 触发的响应函数名
|
|
111
99
|
*/
|
|
112
|
-
export type HttpxResponseCallBackType =
|
|
113
|
-
| "onload"
|
|
114
|
-
| "onerror"
|
|
115
|
-
| "ontimeout"
|
|
116
|
-
| "onabort";
|
|
100
|
+
export type HttpxResponseCallBackType = "onload" | "onerror" | "ontimeout" | "onabort";
|
|
117
101
|
|
|
118
102
|
/**
|
|
119
103
|
* 响应类型映射字典
|
|
@@ -1356,5 +1340,4 @@ export declare interface HttpxInitOption extends HttpxRequestOption {
|
|
|
1356
1340
|
logDetails?: boolean;
|
|
1357
1341
|
}
|
|
1358
1342
|
|
|
1359
|
-
export declare interface HttpxRequestOptionWithDoubleParams
|
|
1360
|
-
extends Omit<HttpxRequestOption, "url"> {}
|
|
1343
|
+
export declare interface HttpxRequestOptionWithDoubleParams extends Omit<HttpxRequestOption, "url"> {}
|
|
@@ -122,11 +122,7 @@ export declare interface UtilsAjaxHookResult {
|
|
|
122
122
|
};
|
|
123
123
|
});
|
|
124
124
|
*/
|
|
125
|
-
hook(
|
|
126
|
-
callback: (
|
|
127
|
-
request: UtilsAjaxHookRequestOptions
|
|
128
|
-
) => void | Promise<undefined>
|
|
129
|
-
): void;
|
|
125
|
+
hook(callback: (request: UtilsAjaxHookRequestOptions) => void | Promise<undefined>): void;
|
|
130
126
|
/**
|
|
131
127
|
* 过滤
|
|
132
128
|
* @example
|