fetch information from URI and head metadata.
modified: uncloseai.js
This commit is contained in:
parent
b97f41a557
commit
fe41810528
1 changed files with 43 additions and 1 deletions
44
uncloseai.js
44
uncloseai.js
|
|
@ -32,8 +32,50 @@ let chatHistory = [
|
|||
];
|
||||
|
||||
// Function to extract text content from the webpage
|
||||
//function extractWebpageContent() {
|
||||
// return document.body.innerText;
|
||||
//}
|
||||
|
||||
// Function to extract text content along with links and metadata from the webpage
|
||||
function extractWebpageContent() {
|
||||
return document.body.innerText;
|
||||
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); // Start with the body element
|
||||
|
||||
return content.trim();
|
||||
}
|
||||
|
||||
// Generator function to send a message to the LLM and yield responses
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue