File tree Expand file tree Collapse file tree 2 files changed +37
-3
lines changed
Expand file tree Collapse file tree 2 files changed +37
-3
lines changed Original file line number Diff line number Diff line change @@ -31,7 +31,7 @@ import { intervalExecution, timeoutExecution } from "@App/pkg/utils/timer";
3131import { useSearchParams } from "react-router-dom" ;
3232import { CACHE_KEY_SCRIPT_INFO } from "@App/app/cache_key" ;
3333import { cacheInstance } from "@App/app/cache" ;
34- import { formatBytes } from "@App/pkg/utils/utils" ;
34+ import { formatBytes , prettyUrl } from "@App/pkg/utils/utils" ;
3535
3636type ScriptOrSubscribe = Script | Subscribe ;
3737
@@ -779,13 +779,13 @@ function App() {
779779 bold
780780 style = { {
781781 overflowWrap : "break-word" ,
782- wordBreak : "break-all " ,
782+ wordBreak : "break-word " ,
783783 maxHeight : "70px" ,
784784 display : "block" ,
785785 overflowY : "auto" ,
786786 } }
787787 >
788- { `${ t ( "source" ) } : ${ scriptInfo ?. url } ` }
788+ { `${ t ( "source" ) } : ${ prettyUrl ( scriptInfo ?. url ) } ` }
789789 </ Typography . Text >
790790 </ div >
791791 </ div >
Original file line number Diff line number Diff line change @@ -439,3 +439,37 @@ export const formatBytes = (bytes: number, decimals: number = 2): string => {
439439
440440 return `${ value . toFixed ( decimals ) } ${ units [ i ] } ` ;
441441} ;
442+
443+ // 把编码URL变成使用者可以阅读的格式
444+ export const prettyUrl = ( s : string | undefined | null , baseUrl ?: string ) => {
445+ if ( s ?. includes ( "://" ) ) {
446+ let u ;
447+ try {
448+ u = baseUrl ? new URL ( s , baseUrl ) : new URL ( s ) ;
449+ } catch {
450+ // ignored
451+ }
452+ if ( ! u ) return s ;
453+ const pathname = u . pathname ;
454+ if ( pathname && pathname . includes ( "%" ) ) {
455+ try {
456+ const raw = decodeURI ( pathname ) ;
457+ if (
458+ raw &&
459+ raw . length < pathname . length &&
460+ ! raw . includes ( "?" ) &&
461+ ! raw . includes ( "#" ) &&
462+ ! raw . includes ( "&" ) &&
463+ ! raw . includes ( "=" ) &&
464+ ! raw . includes ( "%" ) &&
465+ ! raw . includes ( ":" )
466+ ) {
467+ s = s . replace ( pathname , raw ) ;
468+ }
469+ } catch {
470+ // ignored
471+ }
472+ }
473+ }
474+ return s ;
475+ } ;
You can’t perform that action at this time.
0 commit comments