11chrome . runtime . onMessage . addListener ( ( request ) => {
22 if ( request . action === 'updateDescription' ) {
33
4- // testing some stuff
5-
6- let descriptionContainer = document . getElementById ( 'descriptionContainer' ) ;
7- // remove the <pre> element from the page
8- console . log ( descriptionContainer )
9- // end testing
104
5+ chrome . storage . local . get ( [ 'showExamples' ] , ( result ) => {
6+ let showExamples = true ;
7+ showExamples = result . showExamples ;
8+ if ( ! showExamples ) {
9+ let descriptionContainer = document . querySelector ( 'div._1l1MA' ) ;
10+ if ( descriptionContainer ) {
11+ let exampleElements = descriptionContainer . getElementsByClassName ( 'example' ) ;
12+ if ( exampleElements . length > 0 ) {
13+ let startIndex = Array . from ( descriptionContainer . children ) . indexOf ( exampleElements [ 0 ] . parentNode ) ;
14+ for ( let i = startIndex ; i < descriptionContainer . children . length ; i ++ ) {
15+ descriptionContainer . children [ i ] . style . display = 'none' ;
16+ }
17+ }
18+ }
19+ }
20+ else {
21+ let descriptionContainer = document . querySelector ( 'div._1l1MA' ) ;
22+ if ( descriptionContainer ) {
23+ let exampleElements = descriptionContainer . getElementsByClassName ( 'example' ) ;
24+ if ( exampleElements . length > 0 ) {
25+ let startIndex = Array . from ( descriptionContainer . children ) . indexOf ( exampleElements [ 0 ] . parentNode ) ;
26+ for ( let i = startIndex ; i < descriptionContainer . children . length ; i ++ ) {
27+ descriptionContainer . children [ i ] . style . display = 'block' ;
28+ }
29+ }
30+ }
31+ }
32+ } ) ;
1133
12- chrome . storage . local . get ( [ 'hideTags ' ] , ( result ) => {
13- let canShowCompanyTags = true ;
14- canShowCompanyTags = ! result . hideTags ;
15- if ( canShowCompanyTags ) {
34+ chrome . storage . local . get ( [ 'showCompanyTags ' ] , ( result ) => {
35+ let showCompanyTags = true ;
36+ showCompanyTags = ! result . showCompanyTags ;
37+ if ( showCompanyTags ) {
1638 const title = request . title . split ( '-' ) [ 0 ] . trim ( ) ;
1739 addCompanyTags ( title ) ;
1840 }
@@ -24,7 +46,6 @@ chrome.runtime.onMessage.addListener((request) => {
2446 }
2547 } ) ;
2648
27- const details = document . querySelectorAll ( 'div.mt-3.flex.space-x-4' ) [ 0 ] ;
2849 let oldBtn = document . getElementById ( 'openSolutionsBtn' ) ;
2950 if ( oldBtn ) {
3051 oldBtn . remove ( ) ;
@@ -57,77 +78,74 @@ chrome.runtime.onMessage.addListener((request) => {
5778 console . log ( 'No solutions tab found' ) ;
5879 }
5980 } ;
60- details . appendChild ( openSolutionBtn ) ;
61- }
62- } ) ;
6381
82+ function addCompanyTags ( title : string ) {
83+ const container = document . querySelectorAll ( 'div.mt-3.flex' ) [ 0 ] ;
6484
65- function addCompanyTags ( title : string ) {
66- const container = document . querySelectorAll ( 'div.mt-3.flex' ) [ 0 ] ;
67-
68- if ( ! container ) {
69- return ;
70- }
85+ if ( ! container ) {
86+ return ;
87+ }
7188
72- // Find the old button container or create a new one
73- let buttonContainer = document . getElementById ( 'companyButtonContainer' ) ;
74- if ( buttonContainer ) {
75- // Clear the old content
76- buttonContainer . innerHTML = '' ;
77- } else {
78- // create a new container for buttons
79- buttonContainer = document . createElement ( 'div' ) ;
80- buttonContainer . id = 'companyButtonContainer' ; // add an id
81- buttonContainer . style . display = 'flex' ;
82- buttonContainer . style . flexDirection = 'row' ;
83- buttonContainer . style . marginTop = '10px' ;
84- buttonContainer . style . gap = '5px' ;
85-
86- // add the button container to the main container
87- container . parentElement ?. appendChild ( buttonContainer ) ;
88- }
89+ // Find the old button container or create a new one
90+ let buttonContainer = document . getElementById ( 'companyButtonContainer' ) ;
91+ if ( buttonContainer ) {
92+ // Clear the old content
93+ buttonContainer . innerHTML = '' ;
94+ } else {
95+ // create a new container for buttons
96+ buttonContainer = document . createElement ( 'div' ) ;
97+ buttonContainer . id = 'companyButtonContainer' ; // add an id
98+ buttonContainer . style . display = 'flex' ;
99+ buttonContainer . style . flexDirection = 'row' ;
100+ buttonContainer . style . marginTop = '10px' ;
101+ buttonContainer . style . gap = '5px' ;
102+
103+ // add the button container to the main container
104+ container . parentElement ?. appendChild ( buttonContainer ) ;
105+ }
89106
90- chrome . storage . local . get ( [ 'leetcodeProblems' ] , ( result ) => {
91- const problem = result . leetcodeProblems . questions . find ( ( problem ) => problem . title === title ) ;
92- if ( problem . companies && problem . companies . length > 0 ) {
93-
94- // slice the array to get only the first five companies
95- const topCompanies = problem . companies . slice ( 0 , 5 ) ;
96-
97- // create a button for each company
98- topCompanies . forEach ( company => {
99- const button = document . createElement ( 'button' ) ;
100- button . style . display = 'flex' ;
101- button . style . alignItems = 'center' ; // align items vertically in the center
102- button . style . justifyContent = 'center' ; // align items horizontally in the center
103-
104- const icon = document . createElement ( 'img' ) ;
105- icon . src = `https://logo.clearbit.com/${ company . name . toLowerCase ( ) . replace ( / \s / g, '' ) } .com` ; // replace spaces with nothing
106- icon . style . height = '12px' ;
107- icon . style . width = '12px' ;
108- icon . style . marginRight = '5px' ; // some space between the icon and the name
109- button . appendChild ( icon ) ;
110-
111- button . style . color = '#fff' ;
112- button . style . minWidth = '100px' ;
113- button . style . height = '25px' ;
114- button . style . padding = '1px' ;
115- button . style . backgroundColor = '#373737' ;
116- button . style . borderRadius = '10px' ;
117- button . style . fontSize = '10px' ;
118-
119- const companyName = document . createTextNode ( `${ company . name } ` ) ;
120- button . appendChild ( companyName ) ;
121-
122- const score = document . createElement ( 'span' ) ;
123- score . textContent = ` ${ company . score } ` ;
124- score . style . fontSize = '12px' ;
125- score . style . fontWeight = 'bold' ;
126- score . style . fontFamily = 'monospace' ;
127- score . style . marginLeft = '5px' ; // some space between the name and the score
128- button . appendChild ( score ) ;
129- buttonContainer . appendChild ( button ) ;
107+ chrome . storage . local . get ( [ 'leetcodeProblems' ] , ( result ) => {
108+ const problem = result . leetcodeProblems . questions . find ( ( problem ) => problem . title === title ) ;
109+ if ( problem . companies && problem . companies . length > 0 ) {
110+ // slice the array to get only the first five companies
111+ const topCompanies = problem . companies . slice ( 0 , 5 ) ;
112+
113+ // create a button for each company
114+ topCompanies . forEach ( company => {
115+ const button = document . createElement ( 'button' ) ;
116+ button . style . display = 'flex' ;
117+ button . style . alignItems = 'center' ; // align items vertically in the center
118+ button . style . justifyContent = 'center' ; // align items horizontally in the center
119+
120+ const icon = document . createElement ( 'img' ) ;
121+ icon . src = `https://logo.clearbit.com/${ company . name . toLowerCase ( ) . replace ( / \s / g, '' ) } .com` ; // replace spaces with nothing
122+ icon . style . height = '12px' ;
123+ icon . style . width = '12px' ;
124+ icon . style . marginRight = '5px' ; // some space between the icon and the name
125+ button . appendChild ( icon ) ;
126+
127+ button . style . color = '#fff' ;
128+ button . style . minWidth = '100px' ;
129+ button . style . height = '25px' ;
130+ button . style . padding = '1px' ;
131+ button . style . backgroundColor = '#373737' ;
132+ button . style . borderRadius = '10px' ;
133+ button . style . fontSize = '10px' ;
134+
135+ const companyName = document . createTextNode ( `${ company . name } ` ) ;
136+ button . appendChild ( companyName ) ;
137+
138+ const score = document . createElement ( 'span' ) ;
139+ score . textContent = ` ${ company . score } ` ;
140+ score . style . fontSize = '12px' ;
141+ score . style . fontWeight = 'bold' ;
142+ score . style . fontFamily = 'monospace' ;
143+ score . style . marginLeft = '5px' ; // some space between the name and the score
144+ button . appendChild ( score ) ;
145+ buttonContainer . appendChild ( button ) ;
146+ } ) ;
147+ }
130148 } ) ;
131149 }
132- } ) ;
133- }
150+ }
151+ } ) ;
0 commit comments