Skip to content

Commit 9df2e0c

Browse files
committed
fix ts errors
1 parent f70eba5 commit 9df2e0c

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

src/content-script/update-description.ts

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,20 @@
33
function showExamples() {
44
chrome.storage.local.get(['showExamples'], (result) => {
55
let showExamples = result.showExamples;
6-
let descriptionContainer = document.querySelector('div._1l1MA');
6+
let descriptionContainer = document.querySelector('div._1l1MA') as Element;
77
if (!descriptionContainer) {
88
return;
99
}
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);
1317
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';
1520
}
1621
}
1722
});
@@ -53,14 +58,22 @@ function loadCompanyTags(problemTitle: string) {
5358
}
5459
descriptionBtns.parentElement?.appendChild(companyTagContainer);
5560

61+
interface problem {
62+
title: string;
63+
companies: Array<{
64+
name: string;
65+
score: number;
66+
}>;
67+
}
68+
5669
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);
5871
if (problem.companies && problem.companies.length > 0) {
5972
// slice the array to get only the first five companies
6073
const topCompanies = problem.companies.slice(0, 5);
6174

6275
// create a button for each company
63-
topCompanies.forEach(company => {
76+
topCompanies.forEach((company: { name: string; score: any; }) => {
6477
const button = document.createElement('button');
6578
button.style.display = 'flex';
6679
button.style.alignItems = 'center'; // align items vertically in the center
@@ -95,7 +108,7 @@ function loadCompanyTags(problemTitle: string) {
95108
});
96109
}
97110
});
98-
descriptionBtns.parentElement.appendChild(companyTagContainer);
111+
if (descriptionBtns.parentElement) descriptionBtns.parentElement.appendChild(companyTagContainer);
99112
return companyTagContainer;
100113
}
101114

0 commit comments

Comments
 (0)