- Add complete UI translations for all 19 supported languages - Add language preference dropdown in modal settings - Store language preference in localStorage - Inject language preference into Hermes system prompts - Add smart translation dropdown with AI-powered language detection - Keep both original translation modal and new smart dropdown - Remove non-functional upload button from modal - Add biome.json config to ignore third-party CSS files
42 lines
1.3 KiB
JavaScript
42 lines
1.3 KiB
JavaScript
// Content extraction and processing functionality
|
|
|
|
// Function to extract text content along with links and metadata from the webpage
|
|
export function extractWebpageContent() {
|
|
let content = "";
|
|
|
|
// Extract title
|
|
const title = document.title;
|
|
if (title) {
|
|
content += `**Page Title**: ${title}\n\n`;
|
|
}
|
|
|
|
// Extract meta description
|
|
const metaDescription = document.querySelector('meta[name="description"]');
|
|
if (metaDescription) {
|
|
content += `**Meta Description**: ${metaDescription.content}\n\n`;
|
|
}
|
|
|
|
// Extract other metadata (if needed)
|
|
const metaKeywords = document.querySelector('meta[name="keywords"]');
|
|
if (metaKeywords) {
|
|
content += `**Meta Keywords**: ${metaKeywords.content}\n\n`;
|
|
}
|
|
|
|
// Recursively extract text and links from the body content
|
|
function getTextWithLinks(element) {
|
|
if (element.nodeType === Node.TEXT_NODE) {
|
|
content += `${element.textContent} `;
|
|
} else if (element.nodeType === Node.ELEMENT_NODE) {
|
|
if (element.tagName.toLowerCase() === "a") {
|
|
// If it's a link, append the text and the href
|
|
content += `[${element.textContent}](${element.href}) `;
|
|
} else {
|
|
// Recursively process child nodes
|
|
element.childNodes.forEach(getTextWithLinks);
|
|
}
|
|
}
|
|
}
|
|
|
|
getTextWithLinks(document.body);
|
|
return content.trim();
|
|
}
|