@@ -92,7 +92,6 @@ let minFrequency = Number.MAX_SAFE_INTEGER;
9292let maxFrequency = 0 ;
9393
9494
95-
9695async function updateFrequency ( selectedFrequency : string ) {
9796 // Clear the existing table
9897 const table = document . getElementById ( 'solutionTable' ) as HTMLTableElement ;
@@ -237,6 +236,56 @@ function rebuildTable() {
237236 } ) ;
238237}
239238
239+ async function addCompaniesToSelect ( ) {
240+ const companySearch = document . getElementById ( 'companySearch' ) as HTMLInputElement ;
241+ const companyList = document . getElementById ( 'companyList' ) as HTMLDataListElement ;
242+ let companies = [ ] ;
243+
244+ const data = await new Promise < { companyProblems : any } > ( ( resolve ) => {
245+ chrome . storage . local . get ( 'companyProblems' , function ( data ) {
246+ resolve ( data ) ;
247+ } ) ;
248+ } ) ;
249+
250+ const companyProblems = data . companyProblems ;
251+ // Add all the keys to the set
252+ Object . keys ( companyProblems ) . forEach ( ( company ) => {
253+ if ( company ) {
254+ companies . push ( company ) ;
255+ }
256+ } ) ;
257+
258+ // Event when the "Enter" key is pressed or an option is selected from the dropdown
259+ const handleSelection = ( ) => {
260+ const inputValue = companySearch . value ;
261+ // Find the selected company in a case-insensitive manner
262+ const selectedCompany = Array . from ( companies ) . find (
263+ ( company ) => company . toLowerCase ( ) === inputValue . toLowerCase ( )
264+ ) ;
265+ if ( selectedCompany ) {
266+ chrome . storage . local . set ( { clickedCompany : selectedCompany } , ( ) => {
267+ location . reload ( ) ;
268+ } ) ;
269+ }
270+ } ;
271+
272+ companySearch . addEventListener ( 'keydown' , ( event ) => {
273+ if ( event . key === 'Enter' ) {
274+ handleSelection ( ) ;
275+ }
276+ } ) ;
277+
278+ companySearch . addEventListener ( 'change' , handleSelection ) ;
279+
280+ const sortedCompanies = companies . sort ( ) ;
281+
282+ sortedCompanies . forEach ( ( company ) => {
283+ const option = document . createElement ( 'option' ) ;
284+ option . value = company ;
285+ companyList . appendChild ( option ) ;
286+ } ) ;
287+ }
288+
240289
241290// Keep track of the sorting order for each column
242291const sortOrders = {
0 commit comments