forked from creativityexhausted/FlowLearner
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent.js
More file actions
37 lines (31 loc) · 1.28 KB
/
content.js
File metadata and controls
37 lines (31 loc) · 1.28 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
// Content script for additional functionality if needed.
// content.js
// Capture the current tab's URL and send it to the backend
chrome.runtime.sendMessage({ action: "getTabURL" });
// Function to extract text content from the current webpage
function getPageText() {
const bodyText = document.body.innerText || "";
return bodyText.replace(/\s+/g, " ").trim();
}
// Listener for messages from the popup script
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message.type === "GET_PAGE_TEXT") {
const pageText = getPageText();
sendResponse({ text: pageText });
}
});
// Example: Injecting a highlight effect on the webpage for summarized text
function highlightText(summary) {
const bodyHTML = document.body.innerHTML;
const highlightedHTML = summary.split(". ").reduce((html, sentence) => {
return html.replace(sentence, `<span style="background-color: yellow;">${sentence}</span>`);
}, bodyHTML);
document.body.innerHTML = highlightedHTML;
}
// Optional: Listen for commands to highlight the summary
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message.type === "HIGHLIGHT_SUMMARY") {
highlightText(message.summary);
sendResponse({ success: true });
}
});