@@ -5,7 +5,7 @@ const companies = [
5
5
'Adobe' , 'Apple' , 'Bloomberg' , 'Cisco' , 'Facebook' , 'Google' , 'Microsoft' , 'Spotify'
6
6
] ;
7
7
8
- function main ( ) {
8
+ async function main ( ) {
9
9
chrome . storage . local . get ( 'clickedCompany' , function ( data : { [ key : string ] : any ; } ) {
10
10
companyName = data . clickedCompany ;
11
11
const title : HTMLElement | null = document . getElementById ( 'title' ) ;
@@ -19,6 +19,7 @@ function main() {
19
19
document . getElementById ( 'Score' ) ?. addEventListener ( 'click' , ( ) => sortBy ( 'Score' ) ) ;
20
20
21
21
addNavbarLinks ( ) ;
22
+ await addCompaniesToSelect ( ) ;
22
23
}
23
24
24
25
function addNavbarLinks ( ) {
@@ -61,11 +62,10 @@ function addNavbarLinks() {
61
62
button . appendChild ( companyName ) ;
62
63
63
64
navbar ?. appendChild ( button ) ;
65
+
64
66
} ) ;
65
67
}
66
68
67
-
68
-
69
69
interface Company {
70
70
name : string ;
71
71
score : number ;
@@ -127,6 +127,39 @@ function addCompanyProblems(sortMethod: string) {
127
127
} ) ;
128
128
}
129
129
130
+ async function addCompaniesToSelect ( ) {
131
+ const companySelect = document . getElementById ( 'companySelect' ) as HTMLSelectElement ;
132
+
133
+ let uniqueCompanies = new Set < string > ( ) ;
134
+
135
+ const data = await new Promise < { leetcodeProblems : LeetcodeProblems } > ( resolve => {
136
+ chrome . storage . local . get ( 'leetcodeProblems' , function ( items : { [ key : string ] : any ; } ) {
137
+ resolve ( items as { leetcodeProblems : LeetcodeProblems } ) ;
138
+ } ) ;
139
+ } ) ;
140
+
141
+ data . leetcodeProblems . questions . forEach ( ( question : Question ) => {
142
+ if ( question . companies ) {
143
+ question . companies . forEach ( ( company : Company ) => {
144
+ uniqueCompanies . add ( company . name ) ;
145
+ } ) ;
146
+ }
147
+ } ) ;
148
+
149
+ uniqueCompanies . forEach ( ( company ) => {
150
+ const option = document . createElement ( 'option' ) ;
151
+ option . value = company ;
152
+ option . text = company ;
153
+ companySelect . appendChild ( option ) ;
154
+ } ) ;
155
+
156
+ companySelect . addEventListener ( 'change' , ( ) => {
157
+ chrome . storage . local . set ( { clickedCompany : companySelect . value } , ( ) => {
158
+ location . reload ( ) ;
159
+ } ) ;
160
+ } ) ;
161
+ }
162
+
130
163
function sortBy ( column : string ) {
131
164
if ( column === 'Score' ) {
132
165
solutions . sort ( ( a , b ) => b . score - a . score ) ;
0 commit comments