@@ -12,28 +12,41 @@ document.addEventListener("DOMContentLoaded", function() {
1212 var expandSign = document . createElement ( 'span' ) ;
1313 expandSign . style . cursor = 'pointer' ; // Make it look clickable
1414
15- // Check if this is the "Learn the Basics" section
16- if ( link . textContent . trim ( ) === 'Learn the Basics' ) {
17- nestedList . style . display = 'block' ; // Expand the "Learn the Basics" section
15+ // Use the link text as a unique key for localStorage
16+ var sectionKey = 'section_' + link . textContent . trim ( ) . replace ( / \s + / g, '_' ) ;
17+
18+ // Retrieve the saved state from localStorage
19+ var isExpanded = localStorage . getItem ( sectionKey ) ;
20+
21+ // If no state is saved, default to expanded for "Learn the Basics" and collapsed for others
22+ if ( isExpanded === null ) {
23+ isExpanded = ( link . textContent . trim ( ) === 'Learn the Basics' ) ? 'true' : 'false' ;
24+ localStorage . setItem ( sectionKey , isExpanded ) ;
25+ }
26+
27+ if ( isExpanded === 'true' ) {
28+ nestedList . style . display = 'block' ; // Expand the section
1829 expandSign . textContent = '[-] ' ; // Show "[-]" since it's expanded
1930 } else {
20- nestedList . style . display = 'none' ; // Collapse other sections
31+ nestedList . style . display = 'none' ; // Collapse the section
2132 expandSign . textContent = '[+] ' ; // Show "[+]" since it's collapsed
2233 }
2334
24- // Insert the sign before the link
25- link . parentNode . insertBefore ( expandSign , link ) ;
26-
2735 // Add a click event to toggle the nested list
2836 expandSign . addEventListener ( 'click' , function ( ) {
2937 if ( nestedList . style . display === 'none' ) {
3038 nestedList . style . display = 'block' ;
3139 expandSign . textContent = '[-] ' ; // Change to "[-]" when expanded
40+ localStorage . setItem ( sectionKey , 'true' ) ; // Save state
3241 } else {
3342 nestedList . style . display = 'none' ;
3443 expandSign . textContent = '[+] ' ; // Change back to "[+]" when collapsed
44+ localStorage . setItem ( sectionKey , 'false' ) ; // Save state
3545 }
3646 } ) ;
47+
48+ // Insert the sign before the link
49+ link . parentNode . insertBefore ( expandSign , link ) ;
3750 }
3851 } ) ;
3952} ) ;
0 commit comments