@@ -145,6 +145,7 @@ const quoteOutput = document.getElementById("quote-output");
145145const signalCount = document . getElementById ( "signal-count" ) ;
146146const penguinAvatar = document . querySelector ( ".penguin-avatar" ) ;
147147const penguinBelly = document . querySelector ( ".penguin-belly" ) ;
148+ const androidDateBadge = document . querySelector ( ".android-date-badge" ) ;
148149const paletteOpenBtn = document . getElementById ( "palette-open" ) ;
149150let commandPalette = document . getElementById ( "command-palette" ) ;
150151let commandBackdrop = document . getElementById ( "command-backdrop" ) ;
@@ -698,7 +699,7 @@ function initTerminalFontFallbackMode() {
698699}
699700
700701function initPenguinDateBadge ( ) {
701- if ( ! penguinBelly ) return ;
702+ if ( ! penguinBelly && ! androidDateBadge ) return ;
702703
703704 let lastAdDate = "" ;
704705
@@ -716,14 +717,24 @@ function initPenguinDateBadge() {
716717 return `${ year } -${ month } -${ day } ` ;
717718 } ;
718719
719- const parseBsDay = ( value ) => {
720+ const parseBsDate = ( value ) => {
720721 if ( typeof value === "string" ) {
721722 const match = value . match ( / ^ ( \d { 4 } ) [ - / ] ( \d { 1 , 2 } ) [ - / ] ( \d { 1 , 2 } ) $ / ) ;
722- if ( match ) return String ( Number . parseInt ( match [ 3 ] , 10 ) ) ;
723+ if ( match ) {
724+ return {
725+ year : Number . parseInt ( match [ 1 ] , 10 ) ,
726+ month : Number . parseInt ( match [ 2 ] , 10 ) ,
727+ day : Number . parseInt ( match [ 3 ] , 10 ) ,
728+ } ;
729+ }
723730 }
724731
725732 if ( value && typeof value === "object" && "day" in value ) {
726- return String ( Number . parseInt ( value . day , 10 ) ) ;
733+ return {
734+ year : Number . parseInt ( value . year , 10 ) ,
735+ month : Number . parseInt ( value . month , 10 ) ,
736+ day : Number . parseInt ( value . day , 10 ) ,
737+ } ;
727738 }
728739
729740 return null ;
@@ -752,21 +763,31 @@ function initPenguinDateBadge() {
752763
753764 const tick = async ( ) => {
754765 const adDate = getNepalAdDate ( ) ;
755- if ( adDate === lastAdDate && penguinBelly . dataset . day ) return ;
766+ if ( adDate === lastAdDate && ( penguinBelly ? .dataset . day || androidDateBadge ?. dataset . bs ) ) return ;
756767
757- let bsDay = null ;
768+ let bsDate = null ;
758769 const converter = await loadBsConverter ( ) ;
759770
760771 if ( converter ) {
761772 try {
762773 const bsValue = converter ( adDate ) ;
763- bsDay = parseBsDay ( bsValue ) ;
774+ bsDate = parseBsDate ( bsValue ) ;
764775 } catch ( error ) {
765- bsDay = null ;
776+ bsDate = null ;
766777 }
767778 }
768779
769- penguinBelly . dataset . day = bsDay || getFallbackDay ( ) ;
780+ const fallbackDay = getFallbackDay ( ) ;
781+ if ( penguinBelly ) {
782+ penguinBelly . dataset . day = String ( bsDate ?. day || fallbackDay ) ;
783+ }
784+ if ( androidDateBadge ) {
785+ const bsText = bsDate
786+ ? `BS ${ String ( bsDate . year ) . padStart ( 4 , "0" ) } /${ String ( bsDate . month ) . padStart ( 2 , "0" ) } /${ String ( bsDate . day ) . padStart ( 2 , "0" ) } `
787+ : `BS day ${ fallbackDay } ` ;
788+ androidDateBadge . textContent = bsText ;
789+ androidDateBadge . dataset . bs = bsText ;
790+ }
770791 lastAdDate = adDate ;
771792 } ;
772793
@@ -823,7 +844,8 @@ function initThemeSwitcher() {
823844 window . addEventListener ( "pageshow" , ( ) => {
824845 let latestTheme = "neo" ;
825846 try {
826- latestTheme = window . localStorage . getItem ( THEME_STORAGE_KEY ) || getThemeFromUrl ( ) || "neo" ;
847+ const storedTheme = window . localStorage . getItem ( THEME_STORAGE_KEY ) ;
848+ latestTheme = storedTheme || getThemeFromUrl ( ) || "neo" ;
827849 } catch ( error ) {
828850 latestTheme = "neo" ;
829851 }
@@ -849,6 +871,24 @@ function initThemeSwitcher() {
849871 } ) ;
850872}
851873
874+ function initNavThemeGuard ( ) {
875+ const navLinks = document . querySelectorAll ( 'a[href$=".html"], a[href*=".html?"]' ) ;
876+ navLinks . forEach ( ( link ) => {
877+ link . addEventListener ( "click" , ( ) => {
878+ try {
879+ const theme = THEME_OPTIONS . includes ( currentTheme ) ? currentTheme : "neo" ;
880+ window . localStorage . setItem ( THEME_STORAGE_KEY , theme ) ;
881+ const href = link . getAttribute ( "href" ) ;
882+ if ( href ) {
883+ link . setAttribute ( "href" , applyThemeToUrl ( href , theme ) ) ;
884+ }
885+ } catch ( error ) {
886+ // Ignore storage/link update failures.
887+ }
888+ } ) ;
889+ } ) ;
890+ }
891+
852892function spawnBlackflagShot ( startX , startY , side , targetX = null , targetY = null ) {
853893 const bullet = document . createElement ( "span" ) ;
854894 bullet . className = "gun-bullet" ;
@@ -1732,6 +1772,7 @@ function initPersonaQuiz() {
17321772
17331773initPenguinDateBadge ( ) ;
17341774initThemeSwitcher ( ) ;
1775+ initNavThemeGuard ( ) ;
17351776initHeroTypewriters ( ) ;
17361777initBlackflagGunfire ( ) ;
17371778initRuntimeCompatibility ( ) ;
0 commit comments