Skip to content

Commit a837913

Browse files
committed
feat: filter to remove undefined problems from the popup
1 parent 9d98062 commit a837913

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

content.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ async function getProblemData() {
2323
tags = [];
2424
}
2525

26+
// Only return valid data if title and slug are valid
27+
if (!title || title === "Unknown Title" || !problemSlug || problemSlug === "unknown-problem") {
28+
return null;
29+
}
30+
2631
const problemData = {
2732
title,
2833
difficulty,
@@ -43,6 +48,7 @@ function waitForContentAndStore() {
4348
if (titleEl && titleEl.textContent.trim()) {
4449
observer.disconnect();
4550
const data = await getProblemData();
51+
if (!data) return; // Don't store invalid/undefined problems
4652
browser.storage.local.set({ [data.slug]: data }).then(() => {
4753
console.log("Saved to storage:", data);
4854
}).catch((err) => {

popup/popup.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,14 @@ document.addEventListener("DOMContentLoaded", () => {
4040

4141
document.addEventListener("DOMContentLoaded", () => {
4242
browser.storage.local.get(null).then((allData) => {
43-
const problems = Object.values(allData).filter(p => p.status === "Solved");
43+
// Filter out invalid/undefined problems before displaying
44+
const problems = Object.values(allData).filter(p =>
45+
p &&
46+
typeof p.title === 'string' && p.title !== 'Unknown Title' &&
47+
typeof p.slug === 'string' && p.slug !== 'unknown-problem' &&
48+
typeof p.difficulty === 'string' && p.difficulty !== 'Unknown Difficulty' &&
49+
p.status === "Solved"
50+
);
4451
// Sort by solvedAt descending (most recent first)
4552
problems.sort((a, b) => (b.solvedAt || 0) - (a.solvedAt || 0));
4653

0 commit comments

Comments
 (0)