@@ -312,6 +312,8 @@ class PyRadioServer(object):
312312    var url_to_reload = ""; 
313313    var last_title = ""; 
314314
315+     var selection = -1; 
316+ 
315317    function js_refresh_page(){ 
316318        window.location.href = url_to_reload; 
317319    } 
@@ -367,6 +369,9 @@ class PyRadioServer(object):
367369        { 
368370            js_disable_group_button(true); 
369371        } 
372+         // if ( ( the_command == '/html/st' ) || ( the_command == '/html/pl' ) || ( ( the_command.startsWith("/html/pl/" ) && ( the_command.length > 9 )) )){ 
373+         //     js_get_selection(); 
374+         // } 
370375        $.get(the_command, function(result){ 
371376            // console.log(the_command, result, typeof result); 
372377            // 
@@ -416,30 +421,37 @@ class PyRadioServer(object):
416421            } 
417422            // console.log("the_command:", the_command) 
418423            if ( ( the_command == '/html/st' ) || ( the_command == '/html/pl' ) || ( ( the_command.startsWith("/html/pl/" ) && ( the_command.length > 9 )) )){ 
419-             td = document.getElementsByTagName('td'); 
420-             for(i=0; i<td.length; i++){ 
421-                 try{ 
422-                     var x = td[i].getAttribute('style'); 
423-                     // console.log("x =", x); 
424-                     if(i>0){ 
425-                         if(x == "color: white;"){ 
426-                             // console.log("found at", i, "id =", td[i].getAttribute('id')); 
427-                             var this_id = td[i+1].getAttribute('id'); 
428-                             if (i>6){ 
429-                               this_id = "n" + (this_id-2); 
430-                             }else{ 
431-                                 this_id = "myInput"; 
424+                 // console.log("-- selection =", selection); 
425+                 let the_counter = 0; 
426+                 //if (selection > 0){ 
427+                 //    the_counter = 2 * selection; 
428+                 //    console.log("the_counter =", the_counter); 
429+                 //} 
430+                 td = document.getElementsByTagName('td'); 
431+                 for(i=the_counter; i<td.length; i++){ 
432+                     try{ 
433+                         var x = td[i].getAttribute('style'); 
434+                         // console.log("x =", x); 
435+                         if(i>0){ 
436+                             if(x == "color: white;"){ 
437+                                 // console.log("found at", i, "id =", td[i].getAttribute('id')); 
438+                                 var this_id = td[i+1].getAttribute('id'); 
439+                                 if (i>6){ 
440+                                   this_id = "n" + (this_id-2); 
441+                                 }else{ 
442+                                     this_id = "myInput"; 
443+                                 } 
444+                                 // console.log("this_id =", this_id); 
445+                                 document.getElementById(this_id).scrollIntoView(); 
446+                                 break; 
432447                            } 
433-                             // console.log("this_id =", this_id); 
434-                             document.getElementById(this_id).scrollIntoView(); 
435-                             break; 
436448                        } 
449+                     }catch{ 
450+                         // do not care about it! 
437451                    } 
438-                 }catch{ 
439-                     // do not care about it! 
440452                } 
441-             } 
442453        } 
454+         // console.log("--------"); 
443455        }); 
444456    } 
445457
@@ -487,6 +499,21 @@ class PyRadioServer(object):
487499        getStopped(); 
488500    } 
489501
502+     function js_get_selection(){ 
503+         const getSelection = async () => { 
504+             const response = await fetch("/html/get_selection"); 
505+             const data = await response.text(); 
506+             // console.log("async selection:", data); 
507+             if ( data > -1 ){ 
508+                 selection = data; 
509+             }else{ 
510+                 selection = -1; 
511+             } 
512+         } 
513+         getSelection(); 
514+         console.log("==> selection =", selection); 
515+     } 
516+ 
490517    function js_disable_group_button(enable){ 
491518        var element = document.getElementById("group"); 
492519        element.disabled = enable; 
@@ -511,7 +538,7 @@ class PyRadioServer(object):
511538            const response = await fetch("/html/is_logging_titles"); 
512539            const data = await response.text(); 
513540
514-             console.log("async:", data); 
541+             //  console.log("async:", data); 
515542            var element = document.getElementById("logging"); 
516543            if ( data == 0 ){ 
517544                element.className = "btn btn-warning"; 
@@ -668,6 +695,8 @@ def start_remote_control_server(
668695        sel = (self.selection, self.playing) 
669696        ''' 
670697        self .sel  =  sel 
698+         ''' the item to scroll to when displaying list of stations / playlists ''' 
699+         self ._selected  =  - 1 
671700        self .muted  =  muted 
672701        self .lock  =  lock 
673702        try :
@@ -747,6 +776,8 @@ def _handle_client_connection(self, address, request):
747776            self .send_song_title (self .song_title ())
748777        elif  self ._path  ==  '/favicon.ico' :
749778            pass 
779+         elif  self ._path  ==  '/get_selection'  and  self ._is_html :
780+             self ._send_raw (str (self ._selected ))
750781        elif  self ._path  ==  '/is_stopped'  and  self ._is_html :
751782            received  =  self ._commands ['/html_is_stopped' ]()
752783            self ._send_raw (received )
@@ -950,10 +981,11 @@ def _handle_client_connection(self, address, request):
950981                    has_error  =  False 
951982                    if  ret  ==  '/stations' :
952983                        if  self ._is_html :
984+                             self ._selected  =  self .sel ()[1 ]
953985                            self ._send_raw (
954986                                self ._format_html_table (
955987                                self ._list_stations (html = True ), 0 ,
956-                                 sel = self .sel ()[ 1 ] 
988+                                 sel = self ._selected 
957989                                )
958990                            )
959991                        else :
@@ -1121,20 +1153,22 @@ def _handle_client_connection(self, address, request):
11211153                    elif  ret .startswith ('/' ):
11221154                        if  ret  ==  '/stations' :
11231155                            if  self ._is_html :
1156+                                 self ._selected  =  self .sel ()[1 ]
11241157                                self ._send_raw (
11251158                                    self ._format_html_table (
11261159                                        self ._list_stations (html = True ), 0 ,
1127-                                         sel = self .sel ()[ 1 ] 
1160+                                         sel = self ._selected 
11281161                                    )
11291162                                )
11301163                            else :
11311164                                self ._send_text (self ._list_stations ())
11321165                        elif  ret  ==  '/playlists' :
11331166                            if  self ._is_html :
1167+                                 self ._selected  =  self ._get_playlist_id (basename (self .playlist_in_editor ()[:- 4 ]))
11341168                                self ._send_raw (
11351169                                    self ._format_html_table (
11361170                                        self ._list_playlists (html = True ), 1 ,
1137-                                         sel = self ._get_playlist_id ( basename ( self . playlist_in_editor ()[: - 4 ])) 
1171+                                         sel = self ._selected 
11381172                                    )
11391173                                )
11401174                            else :
@@ -1486,7 +1520,7 @@ def _format_html_table(
14861520        Parameters 
14871521        ========== 
14881522        in_list         list of items 
1489-         self             selected item 
1523+         sel              selected item 
14901524        index           type of output (stations / playlist) and URL formatter 
14911525        playlist_index  playist index (only valid if index == 2) 
14921526        ''' 
0 commit comments