@@ -496,17 +496,40 @@ export function initializeThemeWatcher(): () => void {
496496 // Poll for changes (fallback)
497497 const interval = setInterval ( checkTheme , 10000 ) ;
498498
499- // Apply initial theme
500- // Check if we should auto-apply winter theme
501- if ( shouldAutoApplyWinterTheme ( ) ) {
502- console . log ( "will apply winter" ) ;
503- applyTheme ( "winter" , false ) ; // Apply winter but don't store it
504- notifyThemeChange ( "winter" ) ; // Notify with the stored theme, not 'winter'
505- } else {
506- const initialTheme = getStoredTheme ( ) ;
507- applyTheme ( initialTheme ) ;
508- if ( initialTheme === "random" ) {
509- startRandomThemeRotation ( ) ;
499+ // Check for theme URL parameter and apply it
500+ const urlParams = new URLSearchParams ( window . location . search ) ;
501+ const themeParam = urlParams . get ( "theme" ) ;
502+ let themeParamApplied = false ;
503+
504+ if ( themeParam ) {
505+ // Validate theme exists
506+ const themeExists = themes . some ( ( t ) => t . id === themeParam ) ;
507+ if ( themeExists ) {
508+ changeTheme ( themeParam ) ;
509+ themeParamApplied = true ;
510+ }
511+ // Remove theme parameter from URL without page reload
512+ urlParams . delete ( "theme" ) ;
513+ const newUrl =
514+ urlParams . toString ( ) === ""
515+ ? window . location . pathname
516+ : `${ window . location . pathname } ?${ urlParams . toString ( ) } ` ;
517+ window . history . replaceState ( { } , "" , newUrl ) ;
518+ }
519+
520+ // Apply initial theme (only if no valid theme parameter was provided)
521+ if ( ! themeParamApplied ) {
522+ // Check if we should auto-apply winter theme
523+ if ( shouldAutoApplyWinterTheme ( ) ) {
524+ console . log ( "will apply winter" ) ;
525+ applyTheme ( "winter" , false ) ; // Apply winter but don't store it
526+ notifyThemeChange ( "winter" ) ; // Notify with the stored theme, not 'winter'
527+ } else {
528+ const initialTheme = getStoredTheme ( ) ;
529+ applyTheme ( initialTheme ) ;
530+ if ( initialTheme === "random" ) {
531+ startRandomThemeRotation ( ) ;
532+ }
510533 }
511534 }
512535
0 commit comments