@@ -5,7 +5,7 @@ const companies = [
55 'Adobe' , 'Apple' , 'Bloomberg' , 'Cisco' , 'Facebook' , 'Google' , 'Microsoft' , 'Spotify'
66] ;
77
8- function main ( ) {
8+ async function main ( ) {
99 chrome . storage . local . get ( 'clickedCompany' , function ( data : { [ key : string ] : any ; } ) {
1010 companyName = data . clickedCompany ;
1111 const title : HTMLElement | null = document . getElementById ( 'title' ) ;
@@ -19,6 +19,7 @@ function main() {
1919 document . getElementById ( 'Score' ) ?. addEventListener ( 'click' , ( ) => sortBy ( 'Score' ) ) ;
2020
2121 addNavbarLinks ( ) ;
22+ await addCompaniesToSelect ( ) ;
2223}
2324
2425function addNavbarLinks ( ) {
@@ -61,11 +62,10 @@ function addNavbarLinks() {
6162 button . appendChild ( companyName ) ;
6263
6364 navbar ?. appendChild ( button ) ;
65+
6466 } ) ;
6567}
6668
67-
68-
6969interface Company {
7070 name : string ;
7171 score : number ;
@@ -127,6 +127,39 @@ function addCompanyProblems(sortMethod: string) {
127127 } ) ;
128128}
129129
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+
130163function sortBy ( column : string ) {
131164 if ( column === 'Score' ) {
132165 solutions . sort ( ( a , b ) => b . score - a . score ) ;
0 commit comments