From bea19a263db88fef44b4356082b199fbfcc39a25 Mon Sep 17 00:00:00 2001 From: "Shishkevich D." <135337715+shishkevichd@users.noreply.github.com> Date: Sun, 6 Apr 2025 16:40:33 +0700 Subject: [PATCH] Code refactoring (#2865) * refactor: use vue inline styles in entire application * refactor: setting row in dashboard page * refactor: use blob for download file in text modal * refactor: move all html templates in `web/html` folder * refactor: `DeviceUtils` -> `MediaQueryMixin` The transition to mixins has been made, as they can update themselves. * chore: pretty right buttons in `outbounds` tab in xray settings * refactor: add translations for system status * refactor: adjust gutter spacing in setting list item * refactor: use native `a-input-password` for password field * chore: return old system status with new translations * chore: add missing translation --- web/assets/js/util/index.js | 63 +++++---- .../{xui => }/component/aClientTable.html | 52 ++++---- .../{xui => }/component/aCustomStatistic.html | 0 .../component/aPersianDatepicker.html | 2 +- .../{xui => }/component/aSettingListItem.html | 2 +- web/html/{xui => }/component/aSidebar.html | 0 .../{xui => }/component/aTableSortable.html | 2 +- .../{xui => }/component/aThemeSwitch.html | 4 +- web/html/{xui => }/form/allocate.html | 0 web/html/{xui => }/form/client.html | 4 +- web/html/{xui => }/form/inbound.html | 2 +- web/html/{xui => }/form/outbound.html | 18 +-- .../{xui => }/form/protocol/dokodemo.html | 0 web/html/{xui => }/form/protocol/http.html | 10 +- .../{xui => }/form/protocol/shadowsocks.html | 2 +- web/html/{xui => }/form/protocol/socks.html | 10 +- web/html/{xui => }/form/protocol/trojan.html | 2 +- web/html/{xui => }/form/protocol/vless.html | 4 +- web/html/{xui => }/form/protocol/vmess.html | 0 .../{xui => }/form/protocol/wireguard.html | 4 +- web/html/{xui => }/form/reality_settings.html | 2 +- web/html/{xui => }/form/sniffing.html | 0 .../{xui => }/form/stream/external_proxy.html | 14 +- .../{xui => }/form/stream/stream_grpc.html | 0 .../form/stream/stream_httpupgrade.html | 6 +- .../{xui => }/form/stream/stream_kcp.html | 2 +- .../form/stream/stream_settings.html | 2 +- .../{xui => }/form/stream/stream_sockopt.html | 8 +- .../{xui => }/form/stream/stream_tcp.html | 16 +-- web/html/{xui => }/form/stream/stream_ws.html | 6 +- .../{xui => }/form/stream/stream_xhttp.html | 8 +- web/html/{xui => }/form/tls_settings.html | 14 +- web/html/{xui => }/inbounds.html | 77 +++++------ web/html/{xui => }/index.html | 125 ++++++++++-------- web/html/login.html | 21 +-- .../{xui => }/modals/client_bulk_modal.html | 2 +- web/html/{xui => }/modals/client_modal.html | 2 +- web/html/{xui => }/modals/dns_modal.html | 2 +- web/html/{xui => }/modals/fakedns_modal.html | 0 .../{xui => }/modals/inbound_info_modal.html | 16 +-- web/html/{xui => }/modals/inbound_modal.html | 0 web/html/{xui => }/modals/prompt_modal.html | 0 web/html/{xui => }/modals/qrcode_modal.html | 3 +- web/html/{xui => }/modals/text_modal.html | 32 +++-- web/html/{xui => }/modals/warp_modal.html | 18 +-- .../{xui => }/modals/xray_balancer_modal.html | 0 .../{xui => }/modals/xray_outbound_modal.html | 2 +- .../{xui => }/modals/xray_reverse_modal.html | 0 .../{xui => }/modals/xray_rule_modal.html | 8 +- web/html/{xui => }/settings.html | 24 ++-- .../{xui => }/settings/panel/general.html | 20 +-- .../{xui => }/settings/panel/security.html | 10 +- .../settings/panel/subscription/general.html | 4 +- .../settings/panel/subscription/json.html | 24 ++-- .../{xui => }/settings/panel/telegram.html | 4 +- .../{xui => }/settings/xray/advanced.html | 4 +- .../{xui => }/settings/xray/balancers.html | 20 +-- web/html/{xui => }/settings/xray/basics.html | 54 ++++---- web/html/{xui => }/settings/xray/dns.html | 18 +-- .../{xui => }/settings/xray/outbounds.html | 34 ++--- web/html/{xui => }/settings/xray/reverse.html | 8 +- web/html/{xui => }/settings/xray/routing.html | 8 +- web/html/{xui => }/xray.html | 28 ++-- web/html/xui/component/aPasswordInput.html | 57 -------- web/translation/translate.en_US.toml | 12 +- web/translation/translate.es_ES.toml | 14 +- web/translation/translate.fa_IR.toml | 14 +- web/translation/translate.id_ID.toml | 13 +- web/translation/translate.ja_JP.toml | 14 +- web/translation/translate.pt_BR.toml | 14 +- web/translation/translate.ru_RU.toml | 14 +- web/translation/translate.tr_TR.toml | 12 +- web/translation/translate.uk_UA.toml | 14 +- web/translation/translate.vi_VN.toml | 14 +- web/translation/translate.zh_CN.toml | 12 +- web/translation/translate.zh_TW.toml | 12 +- 76 files changed, 570 insertions(+), 473 deletions(-) rename web/html/{xui => }/component/aClientTable.html (81%) rename web/html/{xui => }/component/aCustomStatistic.html (100%) rename web/html/{xui => }/component/aPersianDatepicker.html (96%) rename web/html/{xui => }/component/aSettingListItem.html (97%) rename web/html/{xui => }/component/aSidebar.html (100%) rename web/html/{xui => }/component/aTableSortable.html (97%) rename web/html/{xui => }/component/aThemeSwitch.html (95%) rename web/html/{xui => }/form/allocate.html (100%) rename web/html/{xui => }/form/client.html (98%) rename web/html/{xui => }/form/inbound.html (97%) rename web/html/{xui => }/form/outbound.html (96%) rename web/html/{xui => }/form/protocol/dokodemo.html (100%) rename web/html/{xui => }/form/protocol/http.html (65%) rename web/html/{xui => }/form/protocol/shadowsocks.html (94%) rename web/html/{xui => }/form/protocol/socks.html (74%) rename web/html/{xui => }/form/protocol/trojan.html (90%) rename web/html/{xui => }/form/protocol/vless.html (87%) rename web/html/{xui => }/form/protocol/vmess.html (100%) rename web/html/{xui => }/form/protocol/wireguard.html (90%) rename web/html/{xui => }/form/reality_settings.html (98%) rename web/html/{xui => }/form/sniffing.html (100%) rename web/html/{xui => }/form/stream/external_proxy.html (50%) rename web/html/{xui => }/form/stream/stream_grpc.html (100%) rename web/html/{xui => }/form/stream/stream_httpupgrade.html (75%) rename web/html/{xui => }/form/stream/stream_kcp.html (94%) rename web/html/{xui => }/form/stream/stream_settings.html (93%) rename web/html/{xui => }/form/stream/stream_sockopt.html (90%) rename web/html/{xui => }/form/stream/stream_tcp.html (78%) rename web/html/{xui => }/form/stream/stream_ws.html (76%) rename web/html/{xui => }/form/stream/stream_xhttp.html (86%) rename web/html/{xui => }/form/tls_settings.html (90%) rename web/html/{xui => }/inbounds.html (94%) rename web/html/{xui => }/index.html (85%) rename web/html/{xui => }/modals/client_bulk_modal.html (98%) rename web/html/{xui => }/modals/client_modal.html (98%) rename web/html/{xui => }/modals/dns_modal.html (97%) rename web/html/{xui => }/modals/fakedns_modal.html (100%) rename web/html/{xui => }/modals/inbound_info_modal.html (96%) rename web/html/{xui => }/modals/inbound_modal.html (100%) rename web/html/{xui => }/modals/prompt_modal.html (100%) rename web/html/{xui => }/modals/qrcode_modal.html (98%) rename web/html/{xui => }/modals/text_modal.html (60%) rename web/html/{xui => }/modals/warp_modal.html (92%) rename web/html/{xui => }/modals/xray_balancer_modal.html (100%) rename web/html/{xui => }/modals/xray_outbound_modal.html (99%) rename web/html/{xui => }/modals/xray_reverse_modal.html (100%) rename web/html/{xui => }/modals/xray_rule_modal.html (95%) rename web/html/{xui => }/settings.html (95%) rename web/html/{xui => }/settings/panel/general.html (92%) rename web/html/{xui => }/settings/panel/security.html (83%) rename web/html/{xui => }/settings/panel/subscription/general.html (97%) rename web/html/{xui => }/settings/panel/subscription/json.html (90%) rename web/html/{xui => }/settings/panel/telegram.html (98%) rename web/html/{xui => }/settings/xray/advanced.html (83%) rename web/html/{xui => }/settings/xray/balancers.html (69%) rename web/html/{xui => }/settings/xray/basics.html (87%) rename web/html/{xui => }/settings/xray/dns.html (93%) rename web/html/{xui => }/settings/xray/outbounds.html (64%) rename web/html/{xui => }/settings/xray/reverse.html (85%) rename web/html/{xui => }/settings/xray/routing.html (94%) rename web/html/{xui => }/xray.html (98%) delete mode 100644 web/html/xui/component/aPasswordInput.html diff --git a/web/assets/js/util/index.js b/web/assets/js/util/index.js index 625af8b9..93416abe 100644 --- a/web/assets/js/util/index.js +++ b/web/assets/js/util/index.js @@ -83,7 +83,7 @@ class PromiseUtil { class RandomUtil { static getSeq({ type = "default", hasNumbers = true, hasLowercase = true, hasUppercase = true } = {}) { let seq = ''; - + switch (type) { case "hex": seq += "0123456789abcdef"; @@ -488,7 +488,7 @@ class ClipboardManager { return new Promise((resolve) => { try { const textarea = window.document.createElement('textarea'); - + textarea.style.fontSize = '12pt'; textarea.style.border = '0'; textarea.style.padding = '0'; @@ -498,14 +498,14 @@ class ClipboardManager { textarea.style.top = `${window.pageYOffset || document.documentElement.scrollTop}px`; textarea.setAttribute('readonly', ''); textarea.value = content; - + window.document.body.appendChild(textarea); - + textarea.select(); window.document.execCommand("copy"); - + window.document.body.removeChild(textarea); - + resolve(true) } catch { resolve(false) @@ -558,7 +558,7 @@ class CPUFormatter { static cpuSpeedFormat(speed) { return speed > 1000 ? (speed / 1000).toFixed(2) + " GHz" : speed.toFixed(2) + " MHz"; } - + static cpuCoreFormat(cores) { return cores === 1 ? "1 Core" : cores + " Cores"; } @@ -579,7 +579,7 @@ class NumberFormatter { static addZero(num) { return num < 10 ? "0" + num : num; } - + static toFixed(num, n) { n = Math.pow(10, n); return Math.floor(num * n) / n; @@ -610,7 +610,7 @@ class CookieManager { } return ''; } - + static setCookie(cname, cvalue, exdays) { const d = new Date(); d.setTime(d.getTime() + exdays * 24 * 60 * 60 * 1000); @@ -630,7 +630,7 @@ class ColorUtils { default: return "red"; } } - + static clientUsageColor(clientStats, trafficDiff) { switch (true) { case !clientStats || clientStats.total == 0: return "#7a316f"; @@ -639,7 +639,7 @@ class ColorUtils { default: return "#cf3c3c"; } } - + static userExpiryColor(threshold, client, isDark = false) { if (!client.enable) return isDark ? '#2c3950' : '#bcbcbc'; let now = new Date().getTime(), expiry = client.expiryTime; @@ -665,7 +665,7 @@ class URLBuilder { if (!host || host.length === 0) host = window.location.hostname; if (!port || port.length === 0) port = window.location.port; if (isTLS === undefined) isTLS = window.location.protocol === "https:"; - + const protocol = isTLS ? "https:" : "http:"; port = String(port); if (port === "" || (isTLS && port === "443") || (!isTLS && port === "80")) { @@ -673,7 +673,7 @@ class URLBuilder { } else { port = `:${port}`; } - + return `${protocol}//${host}${port}${base}${path}`; } } @@ -744,11 +744,11 @@ class LanguageManager { static getLanguage() { let lang = CookieManager.getCookie("lang"); - + if (!lang) { if (window.navigator) { lang = window.navigator.language || window.navigator.userLanguage; - + if (LanguageManager.isSupportLanguage(lang)) { CookieManager.setCookie("lang", lang, 150); } else { @@ -760,30 +760,43 @@ class LanguageManager { window.location.reload(); } } - + return lang; } - + static setLanguage(language) { if (!LanguageManager.isSupportLanguage(language)) { language = "en-US"; } - + CookieManager.setCookie("lang", language, 150); window.location.reload(); } - + static isSupportLanguage(language) { const languageFilter = LanguageManager.supportedLanguages.filter((lang) => { return lang.value === language }) - + return languageFilter.length > 0; - } + } } -class DeviceUtils { - static isMobile() { - return window.innerWidth <= 768; - } +const MediaQueryMixin = { + data() { + return { + isMobile: window.innerWidth <= 768, + }; + }, + methods: { + updateDeviceType() { + this.isMobile = window.innerWidth <= 768; + }, + }, + mounted() { + window.addEventListener('resize', this.updateDeviceType); + }, + beforeDestroy() { + window.removeEventListener('resize', this.updateDeviceType); + }, } \ No newline at end of file diff --git a/web/html/xui/component/aClientTable.html b/web/html/component/aClientTable.html similarity index 81% rename from web/html/xui/component/aClientTable.html rename to web/html/component/aClientTable.html index 2bea96e8..868112d9 100644 --- a/web/html/xui/component/aClientTable.html +++ b/web/html/component/aClientTable.html @@ -2,30 +2,30 @@ @@ -124,9 +124,9 @@ - [[ remainedDays(client.expiryTime) ]] + [[ remainedDays(client.expiryTime) ]] - + @@ -135,27 +135,27 @@ -