|
3 | 3 | function showExamples() { |
4 | 4 | chrome.storage.local.get(['showExamples'], (result) => { |
5 | 5 | let showExamples = result.showExamples; |
6 | | - let descriptionContainer = document.querySelector('div._1l1MA'); |
| 6 | + let descriptionContainer = document.querySelector('div._1l1MA') as Element; |
7 | 7 | if (!descriptionContainer) { |
8 | 8 | return; |
9 | 9 | } |
10 | | - let exampleElements = descriptionContainer.getElementsByClassName('example'); |
11 | | - if (exampleElements && exampleElements.length > 0) { |
12 | | - let startIndex = Array.from(descriptionContainer.children).indexOf(exampleElements[0].parentNode); |
| 10 | + let examples = descriptionContainer.getElementsByClassName('example'); |
| 11 | + if (examples && examples.length > 0) { |
| 12 | + let parent = examples[0].parentNode as Element; |
| 13 | + if (!parent) { |
| 14 | + return; |
| 15 | + } |
| 16 | + let startIndex = Array.from(descriptionContainer.children).indexOf(parent); |
13 | 17 | for (let i = startIndex; i < descriptionContainer.children.length; i++) { |
14 | | - descriptionContainer.children[i].style.display = showExamples ? 'block' : 'none'; |
| 18 | + let child = descriptionContainer.children[i] as HTMLElement; |
| 19 | + child.style.display = showExamples ? 'block' : 'none'; |
15 | 20 | } |
16 | 21 | } |
17 | 22 | }); |
@@ -53,14 +58,22 @@ function loadCompanyTags(problemTitle: string) { |
53 | 58 | } |
54 | 59 | descriptionBtns.parentElement?.appendChild(companyTagContainer); |
55 | 60 |
|
| 61 | + interface problem { |
| 62 | + title: string; |
| 63 | + companies: Array<{ |
| 64 | + name: string; |
| 65 | + score: number; |
| 66 | + }>; |
| 67 | + } |
| 68 | + |
56 | 69 | chrome.storage.local.get(['leetcodeProblems'], (result) => { |
57 | | - const problem = result.leetcodeProblems.questions.find((problem) => problem.title === problemTitle); |
| 70 | + const problem = result.leetcodeProblems.questions.find((problem: problem) => problem.title === problemTitle); |
58 | 71 | if (problem.companies && problem.companies.length > 0) { |
59 | 72 | // slice the array to get only the first five companies |
60 | 73 | const topCompanies = problem.companies.slice(0, 5); |
61 | 74 |
|
62 | 75 | // create a button for each company |
63 | | - topCompanies.forEach(company => { |
| 76 | + topCompanies.forEach((company: { name: string; score: any; }) => { |
64 | 77 | const button = document.createElement('button'); |
65 | 78 | button.style.display = 'flex'; |
66 | 79 | button.style.alignItems = 'center'; // align items vertically in the center |
@@ -95,7 +108,7 @@ function loadCompanyTags(problemTitle: string) { |
95 | 108 | }); |
96 | 109 | } |
97 | 110 | }); |
98 | | - descriptionBtns.parentElement.appendChild(companyTagContainer); |
| 111 | + if (descriptionBtns.parentElement) descriptionBtns.parentElement.appendChild(companyTagContainer); |
99 | 112 | return companyTagContainer; |
100 | 113 | } |
101 | 114 |
|
|
0 commit comments