diff --git a/src/pages/install/App.tsx b/src/pages/install/App.tsx index ee282d963..d39fbfd93 100644 --- a/src/pages/install/App.tsx +++ b/src/pages/install/App.tsx @@ -31,7 +31,7 @@ import { intervalExecution, timeoutExecution } from "@App/pkg/utils/timer"; import { useSearchParams } from "react-router-dom"; import { CACHE_KEY_SCRIPT_INFO } from "@App/app/cache_key"; import { cacheInstance } from "@App/app/cache"; -import { formatBytes } from "@App/pkg/utils/utils"; +import { formatBytes, prettyUrl } from "@App/pkg/utils/utils"; type ScriptOrSubscribe = Script | Subscribe; @@ -779,13 +779,13 @@ function App() { bold style={{ overflowWrap: "break-word", - wordBreak: "break-all", + wordBreak: "break-word", maxHeight: "70px", display: "block", overflowY: "auto", }} > - {`${t("source")}: ${scriptInfo?.url}`} + {`${t("source")}: ${prettyUrl(scriptInfo?.url)}`} diff --git a/src/pkg/utils/utils.ts b/src/pkg/utils/utils.ts index e6e1b891b..bb34c0a44 100644 --- a/src/pkg/utils/utils.ts +++ b/src/pkg/utils/utils.ts @@ -439,3 +439,37 @@ export const formatBytes = (bytes: number, decimals: number = 2): string => { return `${value.toFixed(decimals)} ${units[i]}`; }; + +// 把编码URL变成使用者可以阅读的格式 +export const prettyUrl = (s: string | undefined | null, baseUrl?: string) => { + if (s?.includes("://")) { + let u; + try { + u = baseUrl ? new URL(s, baseUrl) : new URL(s); + } catch { + // ignored + } + if (!u) return s; + const pathname = u.pathname; + if (pathname && pathname.includes("%")) { + try { + const raw = decodeURI(pathname); + if ( + raw && + raw.length < pathname.length && + !raw.includes("?") && + !raw.includes("#") && + !raw.includes("&") && + !raw.includes("=") && + !raw.includes("%") && + !raw.includes(":") + ) { + s = s.replace(pathname, raw); + } + } catch { + // ignored + } + } + } + return s; +};