kopia lustrzana https://github.com/learn-awesome/learndb
modified simplifyContent to make it cover more html
rodzic
259e45451f
commit
cf1833e684
|
@ -17,12 +17,23 @@ async function fetchContentFromURL(url) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function simplifyContent(content) {
|
function simplifyContent(content) {
|
||||||
let simplifiedContent = content.replace(/<[^>]*>/g, ''); // Remove HTML tags
|
// Remove script and style elements and their content
|
||||||
simplifiedContent = simplifiedContent.replace(/<style[^>]*>.*<\/style>/gms, ''); // Remove CSS
|
let simplifiedContent = content.replace(/<script.*?>.*?<\/script>/gms, '');
|
||||||
simplifiedContent = simplifiedContent.replace(/<script[^>]*>.*<\/script>/gms, ''); // Remove JS
|
simplifiedContent = simplifiedContent.replace(/<style.*?>.*?<\/style>/gms, '');
|
||||||
simplifiedContent = simplifiedContent.replace(/[^\w\s]/gi, ''); // Remove special characters
|
// Remove all remaining HTML tags, leaving the inner text
|
||||||
simplifiedContent = simplifiedContent.replace(/\s+/g, ' ').trim(); // Normalize whitespace
|
simplifiedContent = simplifiedContent.replace(/<[^>]+>/g, '');
|
||||||
return simplifiedContent;
|
// Decode HTML entities
|
||||||
|
simplifiedContent = simplifiedContent.replace(/&[a-z]+;/gi, match => {
|
||||||
|
const span = document.createElement('span');
|
||||||
|
span.innerHTML = match;
|
||||||
|
return span.textContent || span.innerText;
|
||||||
|
});
|
||||||
|
// Remove any residual CSS and JS (inline events, style attributes)
|
||||||
|
simplifiedContent = simplifiedContent.replace(/style\s*=\s*'.*?'/gi, '');
|
||||||
|
simplifiedContent = simplifiedContent.replace(/on\w+\s*=\s*".*?"/gi, '');
|
||||||
|
// Remove special characters and extra whitespace
|
||||||
|
simplifiedContent = simplifiedContent.replace(/[^\w\s]/gi, '').replace(/\s+/g, ' ').trim();
|
||||||
|
return simplifiedContent.toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Placeholder function to perform GPT analysis for media type and topics using Mistral-7b via OpenRouter
|
// Placeholder function to perform GPT analysis for media type and topics using Mistral-7b via OpenRouter
|
||||||
|
|
Ładowanie…
Reference in New Issue