@@ -270,7 +270,8 @@ function populate_route_table(relevant_vehicles, tbody, table_cell) {
270270 const btns = [ ] ;
271271 for ( const vehicle of relevant_vehicles ) {
272272 const btn = document . createElement ( 'button' ) ;
273- btn . classList . add ( 'vehicle-btn' , 'btn' , 'btn-outline-dark' , 'btn-sm' ) ;
273+ const btn_main_class = is_dark_theme ( ) ? 'btn-outline-light' : 'btn-outline-dark' ;
274+ btn . classList . add ( 'vehicle-btn' , 'btn' , btn_main_class , 'btn-sm' ) ;
274275 btn . addEventListener ( 'click' , ( e ) => {
275276 zoom_to_vehicle ( vehicle . cgm_id ) ;
276277 } ) ;
@@ -282,7 +283,7 @@ function populate_route_table(relevant_vehicles, tbody, table_cell) {
282283 btn . setAttribute ( 'data-cgm-id' , vehicle . cgm_id ) ;
283284 if ( vehicle . is_unexpected ) {
284285 btn . classList . add ( 'btn-warning' ) ;
285- btn . classList . remove ( 'btn-outline-dark' ) ;
286+ btn . classList . remove ( btn_main_class ) ;
286287 btn . setAttribute ( 'data-is-unexpected' , 'true' ) ;
287288 tbody . setAttribute ( 'data-unexpected' , 'true' ) ;
288289 }
@@ -396,4 +397,46 @@ function init_settings() {
396397 const virtual_board_show_relative = get_setting ( 'stop_time_style' ) === 'absolute' ;
397398 const check_el = document . querySelector ( '#virtual_board_show_relative' ) ;
398399 check_el . toggleAttribute ( 'checked' , virtual_board_show_relative ) ;
400+
401+ const theme = get_setting ( 'theme' ) || 'auto' ;
402+ apply_theme ( theme ) ;
403+ const theme_radios = document . querySelectorAll ( 'input[name="theme"]' ) ;
404+ theme_radios . forEach ( radio => {
405+ radio . toggleAttribute ( 'checked' , radio . value === theme ) ;
406+ radio . addEventListener ( 'change' , ( e ) => {
407+ if ( e . target . checked ) {
408+ set_setting ( 'theme' , e . target . value ) ;
409+ apply_theme ( e . target . value ) ;
410+ }
411+ } ) ;
412+ } ) ;
413+ }
414+
415+ function apply_theme ( theme ) {
416+ const html_el = document . querySelector ( 'html' ) ;
417+ html_el . classList . remove ( 'light-theme' , 'dark-theme' ) ;
418+ const affected_btns = document . querySelectorAll ( '.btn-outline-dark, .btn-outline-light' ) ;
419+ let final_theme = theme ;
420+ if ( theme === 'auto' ) {
421+ const prefers_dark = window . matchMedia && window . matchMedia ( '(prefers-color-scheme: dark)' ) . matches ;
422+ final_theme = prefers_dark ? 'dark' : 'light' ;
423+ }
424+ html_el . setAttribute ( 'data-bs-theme' , final_theme ) ;
425+ affected_btns . forEach ( btn => {
426+ btn . classList . toggle ( 'btn-outline-light' , final_theme === 'dark' ) ;
427+ btn . classList . toggle ( 'btn-outline-dark' , final_theme === 'light' ) ;
428+ } ) ;
399429}
430+
431+ export function is_dark_theme ( ) {
432+ const theme = get_setting ( 'theme' ) ;
433+ if ( theme === 'dark' ) {
434+ return true ;
435+ }
436+ else if ( theme === 'light' ) {
437+ return false ;
438+ }
439+ else {
440+ return window . matchMedia && window . matchMedia ( '(prefers-color-scheme: dark)' ) . matches ;
441+ }
442+ }
0 commit comments