Skip to content

Commit 771f9cf

Browse files
committed
feat: successfully scraping data from leetcode problems page
1 parent 343e260 commit 771f9cf

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed

content.js

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,46 @@
1-
console.log("🧠 leetcode tracker is active")
1+
function getProblemData() {
2+
const titleEl = document.querySelector('div[class*="text-title-large"]');
3+
const title = titleEl ? titleEl.textContent.trim() : "Unknown Title";
4+
5+
const difficultyEl = Array.from(document.querySelectorAll('div[class*="text-difficulty"]')).find((el) =>
6+
el.textContent?.match(/Easy|Medium|Hard/)
7+
);
8+
const difficulty = difficultyEl
9+
? difficultyEl.textContent.trim()
10+
: "Unknown Difficulty";
11+
12+
const pathParts = window.location.pathname.split("/").filter(Boolean);
13+
const problemSlug = pathParts[1] || "unknown-problem";
14+
15+
const problemData = {
16+
title,
17+
difficulty,
18+
slug: problemSlug,
19+
url: window.location.href,
20+
timestamp: Date.now(),
21+
};
22+
23+
console.log("LC Problem Detected:", problemData);
24+
return problemData;
25+
}
26+
27+
function waitForContentAndStore() {
28+
const observer = new MutationObserver(() => {
29+
const titleEl = document.querySelector("div");
30+
if (titleEl && titleEl.textContent.trim()) {
31+
observer.disconnect();
32+
const data = getProblemData();
33+
browser.storage.local.set({ [data.slug]: data }).then(() => {
34+
console.log("Saved to storage:", data);
35+
}).catch((err) => {
36+
console.error("Storage error:", err);
37+
});
38+
}
39+
});
40+
41+
observer.observe(document.body, { childList: true, subtree: true });
42+
}
43+
44+
waitForContentAndStore();
45+
46+

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
},
1616
"content_scripts": [
1717
{
18-
"matches": ["https://leetcode.com/*"],
18+
"matches": ["https://leetcode.com/problems/*"],
1919
"js": ["content.js"]
2020
}
2121
]

0 commit comments

Comments
 (0)