@@ -238,6 +238,40 @@ <h2>Top Source User-Agents</h2>
238238 if ( updateHash !== false ) window . location . hash = id ;
239239 if ( id === 'tab-statistics' ) fetchStatistics ( ) ;
240240 }
241+
242+ function fetchStatistics ( ) {
243+ fetch ( '/admin/statistics' ) . then ( function ( r ) { return r . json ( ) ; } ) . then ( function ( data ) {
244+ var tsBody = document . getElementById ( 'topStreamsBody' ) ;
245+ if ( tsBody ) {
246+ tsBody . innerHTML = '' ;
247+ data . top_streams . forEach ( function ( s ) {
248+ var row = document . createElement ( 'tr' ) ;
249+ row . innerHTML = '<td>' + s . MountName + '</td><td>' + s . Name + '</td><td style="font-weight:bold; color:var(--primary)">' + s . ListenersCount + '</td><td>' + s . Bitrate + '</td>' ;
250+ tsBody . appendChild ( row ) ;
251+ } ) ;
252+ }
253+
254+ var tlUABody = document . getElementById ( 'topListenersUABody' ) ;
255+ if ( tlUABody ) {
256+ tlUABody . innerHTML = '' ;
257+ data . top_listeners_ua . forEach ( function ( ua ) {
258+ var row = document . createElement ( 'tr' ) ;
259+ row . innerHTML = '<td>' + ( ua . ua || 'Unknown' ) + '</td><td style="font-weight:bold; color:var(--success)">' + ua . count + '</td>' ;
260+ tlUABody . appendChild ( row ) ;
261+ } ) ;
262+ }
263+
264+ var tsUABody = document . getElementById ( 'topSourcesUABody' ) ;
265+ if ( tsUABody ) {
266+ tsUABody . innerHTML = '' ;
267+ data . top_sources_ua . forEach ( function ( ua ) {
268+ var row = document . createElement ( 'tr' ) ;
269+ row . innerHTML = '<td>' + ( ua . ua || 'Unknown' ) + '</td><td style="font-weight:bold; color:var(--warning)">' + ua . count + '</td>' ;
270+ tsUABody . appendChild ( row ) ;
271+ } ) ;
272+ }
273+ } ) ;
274+ }
241275
242276 // Ensure forms redirect back to the current tab
243277 document . addEventListener ( 'submit' , function ( e ) {
@@ -274,7 +308,6 @@ <h2>Top Source User-Agents</h2>
274308 }
275309
276310 ( function ( ) {
277- if ( window . location . hash ) { var it = window . location . hash . substring ( 1 ) ; if ( document . getElementById ( it ) ) { showTab ( it , false ) ; } }
278311 var canvas = document . getElementById ( 'trafficChart' ) ; var ctx = canvas . getContext ( '2d' ) ;
279312 var outRateEl = document . getElementById ( 'outRate' ) ; var inRateEl = document . getElementById ( 'inRate' ) ;
280313 var streamsBody = document . getElementById ( 'streamsBody' ) ; var rowTemplate = document . getElementById ( 'stream-row-template' ) ;
@@ -391,35 +424,8 @@ <h2>Top Source User-Agents</h2>
391424 } ) ;
392425 document . addEventListener ( 'click' , function ( e ) { if ( e . target . classList . contains ( 'edit-mount' ) ) { document . getElementById ( 'add-mount-path' ) . value = e . target . dataset . mount ; showTab ( 'tab-stations' ) ; document . getElementById ( 'new-mount-pw' ) . focus ( ) ; } } ) ;
393426
394- function fetchStatistics ( ) {
395- fetch ( '/admin/statistics' ) . then ( function ( r ) { return r . json ( ) ; } ) . then ( function ( data ) {
396- var tsBody = document . getElementById ( 'topStreamsBody' ) ;
397- tsBody . innerHTML = '' ;
398- data . top_streams . forEach ( function ( s ) {
399- var row = document . createElement ( 'tr' ) ;
400- row . innerHTML = '<td>' + s . MountName + '</td><td>' + s . Name + '</td><td style="font-weight:bold; color:var(--primary)">' + s . ListenersCount + '</td><td>' + s . Bitrate + '</td>' ;
401- tsBody . appendChild ( row ) ;
402- } ) ;
403-
404- var tlUABody = document . getElementById ( 'topListenersUABody' ) ;
405- tlUABody . innerHTML = '' ;
406- data . top_listeners_ua . forEach ( function ( ua ) {
407- var row = document . createElement ( 'tr' ) ;
408- row . innerHTML = '<td>' + ua . ua + '</td><td style="font-weight:bold; color:var(--success)">' + ua . count + '</td>' ;
409- tlUABody . appendChild ( row ) ;
410- } ) ;
411-
412- var tsUABody = document . getElementById ( 'topSourcesUABody' ) ;
413- tsUABody . innerHTML = '' ;
414- data . top_sources_ua . forEach ( function ( ua ) {
415- var row = document . createElement ( 'tr' ) ;
416- row . innerHTML = '<td>' + ua . ua + '</td><td style="font-weight:bold; color:var(--warning)">' + ua . count + '</td>' ;
417- tsUABody . appendChild ( row ) ;
418- } ) ;
419- } ) ;
420- }
421-
422427 drawChart ( ) ;
428+ if ( window . location . hash ) { var it = window . location . hash . substring ( 1 ) ; if ( document . getElementById ( it ) ) { showTab ( it , false ) ; } }
423429 } ) ( ) ;
424430 </ script >
425431</ body >
0 commit comments