Skip to content

Commit 22f073d

Browse files
committed
fix: resolved use of multiple DOMContentLoaded blocks
1 parent 8406644 commit 22f073d

File tree

1 file changed

+6
-25
lines changed

1 file changed

+6
-25
lines changed

popup/popup.js

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
11
document.addEventListener("DOMContentLoaded", () => {
2+
// Handle current problem display
23
browser.tabs.query({ active: true, currentWindow: true }).then((tabs) => {
34
const tab = tabs[0];
4-
55
const url = new URL(tab.url);
66
const pathParts = url.pathname.split("/").filter(Boolean);
77
const slug = pathParts[1] || null;
8+
const container = document.getElementById("popupContent");
89
if (!slug) {
9-
document.getElementById("popupContent").innerHTML = "<p>To track a problem, please visit a leetcode problem page</p>";
10+
container.innerHTML = "<p>To track a problem, please visit a leetcode problem page</p>";
1011
return;
1112
}
12-
13-
const container = document.getElementById("popupContent");
14-
1513
browser.storage.local.get(slug).then((result) => {
1614
let data = result[slug];
1715
if (data) {
1816
renderCurrentProblem(data);
1917
} else {
20-
2118
browser.runtime
2219
.sendMessage({ type: "GET_PROBLEM_DATA", slug })
2320
.then((data) => {
@@ -33,7 +30,6 @@ document.addEventListener("DOMContentLoaded", () => {
3330
});
3431
}
3532
});
36-
3733
function renderCurrentProblem(data) {
3834
container.innerHTML = "";
3935
const titleEl = document.createElement("h3");
@@ -48,8 +44,6 @@ document.addEventListener("DOMContentLoaded", () => {
4844
container.appendChild(titleEl);
4945
container.appendChild(diffEl);
5046
container.appendChild(statusEl);
51-
52-
// Listen for problem solved message
5347
browser.runtime.onMessage.addListener((msg) => {
5448
if (msg.type === "PROBLEM_SOLVED" && msg.slug === data.slug) {
5549
const statusEl = document.getElementById("status");
@@ -58,11 +52,9 @@ document.addEventListener("DOMContentLoaded", () => {
5852
});
5953
}
6054
});
61-
});
6255

63-
document.addEventListener("DOMContentLoaded", () => {
56+
// Handle solved problems list and tag filter
6457
browser.storage.local.get(null).then((allData) => {
65-
// Filter out invalid/undefined problems before displaying
6658
const problems = Object.values(allData).filter(
6759
(p) =>
6860
p &&
@@ -74,21 +66,16 @@ document.addEventListener("DOMContentLoaded", () => {
7466
p.difficulty !== "Unknown Difficulty" &&
7567
p.status === "Solved"
7668
);
77-
7869
problems.sort((a, b) => (b.solvedAt || 0) - (a.solvedAt || 0));
79-
8070
const tagSet = new Set();
8171
problems.forEach((p) => {
8272
if (Array.isArray(p.tags)) {
8373
p.tags.forEach((tag) => tagSet.add(tag));
8474
}
8575
});
8676
const tags = Array.from(tagSet);
87-
88-
// Populate tag filter dropdown
8977
const tagFilter = document.getElementById("tagFilter");
9078
if (tagFilter) {
91-
// Remove old options except 'All'
9279
tagFilter.innerHTML = '<option value="all">All</option>';
9380
if (tags.length > 0) {
9481
tags.forEach((tag) => {
@@ -104,7 +91,6 @@ document.addEventListener("DOMContentLoaded", () => {
10491
tagFilter.appendChild(opt);
10592
}
10693
}
107-
10894
function renderProblems() {
10995
const list = document.getElementById("solvedList");
11096
list.innerHTML = "";
@@ -125,16 +111,13 @@ document.addEventListener("DOMContentLoaded", () => {
125111
const difficultyClass = problem.difficulty
126112
? problem.difficulty.toLowerCase()
127113
: "";
128-
129114
const link = document.createElement("a");
130115
link.href = problem.url;
131116
link.target = "_blank";
132117
link.textContent = problem.title;
133-
134118
const diffSpan = document.createElement("span");
135119
diffSpan.className = `difficulty ${difficultyClass}`;
136120
diffSpan.textContent = problem.difficulty;
137-
138121
const tagsSpan = document.createElement("span");
139122
tagsSpan.style.fontSize = "0.85em";
140123
tagsSpan.style.color =
@@ -144,20 +127,19 @@ document.addEventListener("DOMContentLoaded", () => {
144127
problem.tags && problem.tags.length > 0
145128
? `[${problem.tags.join(", ")}]`
146129
: "[No tags]";
147-
148130
item.appendChild(link);
149131
item.appendChild(diffSpan);
150132
item.appendChild(tagsSpan);
151133
list.appendChild(item);
152134
});
153135
}
154-
155136
if (tagFilter) {
156137
tagFilter.addEventListener("change", renderProblems);
157138
}
158139
renderProblems();
159140
});
160141

142+
// Handle view all link
161143
const viewAllLink = document.getElementById("viewAllLink");
162144
if (viewAllLink) {
163145
viewAllLink.addEventListener("click", (e) => {
@@ -169,9 +151,8 @@ document.addEventListener("DOMContentLoaded", () => {
169151
}
170152
});
171153
}
172-
});
173154

174-
document.addEventListener("DOMContentLoaded", () => {
155+
// Handle options/settings button
175156
const optionsBtn = document.getElementById("optionsBtn");
176157
if (optionsBtn) {
177158
optionsBtn.addEventListener("click", () => {

0 commit comments

Comments
 (0)