@@ -105,57 +105,46 @@ function showDifficulty() {
105
105
} ) ;
106
106
}
107
107
108
- // show the leetcode problem rating if the user has enabled it in the settings
108
+ // show the leetcode problem rating
109
109
function showRating ( problemTitle : string ) {
110
110
// Check if we're on the description tab before proceeding
111
111
const isDescriptionPage = ! window . location . href . includes ( '/solutions' ) ;
112
112
if ( ! isDescriptionPage ) {
113
113
return ;
114
114
}
115
115
116
- chrome . storage . local . get ( [ 'showRating' ] , ( result ) => {
117
- const showRating = result . showRating ;
118
- if ( ! showRating ) {
119
- const ratingElement = document . getElementById ( 'rating' ) ;
120
- if ( ratingElement ) {
121
- ratingElement . remove ( ) ;
122
- }
123
- return ;
124
- }
125
-
126
- chrome . storage . local . get ( [ 'leetcodeProblems' ] , ( result ) => {
127
- const problem = result . leetcodeProblems . questions . find ( ( problem : Problem ) => problem . title === problemTitle ) ;
128
- if ( ! problem ?. rating ) return ;
129
-
130
- let ratingElement = document . getElementById ( 'rating' ) ;
131
- if ( ! ratingElement ) {
132
- ratingElement = document . createElement ( 'div' ) ;
133
- ratingElement . id = 'rating' ;
134
- }
135
-
136
- ratingElement . textContent = problem . rating ;
137
- ratingElement . style . fontSize = '11px' ;
138
- ratingElement . style . letterSpacing = '.5px' ;
139
- ratingElement . style . borderRadius = '6px' ;
140
- ratingElement . style . width = '60px' ;
141
- ratingElement . style . textAlign = 'center' ;
142
- ratingElement . style . padding = '4px 8px' ;
143
- ratingElement . style . transition = 'all 0.2s ease' ;
116
+ chrome . storage . local . get ( [ 'leetcodeProblems' ] , ( result ) => {
117
+ const problem = result . leetcodeProblems . questions . find ( ( problem : Problem ) => problem . title === problemTitle ) ;
118
+ if ( ! problem ?. rating ) return ;
144
119
145
- chrome . storage . local . get ( [ 'isDarkTheme' ] , ( result ) => {
146
- const isDark = result . isDarkTheme ;
147
- if ( ratingElement ) {
148
- ratingElement . style . backgroundColor = isDark ? '#373737' : '#f3f4f5' ;
149
- ratingElement . style . color = isDark ? '#40a9ff' : '#1a1a1a' ;
150
- ratingElement . style . border = `1px solid ${ isDark ? 'rgba(255, 255, 255, 0.1)' : 'rgba(0, 0, 0, 0.1)' } ` ;
151
- }
152
- } ) ;
120
+ let ratingElement = document . getElementById ( 'rating' ) ;
121
+ if ( ! ratingElement ) {
122
+ ratingElement = document . createElement ( 'div' ) ;
123
+ ratingElement . id = 'rating' ;
124
+ }
153
125
154
- const difficultyContainer = document . querySelectorAll ( 'div.relative.inline-flex' ) [ 0 ] as HTMLDivElement ;
155
- if ( difficultyContainer ?. parentElement && ratingElement ) {
156
- difficultyContainer . parentElement . insertBefore ( ratingElement , difficultyContainer . parentElement . firstChild ) ;
126
+ ratingElement . textContent = problem . rating ;
127
+ ratingElement . style . fontSize = '11px' ;
128
+ ratingElement . style . letterSpacing = '.5px' ;
129
+ ratingElement . style . borderRadius = '6px' ;
130
+ ratingElement . style . width = '60px' ;
131
+ ratingElement . style . textAlign = 'center' ;
132
+ ratingElement . style . padding = '4px 8px' ;
133
+ ratingElement . style . transition = 'all 0.2s ease' ;
134
+
135
+ chrome . storage . local . get ( [ 'isDarkTheme' ] , ( result ) => {
136
+ const isDark = result . isDarkTheme ;
137
+ if ( ratingElement ) {
138
+ ratingElement . style . backgroundColor = isDark ? '#373737' : '#f3f4f5' ;
139
+ ratingElement . style . color = isDark ? '#40a9ff' : '#1a1a1a' ;
140
+ ratingElement . style . border = `1px solid ${ isDark ? 'rgba(255, 255, 255, 0.1)' : 'rgba(0, 0, 0, 0.1)' } ` ;
157
141
}
158
142
} ) ;
143
+
144
+ const difficultyContainer = document . querySelectorAll ( 'div.relative.inline-flex' ) [ 0 ] as HTMLDivElement ;
145
+ if ( difficultyContainer ?. parentElement && ratingElement ) {
146
+ difficultyContainer . parentElement . insertBefore ( ratingElement , difficultyContainer . parentElement . firstChild ) ;
147
+ }
159
148
} ) ;
160
149
}
161
150
0 commit comments