Skip to content

Commit 0a207b8

Browse files
committed
refactor: merging all util functions into classes
1 parent 26bf693 commit 0a207b8

15 files changed

+225
-267
lines changed

web/assets/js/langs.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,20 @@ const supportLangs = [
6262
];
6363

6464
function getLang() {
65-
let lang = getCookie("lang");
65+
let lang = CookieManager.getCookie("lang");
6666

6767
if (!lang) {
6868
if (window.navigator) {
6969
lang = window.navigator.language || window.navigator.userLanguage;
7070

7171
if (isSupportLang(lang)) {
72-
setCookie("lang", lang, 150);
72+
CookieManager.setCookie("lang", lang, 150);
7373
} else {
74-
setCookie("lang", "en-US", 150);
74+
CookieManager.setCookie("lang", "en-US", 150);
7575
window.location.reload();
7676
}
7777
} else {
78-
setCookie("lang", "en-US", 150);
78+
CookieManager.setCookie("lang", "en-US", 150);
7979
window.location.reload();
8080
}
8181
}
@@ -88,7 +88,7 @@ function setLang(lang) {
8888
lang = "en-US";
8989
}
9090

91-
setCookie("lang", lang, 150);
91+
CookieManager.setCookie("lang", lang, 150);
9292
window.location.reload();
9393
}
9494

web/assets/js/model/dbinbound.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ class DBInbound {
2525
}
2626

2727
get totalGB() {
28-
return toFixed(this.total / ONE_GB, 2);
28+
return NumberFormatter.toFixed(this.total / SizeFormatter.ONE_GB, 2);
2929
}
3030

3131
set totalGB(gb) {
32-
this.total = toFixed(gb * ONE_GB, 0);
32+
this.total = NumberFormatter.toFixed(gb * SizeFormatter.ONE_GB, 0);
3333
}
3434

3535
get isVMess() {

web/assets/js/model/inbound.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -1837,11 +1837,11 @@ Inbound.VmessSettings.VMESS = class extends XrayCommonClass {
18371837
}
18381838
}
18391839
get _totalGB() {
1840-
return toFixed(this.totalGB / ONE_GB, 2);
1840+
return NumberFormatter.toFixed(this.totalGB / SizeFormatter.ONE_GB, 2);
18411841
}
18421842

18431843
set _totalGB(gb) {
1844-
this.totalGB = toFixed(gb * ONE_GB, 0);
1844+
this.totalGB = NumberFormatter.toFixed(gb * SizeFormatter.ONE_GB, 0);
18451845
}
18461846

18471847
};
@@ -1947,11 +1947,11 @@ Inbound.VLESSSettings.VLESS = class extends XrayCommonClass {
19471947
}
19481948
}
19491949
get _totalGB() {
1950-
return toFixed(this.totalGB / ONE_GB, 2);
1950+
return NumberFormatter.toFixed(this.totalGB / SizeFormatter.ONE_GB, 2);
19511951
}
19521952

19531953
set _totalGB(gb) {
1954-
this.totalGB = toFixed(gb * ONE_GB, 0);
1954+
this.totalGB = NumberFormatter.toFixed(gb * SizeFormatter.ONE_GB, 0);
19551955
}
19561956
};
19571957
Inbound.VLESSSettings.Fallback = class extends XrayCommonClass {
@@ -2099,11 +2099,11 @@ Inbound.TrojanSettings.Trojan = class extends XrayCommonClass {
20992099
}
21002100
}
21012101
get _totalGB() {
2102-
return toFixed(this.totalGB / ONE_GB, 2);
2102+
return NumberFormatter.toFixed(this.totalGB / SizeFormatter.ONE_GB, 2);
21032103
}
21042104

21052105
set _totalGB(gb) {
2106-
this.totalGB = toFixed(gb * ONE_GB, 0);
2106+
this.totalGB = NumberFormatter.toFixed(gb * SizeFormatter.ONE_GB, 0);
21072107
}
21082108

21092109
};
@@ -2263,11 +2263,11 @@ Inbound.ShadowsocksSettings.Shadowsocks = class extends XrayCommonClass {
22632263
}
22642264
}
22652265
get _totalGB() {
2266-
return toFixed(this.totalGB / ONE_GB, 2);
2266+
return NumberFormatter.toFixed(this.totalGB / SizeFormatter.ONE_GB, 2);
22672267
}
22682268

22692269
set _totalGB(gb) {
2270-
this.totalGB = toFixed(gb * ONE_GB, 0);
2270+
this.totalGB = NumberFormatter.toFixed(gb * SizeFormatter.ONE_GB, 0);
22712271
}
22722272

22732273
};

web/assets/js/util/common.js

-183
This file was deleted.

web/assets/js/util/date-util.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,14 @@ Date.prototype.setMaxTime = function () {
108108
* Formatting date
109109
*/
110110
Date.prototype.formatDate = function () {
111-
return this.getFullYear() + "-" + addZero(this.getMonth() + 1) + "-" + addZero(this.getDate());
111+
return this.getFullYear() + "-" + NumberFormatter.addZero(this.getMonth() + 1) + "-" + NumberFormatter.addZero(this.getDate());
112112
};
113113

114114
/**
115115
* Format time
116116
*/
117117
Date.prototype.formatTime = function () {
118-
return addZero(this.getHours()) + ":" + addZero(this.getMinutes()) + ":" + addZero(this.getSeconds());
118+
return NumberFormatter.addZero(this.getHours()) + ":" + NumberFormatter.addZero(this.getMinutes()) + ":" + NumberFormatter.addZero(this.getSeconds());
119119
};
120120

121121
/**

0 commit comments

Comments
 (0)