@@ -398,21 +398,48 @@ if (treeview) {
398398 init_expand_state ( ) ;
399399}
400400
401- function update_folder_counts ( ) {
402- const folders = document . querySelectorAll ( '.tree-toggle[data-path]' ) ;
401+ function number_format ( number , decimals = 0 ) {
402+ let parts = parseFloat ( number ) . toFixed ( decimals ) . split ( '.' ) ;
403+ parts [ 0 ] = parts [ 0 ] . replace ( / \B (? = ( \d { 3 } ) + (? ! \d ) ) / g, thousandssep ) ;
404+ return parts . join ( decimalsep ) ;
405+ }
406+
407+ function format_bytes ( bytes , decimals = 2 ) {
408+ if ( bytes > 1048576 ) {
409+ return number_format ( bytes / 1048576 , decimals ) + 'MB' ;
410+ }
411+
412+ if ( bytes > 1024 ) {
413+ return number_format ( bytes / 1024 , decimals ) + 'KB' ;
414+ }
403415
404- folders . forEach ( folder => {
405- const path = folder . getAttribute ( 'data-path' ) ;
406- const tree_children = document . querySelector ( `.tree-children[data-path="${ path } "]` ) ;
407- const children_count = tree_children ? tree_children . querySelectorAll ( '.keywrapper' ) . length : 0 ;
408- const items_count = folder . parentElement . querySelector ( '.items-count' ) ;
416+ return number_format ( bytes , decimals ) + 'B' ;
417+ }
409418
410- if ( items_count ) {
411- items_count . textContent = `(${ children_count } )` ;
419+ function update_folder_counts ( ) {
420+ document . querySelectorAll ( '.tree-toggle' ) . forEach ( folder => {
421+ const children_wrapper = folder . closest ( '.tree-group' ) . querySelector ( '.tree-children' ) ;
422+
423+ if ( children_wrapper ) {
424+ const total_items = children_wrapper . querySelectorAll ( '.keywrapper' ) . length ;
425+ let total_bytes = 0 ;
426+ children_wrapper . querySelectorAll ( '.file-size' ) . forEach ( el => {
427+ const bytes = parseFloat ( el . getAttribute ( 'data-bytes' ) ) || 0 ;
428+ total_bytes += bytes ;
429+ } ) ;
430+
431+ const items_count_span = folder . parentElement . querySelector ( '.items-count' ) ;
432+ if ( items_count_span ) {
433+ items_count_span . textContent = `(${ total_items } items, ${ format_bytes ( total_bytes ) } )` ;
434+ }
412435 }
413436 } ) ;
414437}
415438
439+ document . addEventListener ( 'DOMContentLoaded' , ( ) => {
440+ update_folder_counts ( ) ;
441+ } ) ;
442+
416443/**
417444 * Light / Dark mode
418445 */
0 commit comments