diff --git a/config-sub-converter/scripts/external-proxies-sanitizer.js b/config-sub-converter/scripts/external-proxies-sanitizer.js index e80dc8a..d194999 100644 --- a/config-sub-converter/scripts/external-proxies-sanitizer.js +++ b/config-sub-converter/scripts/external-proxies-sanitizer.js @@ -146,8 +146,16 @@ const PROTOCOL_ICONS = { tuic: "" }; +const STANDARD_PORTS_BY_TYPE = { + wireguard: new Set(["51820"]), + vless: new Set(["443"]), + trojan: new Set(["443"]), + ss: new Set(["443"]), +}; + const PROTOCOL_ICON_DEFAULT = ""; // fallback icon if type is unknown + const METATAG_RULES = { // Keys are "network/type" OR "/type" (network-agnostic) OR "network/" (type-agnostic) // Matching priority: exact "network/type" -> "/type" -> "network/" -> default @@ -170,9 +178,9 @@ const METATAG_RULES = { // Port formatting: superscript digits with left padding to 4 chars // 𝟎𝟏𝟐𝟑𝟒𝟓𝟔𝟕𝟖𝟗 const PORT_FORMAT = { - padLeftTo: 5, + padLeftTo: 3, padChar: "0", - superscripts: { + fancy: { "0": "𝟎", "1": "𝟏", "2": "𝟐", "3": "𝟑", "4": "𝟒", "5": "𝟓", "6": "𝟔", "7": "𝟕", "8": "𝟖", "9": "𝟗", }, }; @@ -191,13 +199,15 @@ function uWordBoundaryGroup(inner) { return new RegExp(`(?:^|[^\\p{L}\\p{N}])(?:${inner})(?=$|[^\\p{L}\\p{N}])`, "iu"); } -function portToSuperscript(port) { +function portToFancy(port, type) { let p = String(port ?? "").trim(); - - // keep only digits, because providers love putting garbage here p = p.replace(/[^\d]/g, ""); - if (!p) p = "0"; + if (!p) return ""; + if (STANDARD_PORTS_BY_TYPE[type]?.has(p)) { + return ""; + } + // left pad to fixed width if (PORT_FORMAT.padLeftTo && p.length < PORT_FORMAT.padLeftTo) { p = p.padStart(PORT_FORMAT.padLeftTo, PORT_FORMAT.padChar); @@ -205,7 +215,7 @@ function portToSuperscript(port) { // map digits let out = ""; - for (const ch of p) out += PORT_FORMAT.superscripts[ch] ?? ch; + for (const ch of p) out += PORT_FORMAT.fancy[ch] ?? ch; return out; } @@ -215,7 +225,7 @@ function buildMetaTag(proxy) { const port = safeStr(proxy && proxy.port); const { icon, matched } = metaPairIcon(net, typ); - const portSup = portToSuperscript(port); + const portSup = portToFancy(port, typ); if (icon === METATAG_RULES.defaultPair && METATAG_RULES.includeFallbackText) { return `${icon}${portSup}(${normalizeToken(net)}/${normalizeToken(typ)})`;