-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent.js
More file actions
32 lines (27 loc) · 823 Bytes
/
Copy pathcontent.js
File metadata and controls
32 lines (27 loc) · 823 Bytes
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
// Content script to extract page content
(function() {
// Extract page data
const pageData = {
title: document.title,
url: window.location.href,
content: extractTextContent(),
links: document.querySelectorAll("a").length,
timestamp: new Date().toISOString()
};
// Send data back to background script
browser.runtime.sendMessage({
type: "PAGE_CONTENT",
data: pageData
});
})();
function extractTextContent() {
// Remove script and style elements
const clone = document.body.cloneNode(true);
const scriptsAndStyles = clone.querySelectorAll("script, style, noscript");
scriptsAndStyles.forEach(el => el.remove());
// Get text content
let text = clone.innerText || clone.textContent;
// Clean up whitespace
text = text.replace(/\s+/g, " ").trim();
return text;
}