-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent.js
More file actions
37 lines (28 loc) · 1.02 KB
/
content.js
File metadata and controls
37 lines (28 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
console.log("✅ content.js loaded on CSES result page");
window.addEventListener("load", () => {
console.log("⏳ DOM fully loaded, checking for submission data");
// Trying multiple strategies to extract the title
let title = null;
const breadcrumb = document.querySelector(".breadcrumb a[href*='problem']");
const h1 = document.querySelector("h1");
if (breadcrumb) {
title = breadcrumb.innerText.trim();
} else if (h1) {
title = h1.innerText.trim();
}
const codeEl = document.querySelector("pre");
if (!title || !codeEl) {
console.warn("⚠️ Could not find problem title or code block");
console.log("🔍 title:", title);
console.log("🔍 codeEl:", codeEl);
return;
}
const sanitizedTitle = title.replace(/[^\w\s]/gi, '').replace(/\s+/g, '_');
const code = codeEl.innerText;
console.log(`📘 Title: ${sanitizedTitle}`);
console.log("📄 Code snippet captured");
chrome.runtime.sendMessage({
action: "submission",
data: { title: sanitizedTitle, code }
});
});