@@ -17,8 +17,42 @@ function showExamples() {
1717 } ) ;
1818}
1919
20- function loadCompanyTags ( ) {
21- let companyTags ;
20+ // shows the company tags if the user has enabled it in the settings
21+ function showCompanyTags ( problemTitle : string ) {
22+ chrome . storage . local . get ( [ 'showCompanyTags' ] , ( result ) => {
23+ let showCompanyTags = result . showCompanyTags ;
24+ let companyTagContainer = document . getElementById ( 'companyTagContainer' ) ;
25+ if ( ! showCompanyTags ) {
26+ if ( companyTagContainer ) {
27+ companyTagContainer . style . display = 'none' ;
28+ }
29+ return ;
30+ }
31+
32+ // if the company tag container already exists then just show it
33+ if ( companyTagContainer ) {
34+ companyTagContainer . style . display = 'flex' ;
35+ return ;
36+ }
37+ companyTagContainer = loadCompanyTags ( problemTitle ) || null ;
38+ } ) ;
39+ }
40+
41+ function loadCompanyTags ( problemTitle : string ) {
42+ // create a new container for buttons
43+ let companyTagContainer = document . createElement ( 'div' ) ;
44+ companyTagContainer . id = 'companyTagContainer' ; // add an id
45+ companyTagContainer . style . display = 'flex' ;
46+ companyTagContainer . style . flexDirection = 'row' ;
47+ companyTagContainer . style . marginTop = '10px' ;
48+ companyTagContainer . style . gap = '5px' ;
49+
50+ const descriptionBtns = document . querySelectorAll ( 'div.mt-3.flex' ) [ 0 ] ;
51+ if ( ! descriptionBtns ) {
52+ return ;
53+ }
54+ descriptionBtns . parentElement ?. appendChild ( companyTagContainer ) ;
55+
2256 chrome . storage . local . get ( [ 'leetcodeProblems' ] , ( result ) => {
2357 const problem = result . leetcodeProblems . questions . find ( ( problem ) => problem . title === problemTitle ) ;
2458 if ( problem . companies && problem . companies . length > 0 ) {
@@ -61,82 +95,8 @@ function loadCompanyTags() {
6195 } ) ;
6296 }
6397 } ) ;
64- }
65-
66- // shows the company tags if the user has enabled it in the settings
67- function showCompanyTags ( problemTitle : string ) {
68- chrome . storage . local . get ( [ 'showCompanyTags' ] , ( result ) => {
69- let showCompanyTags = result . showCompanyTags ;
70- let companyTagContainer = document . getElementById ( 'companyTagContainer' ) ;
71- if ( ! showCompanyTags ) {
72- if ( companyTagContainer ) {
73- companyTagContainer . style . display = 'none' ;
74- }
75- return ;
76- }
77- const descriptionBtns = document . querySelectorAll ( 'div.mt-3.flex' ) [ 0 ] ;
78- if ( ! descriptionBtns ) {
79- return ;
80- }
81-
82- // if the company tag container already exists then just show it
83- if ( companyTagContainer ) {
84- companyTagContainer . style . display = 'flex' ;
85- return ;
86- }
87-
88- // create a new container for buttons
89- companyTagContainer = document . createElement ( 'div' ) ;
90- companyTagContainer . id = 'companyTagContainer' ; // add an id
91- companyTagContainer . style . display = 'flex' ;
92- companyTagContainer . style . flexDirection = 'row' ;
93- companyTagContainer . style . marginTop = '10px' ;
94- companyTagContainer . style . gap = '5px' ;
95- descriptionBtns . parentElement ?. appendChild ( companyTagContainer ) ;
96-
97- chrome . storage . local . get ( [ 'leetcodeProblems' ] , ( result ) => {
98- const problem = result . leetcodeProblems . questions . find ( ( problem ) => problem . title === problemTitle ) ;
99- if ( problem . companies && problem . companies . length > 0 ) {
100- // slice the array to get only the first five companies
101- const topCompanies = problem . companies . slice ( 0 , 5 ) ;
102-
103- // create a button for each company
104- topCompanies . forEach ( company => {
105- const button = document . createElement ( 'button' ) ;
106- button . style . display = 'flex' ;
107- button . style . alignItems = 'center' ; // align items vertically in the center
108- button . style . justifyContent = 'center' ; // align items horizontally in the center
109-
110- const icon = document . createElement ( 'img' ) ;
111- icon . src = `https://logo.clearbit.com/${ company . name . toLowerCase ( ) . replace ( / \s / g, '' ) } .com` ; // replace spaces with nothing
112- icon . style . height = '12px' ;
113- icon . style . width = '12px' ;
114- icon . style . marginRight = '5px' ; // some space between the icon and the name
115- button . appendChild ( icon ) ;
116-
117- button . style . color = '#fff' ;
118- button . style . minWidth = '100px' ;
119- button . style . height = '25px' ;
120- button . style . padding = '1px' ;
121- button . style . backgroundColor = '#373737' ;
122- button . style . borderRadius = '10px' ;
123- button . style . fontSize = '10px' ;
124-
125- const companyName = document . createTextNode ( `${ company . name } ` ) ;
126- button . appendChild ( companyName ) ;
127-
128- const score = document . createElement ( 'span' ) ;
129- score . textContent = ` ${ company . score } ` ;
130- score . style . fontSize = '12px' ;
131- score . style . fontWeight = 'bold' ;
132- score . style . fontFamily = 'monospace' ;
133- score . style . marginLeft = '5px' ; // some space between the name and the score
134- button . appendChild ( score ) ;
135- companyTagContainer ! . appendChild ( button ) ;
136- } ) ;
137- }
138- } ) ;
139- } ) ;
98+ descriptionBtns . parentElement . appendChild ( companyTagContainer ) ;
99+ return companyTagContainer ;
140100}
141101
142102chrome . runtime . onMessage . addListener ( ( request ) => {
0 commit comments