-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
41 lines (37 loc) · 1.32 KB
/
popup.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
36
37
38
39
40
41
document.addEventListener("DOMContentLoaded", () => {
document.getElementById("fetch-hints").addEventListener("click", fetchHints);
async function fetchHints() {
chrome.tabs.query(
{ active: true, currentWindow: true },
async function (tabs) {
const tab = tabs[0];
const url = new URL(tab.url);
const problemName = url.pathname.split("/")[2];
console.log(problemName);
document.getElementById("problem-name").innerText = `
Give me hints about this problem ${problemName}
`;
try {
const response = await fetch("http://localhost:3000/getHints", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ problemName: problemName }),
});
if (response.ok) {
const data = await response.json();
const hintText = data.hint;
const hintContainer = document.getElementById("hint-container");
hintContainer.innerHTML = "";
hintContainer.innerHTML = hintText;
}
} catch (error) {
console.error("Error fetching hints:", error);
document.getElementById("hint-list").innerHTML =
"<li>Failed to fetch hints</li>";
}
}
);
}
});