1
- const solutions = [ ] as { id : number , title : string , score : number , url : string } [ ] ;
1
+ const solutions = [ ] as { id : number , title : string , url : string } [ ] ;
2
2
3
3
let companyName = 'Amazon' ;
4
4
const companies = [
@@ -16,9 +16,13 @@ async function main() {
16
16
17
17
document . getElementById ( '#' ) ?. addEventListener ( 'click' , ( ) => sortBy ( '#' ) ) ;
18
18
document . getElementById ( 'Title' ) ?. addEventListener ( 'click' , ( ) => sortBy ( 'Title' ) ) ;
19
- document . getElementById ( 'Score' ) ?. addEventListener ( 'click' , ( ) => sortBy ( 'Score' ) ) ;
20
19
document . getElementById ( 'Difficulty' ) ?. addEventListener ( 'click' , ( ) => sortBy ( 'Difficulty' ) ) ;
21
20
document . getElementById ( 'Frequency' ) ?. addEventListener ( 'click' , ( ) => sortBy ( 'Frequency' ) ) ;
21
+ document . getElementById ( 'dateSelect' ) ?. addEventListener ( 'change' , ( event ) => {
22
+ const selectedFrequency = ( event . target as HTMLSelectElement ) . value ;
23
+ updateFrequency ( selectedFrequency ) ;
24
+ } ) ;
25
+
22
26
23
27
addNavbarLinks ( ) ;
24
28
await addCompaniesToSelect ( ) ;
@@ -68,9 +72,44 @@ function addNavbarLinks() {
68
72
} ) ;
69
73
}
70
74
75
+ function updateFrequency ( selectedFrequency : string ) {
76
+ // Clear the existing table
77
+ const table = document . getElementById ( 'solutionTable' ) as HTMLTableElement ;
78
+ while ( table . rows . length > 1 ) {
79
+ table . deleteRow ( 1 ) ;
80
+ }
81
+
82
+ // Update the frequency values in the solutions array
83
+ solutions . forEach ( ( solution , index ) => {
84
+ chrome . storage . local . get ( 'companyProblems' , function ( data ) {
85
+ const companyProblems = data . companyProblems [ companyName ] ;
86
+ if ( Array . isArray ( companyProblems ) ) {
87
+ solution . frequency = companyProblems [ index ] [ selectedFrequency ] ;
88
+ }
89
+ } ) ;
90
+ } ) ;
91
+
92
+ // Rebuild the table with updated frequency values
93
+ solutions . forEach ( ( solution ) => {
94
+ const row = table . insertRow ( - 1 ) ;
95
+ row . insertCell ( 0 ) . innerText = solution . id . toString ( ) ;
96
+ row . insertCell ( 1 ) . innerHTML = `<a href="${ solution . url } " target="_blank">${ solution . title } </a>` ;
97
+
98
+ // Add frequency as a bar
99
+ const frequencyCell = row . insertCell ( 2 ) ;
100
+ const bar = document . createElement ( 'div' ) ;
101
+ const width = ( ( solution . frequency - minFrequency ) / ( maxFrequency - minFrequency ) ) * 100 ;
102
+ bar . style . width = width + '%' ;
103
+ bar . style . height = '10px' ;
104
+ bar . style . backgroundColor = 'lightgreen' ;
105
+ bar . style . borderRadius = '10px' ;
106
+ frequencyCell . appendChild ( bar ) ;
107
+ } ) ;
108
+ }
109
+
110
+
71
111
interface Company {
72
112
name : string ;
73
- score : number ;
74
113
}
75
114
76
115
interface Question {
@@ -109,7 +148,6 @@ function addCompanyProblems(sortMethod: string) {
109
148
solutions . push ( {
110
149
id : problem . id ,
111
150
title : problem . title ,
112
- // score: company.score, // Adjust this as needed
113
151
url : `https://leetcode.com/problems/${ problem . title . replace ( / \s / g, '-' ) } /` ,
114
152
frequency : problem . freq_alltime ,
115
153
// acceptance: company.acceptance, // Adjust this as needed
@@ -121,10 +159,6 @@ function addCompanyProblems(sortMethod: string) {
121
159
122
160
const table = document . getElementById ( 'solutionTable' ) as HTMLTableElement ;
123
161
124
- if ( sortMethod === 'Score' ) {
125
- solutions . sort ( ( a , b ) => b . score - a . score ) ;
126
- }
127
-
128
162
solutions . forEach ( solution => {
129
163
const row = table . insertRow ( - 1 ) ;
130
164
// add id
@@ -143,40 +177,6 @@ function addCompanyProblems(sortMethod: string) {
143
177
bar . style . borderRadius = '10px' ;
144
178
frequencyCell . appendChild ( bar ) ;
145
179
}
146
-
147
- // add difficulty
148
- // const difficultyCell = row.insertCell(1);
149
- // let innerText = '';
150
- // if (solution.difficulty === 1) {
151
- // innerText = 'Easy';
152
- // }
153
- // else if (solution.difficulty === 2) {
154
- // innerText = 'Medium';
155
- // }
156
- // else if (solution.difficulty === 3) {
157
- // innerText = 'Hard';
158
- // }
159
- // difficultyCell.innerText = innerText;
160
- // difficultyCell.style.color = color;
161
-
162
-
163
- // add score
164
- // const scoreCell = row.insertCell(2);
165
- // scoreCell.innerText = solution.score.toString();
166
-
167
- // add acceptance
168
- // if (solution.acceptance) {
169
- // const acceptanceCell = row.insertCell(5);
170
- // acceptanceCell.innerText = solution.acceptance.toString();
171
- // acceptanceCell.style.color = color;
172
- // }
173
-
174
- // add frequency
175
- // if (solution.frequency) {
176
- // const frequencyCell = row.insertCell(4);
177
- // frequencyCell.innerText = solution.frequency.toString();
178
- // frequencyCell.style.color = color;
179
- // }
180
180
} ) ;
181
181
} ) ;
182
182
}
@@ -225,7 +225,6 @@ async function addCompaniesToSelect() {
225
225
const sortOrders = {
226
226
'#' : false ,
227
227
'Title' : false ,
228
- 'Score' : false ,
229
228
'Frequency' : false ,
230
229
} ;
231
230
0 commit comments