]*>[\s\S]*?<\/script><\/div>/gi, '');
content = content.replace(/<(?!\/?p\b)[^>]+>/gi, '');
content = content.replace(/\s+/g, ' ').trim();
if (!content) throw new Error("No content found between markers");
console.log(content);
return content;
}
const startIndex = htmlText.match(startPattern)[0].length + startMatch;
let content = htmlText.substring(startIndex, endMatch).trim();
content = content.replace(/
]*>[\s\S]*?<\/script><\/div>/gi, '');
content = content.replace(/<(?!\/?p\b)[^>]+>/gi, '');
content = content.replace(/\s+/g, ' ').trim();
if (!content) throw new Error("No content found between markers");
console.log(content);
return decodeHtmlEntities(content);
} catch (error) {
console.log("Fetch error in extractText: " + error);
return '
Error extracting text
';
}
}
async function soraFetch(url, options = {
headers: {},
method: 'GET',
body: null
}) {
try {
return await fetchv2(url, options.headers ?? {}, options.method ?? 'GET', options.body ?? null);
} catch (e) {
try {
return await fetch(url, options);
} catch (error) {
return null;
}
}
}
function decodeHtmlEntities(text) {
const entities = {
'—': '—',
'–': '–',
'&': '&',
'<': '<',
'>': '>',
'"': '"',
''': "'",
'/': '/',
'`': '`',
'=': '=',
' ': ' '
};
return text.replace(/[\dA-Fa-f]+;|&\w+;/g, (match) => {
return entities[match] || match;
});
}