@@ -182,7 +182,8 @@ function addCompanyProblems(sortMethod: string) {
182
182
}
183
183
184
184
async function addCompaniesToSelect ( ) {
185
- const companySelect = document . getElementById ( 'companySelect' ) as HTMLSelectElement ;
185
+ const companySearch = document . getElementById ( 'companySearch' ) as HTMLInputElement ;
186
+ const companyList = document . getElementById ( 'companyList' ) as HTMLDataListElement ;
186
187
let uniqueCompanies = new Set < string > ( ) ;
187
188
188
189
const data = await new Promise < { leetcodeProblems : LeetcodeProblems } > ( resolve => {
@@ -199,17 +200,46 @@ async function addCompaniesToSelect() {
199
200
}
200
201
} ) ;
201
202
203
+ // Add event listener to the search input
204
+ companySearch . addEventListener ( 'input' , ( ) => {
205
+ // Get the search term
206
+ const searchTerm = companySearch . value . trim ( ) . toLowerCase ( ) ;
207
+
208
+ // Clear the existing options
209
+ companySelect . innerHTML = '' ;
210
+
211
+ // Filter and add the options based on the search term
212
+ sortedCompanies . forEach ( ( company ) => {
213
+ if ( company . toLowerCase ( ) . includes ( searchTerm ) ) {
214
+ const option = document . createElement ( 'option' ) ;
215
+ option . value = company ;
216
+ option . text = company ;
217
+ if ( company === companyName ) {
218
+ option . selected = true ;
219
+ }
220
+ companySelect . appendChild ( option ) ;
221
+ }
222
+ } ) ;
223
+ } ) ;
224
+
225
+ companySearch . addEventListener ( 'keydown' , ( event ) => {
226
+ if ( event . key === 'Enter' ) {
227
+ const selectedCompany = companySearch . value ;
228
+ if ( selectedCompany ) {
229
+ chrome . storage . local . set ( { clickedCompany : selectedCompany } , ( ) => {
230
+ location . reload ( ) ;
231
+ } ) ;
232
+ }
233
+ }
234
+ } ) ;
235
+
202
236
// Convert the Set to an Array and sort it alphabetically
203
237
const sortedCompanies = Array . from ( uniqueCompanies ) . sort ( ) ;
204
238
205
239
sortedCompanies . forEach ( ( company ) => {
206
240
const option = document . createElement ( 'option' ) ;
207
241
option . value = company ;
208
- option . text = company ;
209
- if ( company === companyName ) {
210
- option . selected = true ;
211
- }
212
- companySelect . appendChild ( option ) ;
242
+ companyList . appendChild ( option ) ;
213
243
} ) ;
214
244
215
245
companySelect . addEventListener ( 'change' , ( ) => {
@@ -271,4 +301,4 @@ function sortBy(column: string) {
271
301
}
272
302
273
303
/* Run the script */
274
- main ( ) ;
304
+ main ( ) ;
0 commit comments