From 729d8549e2b536a10c402a88e0d4cfde9e4baf3f Mon Sep 17 00:00:00 2001 From: Alireza Ahmadi Date: Mon, 4 Dec 2023 19:17:38 +0100 Subject: new frontend and mobile view #1286 --- web/assets/js/util/common.js | 48 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 37 insertions(+), 11 deletions(-) (limited to 'web/assets/js/util') diff --git a/web/assets/js/util/common.js b/web/assets/js/util/common.js index 8e30bce7..b2f15fb2 100644 --- a/web/assets/js/util/common.js +++ b/web/assets/js/util/common.js @@ -52,13 +52,15 @@ function safeBase64(str) { function formatSecond(second) { if (second < 60) { - return second.toFixed(0) + ' s'; + return second.toFixed(0) + 's'; } else if (second < 3600) { - return (second / 60).toFixed(0) + ' m'; + return (second / 60).toFixed(0) + 'm'; } else if (second < 3600 * 24) { - return (second / 3600).toFixed(0) + ' h'; + return (second / 3600).toFixed(0) + 'h'; } else { - return (second / 3600 / 24).toFixed(0) + ' d'; + day = Math.floor(second / 3600 / 24); + remain = ((second/3600) - (day*24)).toFixed(0); + return day + 'd' + (remain > 0 ? ' ' + remain + 'h' : ''); } } @@ -72,7 +74,7 @@ function addZero(num) { function toFixed(num, n) { n = Math.pow(10, n); - return Math.round(num * n) / n; + return Math.floor(num * n) / n; } function debounce(fn, delay) { @@ -115,15 +117,39 @@ function setCookie(cname, cvalue, exdays) { function usageColor(data, threshold, total) { switch (true) { case data === null: - return 'blue'; - case total <= 0: - return 'blue'; + return "green"; + case total < 0: + return "blue"; + case total == 0: + return "purple"; case data < total - threshold: - return 'cyan'; + return "blue"; case data < total: - return 'orange'; + return "orange"; default: - return 'red'; + return "red"; + } +} + +function userExpiryColor(threshold, client, isDark = false) { + if (!client.enable) { + return isDark ? '#2c3950' : '#bcbcbc'; + } + now = new Date().getTime(), + expiry = client.expiryTime; + switch (true) { + case expiry === null: + return "#389e0d"; + case expiry < 0: + return "#0e49b5"; + case expiry == 0: + return "#7a316f"; + case now < expiry - threshold: + return "#0e49b5"; + case now < expiry: + return "#ffa031"; + default: + return "#e04141"; } } -- cgit v1.2.3 From 375814da273cd2548c30fc56a86dd74ef5f009c9 Mon Sep 17 00:00:00 2001 From: MHSanaei Date: Mon, 4 Dec 2023 23:51:14 +0330 Subject: [bug] fix status colors in pages Co-Authored-By: Alireza Ahmadi --- web/assets/js/util/common.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'web/assets/js/util') diff --git a/web/assets/js/util/common.js b/web/assets/js/util/common.js index b2f15fb2..38a2c37e 100644 --- a/web/assets/js/util/common.js +++ b/web/assets/js/util/common.js @@ -131,6 +131,19 @@ function usageColor(data, threshold, total) { } } +function clientUsageColor(clientStats, trafficDiff) { + switch (true) { + case !clientStats || clientStats.total == 0: + return "#7a316f"; + case clientStats.up + clientStats.down < clientStats.total - trafficDiff: + return "#0e49b5"; + case clientStats.up + clientStats.down < clientStats.total: + return "#FFA031"; + default: + return "#E04141"; + } +} + function userExpiryColor(threshold, client, isDark = false) { if (!client.enable) { return isDark ? '#2c3950' : '#bcbcbc'; -- cgit v1.2.3 From d8c509b41056b9ca41725fac0bfa7515ce1f795b Mon Sep 17 00:00:00 2001 From: MHSanaei Date: Tue, 5 Dec 2023 00:19:01 +0330 Subject: small typo Co-Authored-By: Alireza Ahmadi --- web/assets/js/util/common.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'web/assets/js/util') diff --git a/web/assets/js/util/common.js b/web/assets/js/util/common.js index 38a2c37e..82bc9a0c 100644 --- a/web/assets/js/util/common.js +++ b/web/assets/js/util/common.js @@ -138,9 +138,9 @@ function clientUsageColor(clientStats, trafficDiff) { case clientStats.up + clientStats.down < clientStats.total - trafficDiff: return "#0e49b5"; case clientStats.up + clientStats.down < clientStats.total: - return "#FFA031"; + return "#ffa031"; default: - return "#E04141"; + return "#e04141"; } } -- cgit v1.2.3 From c419eadf15630518606ab434387079172070d340 Mon Sep 17 00:00:00 2001 From: Alireza Ahmadi Date: Tue, 5 Dec 2023 18:13:36 +0100 Subject: xray setting enhancements #1286 --- web/assets/js/util/utils.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'web/assets/js/util') diff --git a/web/assets/js/util/utils.js b/web/assets/js/util/utils.js index 781e13a8..9d6cb0d1 100644 --- a/web/assets/js/util/utils.js +++ b/web/assets/js/util/utils.js @@ -1,3 +1,21 @@ +class Msg { + constructor(success, msg, obj) { + this.success = false; + this.msg = ""; + this.obj = null; + + if (success != null) { + this.success = success; + } + if (msg != null) { + this.msg = msg; + } + if (obj != null) { + this.obj = obj; + } + } +} + class HttpUtil { static _handleMsg(msg) { if (!(msg instanceof Msg)) { -- cgit v1.2.3 From f7e439b9307357ebb53cc909d164cb4dab23dfc8 Mon Sep 17 00:00:00 2001 From: Alireza Ahmadi Date: Tue, 5 Dec 2023 22:57:45 +0100 Subject: fix deep search null error --- web/assets/js/util/utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'web/assets/js/util') diff --git a/web/assets/js/util/utils.js b/web/assets/js/util/utils.js index 9d6cb0d1..8bab58ec 100644 --- a/web/assets/js/util/utils.js +++ b/web/assets/js/util/utils.js @@ -176,7 +176,7 @@ class ObjectUtil { } } } else { - return obj.toString().toLowerCase().indexOf(key.toLowerCase()) >= 0; + return this.isEmpty(obj) ? false : obj.toString().toLowerCase().indexOf(key.toLowerCase()) >= 0; } return false; } -- cgit v1.2.3 From bf267c2c48ebc3dc54c28e7713ba7f1615aea944 Mon Sep 17 00:00:00 2001 From: Alireza Ahmadi Date: Sat, 9 Dec 2023 13:59:48 +0100 Subject: fix colors #1300 --- web/assets/js/util/common.js | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'web/assets/js/util') diff --git a/web/assets/js/util/common.js b/web/assets/js/util/common.js index 82bc9a0c..5f20d7d9 100644 --- a/web/assets/js/util/common.js +++ b/web/assets/js/util/common.js @@ -117,13 +117,13 @@ function setCookie(cname, cvalue, exdays) { function usageColor(data, threshold, total) { switch (true) { case data === null: - return "green"; + return "purple"; case total < 0: - return "blue"; + return "green"; case total == 0: return "purple"; case data < total - threshold: - return "blue"; + return "green"; case data < total: return "orange"; default: @@ -134,13 +134,13 @@ function usageColor(data, threshold, total) { function clientUsageColor(clientStats, trafficDiff) { switch (true) { case !clientStats || clientStats.total == 0: - return "#7a316f"; + return "#7a316f"; // purple case clientStats.up + clientStats.down < clientStats.total - trafficDiff: - return "#0e49b5"; + return "#008771"; // Green case clientStats.up + clientStats.down < clientStats.total: - return "#ffa031"; + return "#f37b24"; // Orange default: - return "#e04141"; + return "#cf3c3c"; // Red } } @@ -152,17 +152,17 @@ function userExpiryColor(threshold, client, isDark = false) { expiry = client.expiryTime; switch (true) { case expiry === null: - return "#389e0d"; + return "#7a316f"; // purple case expiry < 0: - return "#0e49b5"; + return "#008771"; // Green case expiry == 0: - return "#7a316f"; + return "#7a316f"; // purple case now < expiry - threshold: - return "#0e49b5"; + return "#008771"; // Green case now < expiry: - return "#ffa031"; + return "#f37b24"; // Orange default: - return "#e04141"; + return "#cf3c3c"; // Red } } -- cgit v1.2.3