forked from kamalesh-2003/ai-notes-summarizer-web-extension
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent.js
More file actions
20 lines (19 loc) · 920 Bytes
/
Copy pathcontent.js
File metadata and controls
20 lines (19 loc) · 920 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// Listener for messages from the popup or background script
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.action === "summarize") {
let selectedText = window.getSelection().toString().trim();
let textToSummarize = selectedText || document.body.innerText; // Use selected text or full page
// Send extracted text to the backend API
fetch("http://127.0.0.1:5000/summarize", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ text: textToSummarize }),
})
.then(response => response.json())
.then(data => {
// Send the summarized text back to the popup.js to display
chrome.runtime.sendMessage({ action: "showSummary", summary: data.summary });
})
.catch(error => console.error("Error:", error));
}
});