Skip to content

Commit 9e46992

Browse files
committed
track the clicked company and display the problems asked sorted by the score
1 parent b1799f0 commit 9e46992

File tree

5 files changed

+106
-24
lines changed

5 files changed

+106
-24
lines changed

src/background/background.ts

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,14 @@ chrome.runtime.onInstalled.addListener(() => {
1111
.catch((error) => {
1212
console.error(error);
1313
});
14+
15+
// Default settings
1416
chrome.storage.local.set({ language: 'python' });
1517
chrome.storage.local.set({ fontSize: 14 });
1618
chrome.storage.local.set({ showCompanyTags: true });
1719
chrome.storage.local.set({ showExamples: true });
1820
chrome.storage.local.set({ showDifficulty: true });
21+
chrome.storage.local.set({ clickedCompany: 'Amazon' })
1922
});
2023

2124
chrome.runtime.onMessage.addListener(
@@ -44,6 +47,28 @@ chrome.runtime.onMessage.addListener(
4447
}
4548
);
4649

50+
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
51+
if (request.action === "openCompanyPage") {
52+
chrome.storage.local.set({ clickedCompany: request.company });
53+
chrome.tabs.create({
54+
url: chrome.runtime.getURL("src/popup/company.html"),
55+
active: true
56+
}, function (tab) {
57+
// Keep a reference to the listener so it can be removed later
58+
let listener = function (tabId, changedProps) {
59+
// When the tab is done loading
60+
if (tabId == tab.id && changedProps.status == "complete") {
61+
chrome.tabs.sendMessage(tabId, request);
62+
// Remove the listener once the tab is loaded
63+
chrome.tabs.onUpdated.removeListener(listener);
64+
}
65+
};
66+
// Attach the listener
67+
chrome.tabs.onUpdated.addListener(listener);
68+
});
69+
}
70+
});
71+
4772
chrome.runtime.onMessage.addListener((request: any) => {
4873
if (request.type === 'OPEN_LOGIN_PAGE') {
4974
chrome.tabs.create({ url: 'https://chat.openai.com' });
@@ -59,22 +84,7 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
5984
}
6085
});
6186

62-
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
63-
if (request.action === "openCompanyPage") {
64-
chrome.tabs.create({
65-
url: chrome.runtime.getURL("src/popup/company.html"),
66-
active: true
67-
}, function (tab) {
68-
chrome.tabs.onUpdated.addListener(function listener(tabId, changedProps) {
69-
// When the tab is done loading
70-
if (tabId == tab.id && changedProps.status == "complete") {
71-
chrome.tabs.sendMessage(tabId, request);
72-
chrome.tabs.onUpdated.removeListener(listener);
73-
}
74-
});
75-
});
76-
}
77-
});
87+
7888

7989

8090
chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {

src/content-script/update-description-tab.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,24 @@ function loadCompanyTags(problemTitle: string, companyTagContainer: HTMLElement)
101101
// create a button for each company
102102
topCompanies.forEach((company: { name: string; score: any; }) => {
103103
const button = document.createElement('button');
104+
104105
// opens the company page when the button is clicked
105106
button.onclick = () => {
106107
chrome.runtime.sendMessage({
107108
// passes the company name and score to the background script
108-
action: 'openCompanyPage', company: company
109+
action: 'openCompanyPage', company: company.name
109110
})
110111
}
111112

113+
114+
// on hover, set background color to black
115+
button.onmouseover = () => {
116+
button.style.color = 'orange';
117+
}
118+
button.onmouseout = () => {
119+
button.style.color = 'white';
120+
}
121+
112122
button.style.display = 'flex';
113123
button.style.alignItems = 'center';
114124
button.style.justifyContent = 'center';

src/popup/company.css

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
body {
2+
background-color: #202020;
3+
color: #f0f0f0;
4+
font-size: 18px;
5+
font-family: 'Roboto', sans-serif;
6+
display: flex;
7+
flex-direction: column;
8+
align-items: center;
9+
justify-content: center;
10+
margin: 0;
11+
padding: 20px;
12+
}
13+
14+
h1 {
15+
font-size: 36px;
16+
margin-bottom: 20px;
17+
color: lightcyan;
18+
}
19+
20+
table {
21+
border-collapse: collapse;
22+
margin: auto;
23+
width: 500px;
24+
}
25+
26+
table,
27+
th,
28+
td {
29+
border: 1px solid #FFFFFF;
30+
padding: 10px;
31+
text-align: center;
32+
}
33+
34+
th {
35+
font-size: 18px;
36+
background-color: #424242;
37+
}
38+
39+
td {
40+
font-size: 16px;
41+
}
42+
43+
a {
44+
color: lightgreen;
45+
text-decoration: none;
46+
}
47+
48+
a:hover {
49+
color: #a0a0a0;
50+
}

src/popup/company.html

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,19 @@
22
<html>
33

44
<head>
5+
<link rel="stylesheet" href="./company.css">
56
<title>LeetCode Solutions</title>
67
</head>
78

89
<body>
9-
<h1 id="test">Company tags</h1>
10+
<h1 id="title">Amazon</h1>
11+
<p>
12+
Score = How many times this question has been asked in interviews in the past 2 years.
13+
</p>
1014
<table id="solutionTable">
1115
<tr>
12-
<th>Problem Number</th>
13-
<th>Problem Title</th>
16+
<th>#</th>
17+
<th>Title</th>
1418
<th>Score</th>
1519
</tr>
1620
</table>

src/popup/company.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
1+
function main() {
12

3+
let companyName = "Amazon";
4+
5+
6+
chrome.storage.local.get("clickedCompany", function (data) {
7+
companyName = data.clickedCompany;
8+
document.getElementById("title").textContent = companyName;
9+
document.title = companyName + "'s favorite problems"
10+
});
211

3-
function main() {
412
chrome.storage.local.get("leetcodeProblems", function (data) {
5-
const companyName = "Amazon";
613
let solutions = [];
714

815
console.log(data);
@@ -22,6 +29,9 @@ function main() {
2229
});
2330

2431
const table = document.getElementById("solutionTable");
32+
33+
solutions.sort((a, b) => b.score - a.score);
34+
2535
solutions.forEach(solution => {
2636
const row = table.insertRow(-1);
2737
row.insertCell(0).innerText = solution.id;
@@ -30,8 +40,6 @@ function main() {
3040
row.insertCell(2).innerText = solution.score;
3141
});
3242
});
33-
34-
document.getElementById("test")?.textContent = "Hello World!";
3543
}
3644

3745
/* Run the script */

0 commit comments

Comments
 (0)