-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontent-script.js
35 lines (35 loc) · 1.2 KB
/
content-script.js
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
chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
if (request.action === "grabProblemName") {
for (const a of document.body.querySelectorAll("a")) {
if (a.textContent.includes(document.title.split(" - ")[0])) {
return chrome.runtime.sendMessage({
data: a.textContent
.replace(".", "")
.split(" ")
.map((word) => word[0].toUpperCase() + word.substring(1))
.join("")
.concat(".py"),
type: "problemName",
});
}
}
} else if (request.action === "grabProblemSkeleton") {
return chrome.runtime.sendMessage({
data: `"""\n${
document
.querySelector("[data-track-load='description_content']")
.innerHTML.replaceAll("<sup>", "^")
.replaceAll("</sup>", "")
.replace(/<.*?>/g, "")
.replaceAll(" ", " ")
.replaceAll("<", "<")
.replaceAll(">", ">")
.replaceAll("\n\n", "\n")
.split("\n \nFollow up")[0]
}\n"""\n\n${document
.getElementsByClassName("view-lines")[0]
.innerText.replace(/[^\x00-\x7F]/g, " ")}`,
type: "problemSkeleton",
});
}
});