@@ -90,6 +90,7 @@ async function update_stop_times(stop_code) {
9090 const old_tbody = panel . querySelector ( 'tbody' ) ;
9191 if ( old_tbody ) {
9292 old_tbody . replaceWith ( new_tbody ) ;
93+ refresh_stop_times ( ) ;
9394 }
9495 refresh_btn . disabled = false ;
9596 last_updated_el . setAttribute ( 'data-timestamp' , ( Date . now ( ) / 1000 ) . toString ( ) ) ;
@@ -144,6 +145,32 @@ async function load_stop_times(stop_code) {
144145 return data . routes ;
145146}
146147
148+ function refresh_stop_times ( style ) {
149+ if ( ! style ) {
150+ style = localStorage . getItem ( 'livemap_stop_time_style' ) || 'relative' ;
151+ }
152+ localStorage . setItem ( 'livemap_stop_time_style' , style ) ;
153+ const panel = document . querySelector ( '#virtual-board-panel' ) ;
154+ const elements = panel . querySelectorAll ( 'span[data-stop-time]' ) ;
155+ const now1 = new Date ( ) ;
156+ const now_hour = now1 . getHours ( ) * 60 ;
157+ const now_minute = now1 . getMinutes ( ) ;
158+ const current_time = now_hour + now_minute ;
159+ for ( const el of elements ) {
160+ const stop_time = Number ( el . getAttribute ( 'data-stop-time' ) ) ;
161+ if ( style == 'relative' ) {
162+ const diff = stop_time - current_time ;
163+ el . textContent = `${ diff } мин.` ;
164+ }
165+ else {
166+ const hour = Math . floor ( stop_time / 60 ) % 24 ;
167+ const minute = ( stop_time % 60 ) . toString ( ) . padStart ( 2 , '0' ) ;
168+ el . textContent = `${ ( hour % 24 ) . toString ( ) . padStart ( 2 , '0' ) } :${ minute } ` ;
169+ }
170+ }
171+ }
172+ window . refresh_stop_times = refresh_stop_times ;
173+
147174function display_stop_times ( stop_routes ) {
148175 function display_hours ( scheduled , actual ) {
149176 if ( scheduled === null ) {
@@ -153,11 +180,8 @@ function display_stop_times(stop_routes) {
153180
154181 const diff_class = 3 < total_diff || total_diff < - 1 ? 'text-danger fw-bold' : 'text-success' ;
155182 const diff_html = `<span class="${ diff_class } text-nowrap">${ total_diff > 0 ? '+' : '' } ${ total_diff == 0 ? 'навреме' : total_diff + ' мин.' } </span>` ;
156-
157- const hour = ( Math . floor ( actual / 60 ) % 24 ) ;
158- const minute = ( actual % 60 ) . toString ( ) . padStart ( 2 , '0' ) ;
159-
160- const actual_formatted = `${ ( hour % 24 ) . toString ( ) . padStart ( 2 , '0' ) } :${ minute } ` ;
183+
184+ const actual_formatted = `<span data-stop-time="${ actual } "></span>` ;
161185
162186 return [ actual_formatted , total_diff === null ? null : diff_html ] ;
163187 }
0 commit comments