// Content script for DocuElevate browser extension
// This script runs on all web pages to enable communication
// between page content and the extension
/**
* Capture the full page HTML with inline styles
*/
function captureFullPage() {
// Get all stylesheets and inline them
const styles = Array.from(document.styleSheets)
.map(sheet => {
try {
return Array.from(sheet.cssRules)
.map(rule => rule.cssText)
.join('\n');
} catch (e) {
// Handle CORS issues with external stylesheets
console.warn('Could not access stylesheet:', sheet.href, e);
return '';
}
})
.join('\n');
// Create a complete HTML document with inlined styles
const styledHtml = `
${document.title}
${document.body.innerHTML}
`;
return {
html: styledHtml,
title: document.title,
url: window.location.href,
timestamp: new Date().toISOString()
};
}
/**
* Capture selected content from the page
* Note: For performance, uses basic HTML structure without per-element computed styles.
* The resulting PDF will use browser default styles.
*/
function captureSelection() {
const selection = window.getSelection();
if (!selection || selection.rangeCount === 0) {
throw new Error('No content selected');
}
const range = selection.getRangeAt(0);
const container = document.createElement('div');
container.appendChild(range.cloneContents());
const html = `
${document.title} - Selection
${document.title}
Source: ${window.location.href}
${container.innerHTML}
`;