@@ -604,16 +604,6 @@ <h1>LeetCode Stats Card</h1>
604604 } ) ;
605605 }
606606
607- function getColors ( ) {
608- const order = [ "bg0" , "bg1" , "text0" , "text1" , "color0" , "color1" , "color2" , "color3" ] ;
609- return order
610- . map ( ( key ) => {
611- const el = document . querySelector ( "#color-" + key ) ;
612- return el ? el . value . trim ( ) : "" ;
613- } )
614- . join ( "," ) ;
615- }
616-
617607 function toggleTheme ( ) {
618608 document . body . classList . toggle ( "dark-mode" ) ;
619609 }
@@ -623,6 +613,21 @@ <h1>LeetCode Stats Card</h1>
623613 img . src = url ( ) || img . src ;
624614 }
625615
616+ function getColors ( ) {
617+ const order = [ "bg0" , "bg1" , "text0" , "text1" , "color0" , "color1" , "color2" , "color3" ] ;
618+ return order
619+ . map ( ( key ) => {
620+ const el = document . querySelector ( "#color-" + key ) ;
621+ if ( ! el ) return "" ;
622+ let val = el . value . trim ( ) ;
623+
624+ // Ensure we keep valid #, &, , but still make it URL-safe later
625+ // Replace commas inside color values to avoid splitting issues
626+ return val . replace ( / , / g, "%2C" ) ;
627+ } )
628+ . join ( "," ) ;
629+ }
630+
626631 function url ( ) {
627632 if ( ! value ( "username" ) ) {
628633 return "" ;
@@ -632,18 +637,14 @@ <h1>LeetCode Stats Card</h1>
632637 const useCustomColors = useCustomColorsEl ? useCustomColorsEl . checked : false ;
633638 const colors = useCustomColors ? getColors ( ) : "" ;
634639
635- return (
636- location . origin +
637- "/" +
638- encodeURIComponent ( value ( "username" ) ) +
639- "?theme=" +
640- encodeURIComponent ( value ( "theme" ) ) +
641- "&font=" +
642- encodeURIComponent ( value ( "font" ) ) +
643- ( useCustomColors && colors ? "&colors=" + encodeURIComponent ( colors ) : "" ) +
644- ( value ( "extension" ) ? "&ext=" + encodeURIComponent ( value ( "extension" ) ) : "" ) +
645- ( value ( "site" ) === "cn" ? "&site=cn" : "" )
646- ) ;
640+ const params = new URLSearchParams ( ) ;
641+ params . set ( "theme" , value ( "theme" ) ) ;
642+ params . set ( "font" , value ( "font" ) ) ;
643+ if ( useCustomColors && colors ) params . set ( "colors" , colors ) ;
644+ if ( value ( "extension" ) ) params . set ( "ext" , value ( "extension" ) ) ;
645+ if ( value ( "site" ) === "cn" ) params . set ( "site" , "cn" ) ;
646+
647+ return `${ location . origin } /${ encodeURIComponent ( value ( "username" ) ) } ?${ params . toString ( ) } ` ;
647648 }
648649
649650 function go ( ) {
0 commit comments