@@ -20,33 +20,86 @@ function createStyledButton(text: string, isActive: boolean = false): HTMLButton
2020 button . classList . add ( 'nav-button' ) ;
2121 if ( isActive ) button . classList . add ( 'active' ) ;
2222
23- chrome . storage . local . get ( [ 'isDarkTheme' ] , ( result ) => {
24- const isDark = result . isDarkTheme ;
25- button . style . backgroundColor = isDark ? '#2d2d2d' : '#f3f4f5' ;
26- button . style . color = isDark ? '#e6e6e6' : '#2d2d2d' ;
27- button . style . border = `1px solid ${ isDark ? 'rgba(255, 255, 255, 0.15)' : 'rgba(0, 0, 0, 0.15)' } ` ;
28- button . style . fontWeight = '500' ;
23+ const updateButtonStyles = ( isDark : boolean , isButtonActive : boolean ) => {
24+ // Light theme colors
25+ const lightTheme = {
26+ base : '#f3f4f5' ,
27+ active : '#e0e0e0' ,
28+ hover : '#e6e6e6' ,
29+ border : 'rgba(0, 0, 0, 0.15)' ,
30+ activeBorder : '#f3f4f5' ,
31+ hoverBorder : 'rgba(0, 0, 0, 0.25)' ,
32+ text : '#2d2d2d'
33+ } ;
34+
35+ // Dark theme colors
36+ const darkTheme = {
37+ base : '#2d2d2d' ,
38+ active : '#404040' ,
39+ hover : '#3d3d3d' ,
40+ border : 'rgba(255, 255, 255, 0.15)' ,
41+ activeBorder : '#2d2d2d' ,
42+ hoverBorder : 'rgba(255, 255, 255, 0.25)' ,
43+ text : '#e6e6e6'
44+ } ;
45+
46+ const theme = isDark ? darkTheme : lightTheme ;
47+
48+ button . style . backgroundColor = isButtonActive ? theme . active : theme . base ;
49+ button . style . color = theme . text ;
50+ button . style . border = `1px solid ${ isButtonActive ? theme . activeBorder : theme . border } ` ;
51+ button . style . boxShadow = isButtonActive ? `0 0 0 1px ${ theme . activeBorder } ` : 'none' ;
2952
53+ // Remove existing listeners
54+ const oldMouseEnter = button . onmouseenter ;
55+ const oldMouseLeave = button . onmouseleave ;
56+ if ( oldMouseEnter ) button . removeEventListener ( 'mouseenter' , oldMouseEnter ) ;
57+ if ( oldMouseLeave ) button . removeEventListener ( 'mouseleave' , oldMouseLeave ) ;
58+
59+ // Add new theme-aware listeners
3060 button . addEventListener ( 'mouseenter' , ( ) => {
3161 if ( ! button . classList . contains ( 'active' ) ) {
32- button . style . backgroundColor = isDark ? '#3d3d3d' : '#e6e6e6' ;
33- button . style . borderColor = isDark ? 'rgba(255, 255, 255, 0.25)' : 'rgba(0, 0, 0, 0.25)' ;
62+ button . style . backgroundColor = theme . hover ;
63+ button . style . borderColor = theme . hoverBorder ;
3464 }
3565 } ) ;
66+
3667 button . addEventListener ( 'mouseleave' , ( ) => {
3768 if ( ! button . classList . contains ( 'active' ) ) {
38- button . style . backgroundColor = isDark ? '#2d2d2d' : '#f3f4f5' ;
39- button . style . borderColor = isDark ? 'rgba(255, 255, 255, 0.15)' : 'rgba(0, 0, 0, 0.15)' ;
69+ button . style . backgroundColor = theme . base ;
70+ button . style . borderColor = theme . border ;
71+ } else {
72+ button . style . backgroundColor = theme . active ;
73+ button . style . borderColor = theme . activeBorder ;
4074 }
4175 } ) ;
76+ } ;
4277
43- if ( isActive ) {
44- button . style . backgroundColor = isDark ? '#404040' : '#e0e0e0' ;
45- button . style . color = isDark ? '#ffffff' : '#000000' ;
46- button . style . borderColor = isDark ? 'rgba(255, 255, 255, 0.3)' : 'rgba(0, 0, 0, 0.3)' ;
78+ // Initial style setup
79+ chrome . storage . local . get ( [ 'isDarkTheme' ] , ( result ) => {
80+ updateButtonStyles ( result . isDarkTheme , isActive ) ;
81+ } ) ;
82+
83+ // Listen for theme changes
84+ chrome . storage . onChanged . addListener ( ( changes ) => {
85+ if ( changes . isDarkTheme ) {
86+ updateButtonStyles ( changes . isDarkTheme . newValue , button . classList . contains ( 'active' ) ) ;
4787 }
4888 } ) ;
4989
90+ // Update styles when active state changes
91+ const observer = new MutationObserver ( ( mutations ) => {
92+ mutations . forEach ( ( mutation ) => {
93+ if ( mutation . type === 'attributes' && mutation . attributeName === 'class' ) {
94+ chrome . storage . local . get ( [ 'isDarkTheme' ] , ( result ) => {
95+ updateButtonStyles ( result . isDarkTheme , button . classList . contains ( 'active' ) ) ;
96+ } ) ;
97+ }
98+ } ) ;
99+ } ) ;
100+
101+ observer . observe ( button , { attributes : true } ) ;
102+
50103 button . style . width = '120px' ;
51104 button . style . padding = '4px 8px' ;
52105 button . style . margin = '0 8px' ;
@@ -252,7 +305,8 @@ function showContent(type: 'Discussion' | 'Video' | 'Code') {
252305 // Update button states
253306 const buttons = document . querySelectorAll ( '.nav-button' ) ;
254307 buttons . forEach ( button => {
255- if ( button . textContent === type ) {
308+ const isActive = button . textContent === type ;
309+ if ( isActive ) {
256310 button . classList . add ( 'active' ) ;
257311 } else {
258312 button . classList . remove ( 'active' ) ;
0 commit comments