Skip to content

Commit 9968bf1

Browse files
committed
remove the open solutions btn that we added to the descriptions tab
1 parent 8f0f9aa commit 9968bf1

File tree

1 file changed

+51
-47
lines changed

1 file changed

+51
-47
lines changed

src/content-script/update-description.ts

Lines changed: 51 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,69 @@
11

2-
// shows the examples if the user has enabled the option
2+
// shows the Leetcode examples if the user has enabled it in the settings
33
function showExamples() {
44
chrome.storage.local.get(['showExamples'], (result) => {
55
let showExamples = result.showExamples;
66
let descriptionContainer = document.querySelector('div._1l1MA');
7-
let style = showExamples ? 'block' : 'none';
87
if (!descriptionContainer) {
98
return;
109
}
1110
let exampleElements = descriptionContainer.getElementsByClassName('example');
1211
if (exampleElements && exampleElements.length > 0) {
1312
let startIndex = Array.from(descriptionContainer.children).indexOf(exampleElements[0].parentNode);
1413
for (let i = startIndex; i < descriptionContainer.children.length; i++) {
15-
descriptionContainer.children[i].style.display = style;
14+
descriptionContainer.children[i].style.display = showExamples ? 'block' : 'none';
1615
}
1716
}
1817
});
1918
}
2019

21-
// TODO : refactor this function
22-
// showCompanyTags shouldnt worry about if its allowed to show the tags or not
23-
// it should only worry about showing the tags
24-
// that logic should be handled by the caller
20+
function loadCompanyTags() {
21+
let companyTags;
22+
chrome.storage.local.get(['leetcodeProblems'], (result) => {
23+
const problem = result.leetcodeProblems.questions.find((problem) => problem.title === problemTitle);
24+
if (problem.companies && problem.companies.length > 0) {
25+
// slice the array to get only the first five companies
26+
const topCompanies = problem.companies.slice(0, 5);
27+
28+
// create a button for each company
29+
topCompanies.forEach(company => {
30+
const button = document.createElement('button');
31+
button.style.display = 'flex';
32+
button.style.alignItems = 'center'; // align items vertically in the center
33+
button.style.justifyContent = 'center'; // align items horizontally in the center
34+
35+
const icon = document.createElement('img');
36+
icon.src = `https://logo.clearbit.com/${company.name.toLowerCase().replace(/\s/g, '')}.com`; // replace spaces with nothing
37+
icon.style.height = '12px';
38+
icon.style.width = '12px';
39+
icon.style.marginRight = '5px'; // some space between the icon and the name
40+
button.appendChild(icon);
41+
42+
button.style.color = '#fff';
43+
button.style.minWidth = '100px';
44+
button.style.height = '25px';
45+
button.style.padding = '1px';
46+
button.style.backgroundColor = '#373737';
47+
button.style.borderRadius = '10px';
48+
button.style.fontSize = '10px';
49+
50+
const companyName = document.createTextNode(`${company.name}`);
51+
button.appendChild(companyName);
52+
53+
const score = document.createElement('span');
54+
score.textContent = ` ${company.score}`;
55+
score.style.fontSize = '12px';
56+
score.style.fontWeight = 'bold';
57+
score.style.fontFamily = 'monospace';
58+
score.style.marginLeft = '5px'; // some space between the name and the score
59+
button.appendChild(score);
60+
companyTagContainer!.appendChild(button);
61+
});
62+
}
63+
});
64+
}
65+
66+
// shows the company tags if the user has enabled it in the settings
2567
function showCompanyTags(problemTitle: string) {
2668
chrome.storage.local.get(['showCompanyTags'], (result) => {
2769
let showCompanyTags = result.showCompanyTags;
@@ -36,9 +78,9 @@ function showCompanyTags(problemTitle: string) {
3678
if (!descriptionBtns) {
3779
return;
3880
}
39-
// Find the old button container or create a new one
81+
82+
// if the company tag container already exists then just show it
4083
if (companyTagContainer) {
41-
// Clear the old content
4284
companyTagContainer.style.display = 'flex';
4385
return;
4486
}
@@ -50,7 +92,6 @@ function showCompanyTags(problemTitle: string) {
5092
companyTagContainer.style.flexDirection = 'row';
5193
companyTagContainer.style.marginTop = '10px';
5294
companyTagContainer.style.gap = '5px';
53-
// add the button container to the main container
5495
descriptionBtns.parentElement?.appendChild(companyTagContainer);
5596

5697
chrome.storage.local.get(['leetcodeProblems'], (result) => {
@@ -98,46 +139,9 @@ function showCompanyTags(problemTitle: string) {
98139
});
99140
}
100141

101-
function showOpenSolutionsBtn() {
102-
let oldBtn = document.getElementById('openSolutionsBtn');
103-
if (oldBtn) {
104-
oldBtn.remove();
105-
}
106-
107-
let openSolutionBtn = document.createElement('button');
108-
openSolutionBtn.id = 'openSolutionsBtn';
109-
openSolutionBtn.style.minWidth = '100px';
110-
openSolutionBtn.style.backgroundColor = '#373737';
111-
openSolutionBtn.style.height = '30px';
112-
openSolutionBtn.style.fontSize = '10px';
113-
openSolutionBtn.style.borderRadius = '10px';
114-
openSolutionBtn.textContent = 'Solution Video';
115-
116-
openSolutionBtn.onmouseover = function () {
117-
openSolutionBtn.style.color = 'orange';
118-
}
119-
openSolutionBtn.onmouseout = function () {
120-
openSolutionBtn.style.color = 'white';
121-
}
122-
123-
openSolutionBtn.onclick = function () {
124-
// If a solutions tab was found, simulate a click on it
125-
let solutionsTabs = document.querySelectorAll('div.relative.flex.h-full.select-none');
126-
if (solutionsTabs.length > 0) {
127-
solutionsTabs[2].click();
128-
} else {
129-
console.log('No solutions tab found');
130-
}
131-
};
132-
}
133-
134142
chrome.runtime.onMessage.addListener((request) => {
135143
if (request.action === 'updateDescription') {
136144
showExamples();
137145
showCompanyTags(request.title.split('-')[0].trim());
138146
}
139-
140-
if (request.action === 'toggleShowExamples') {
141-
142-
}
143147
});

0 commit comments

Comments
 (0)