@@ -12,28 +12,41 @@ document.addEventListener("DOMContentLoaded", function() {
12
12
var expandSign = document . createElement ( 'span' ) ;
13
13
expandSign . style . cursor = 'pointer' ; // Make it look clickable
14
14
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
18
29
expandSign . textContent = '[-] ' ; // Show "[-]" since it's expanded
19
30
} else {
20
- nestedList . style . display = 'none' ; // Collapse other sections
31
+ nestedList . style . display = 'none' ; // Collapse the section
21
32
expandSign . textContent = '[+] ' ; // Show "[+]" since it's collapsed
22
33
}
23
34
24
- // Insert the sign before the link
25
- link . parentNode . insertBefore ( expandSign , link ) ;
26
-
27
35
// Add a click event to toggle the nested list
28
36
expandSign . addEventListener ( 'click' , function ( ) {
29
37
if ( nestedList . style . display === 'none' ) {
30
38
nestedList . style . display = 'block' ;
31
39
expandSign . textContent = '[-] ' ; // Change to "[-]" when expanded
40
+ localStorage . setItem ( sectionKey , 'true' ) ; // Save state
32
41
} else {
33
42
nestedList . style . display = 'none' ;
34
43
expandSign . textContent = '[+] ' ; // Change back to "[+]" when collapsed
44
+ localStorage . setItem ( sectionKey , 'false' ) ; // Save state
35
45
}
36
46
} ) ;
47
+
48
+ // Insert the sign before the link
49
+ link . parentNode . insertBefore ( expandSign , link ) ;
37
50
}
38
51
} ) ;
39
52
} ) ;
0 commit comments