removed get visible text because not working

This commit is contained in:
yoannchb-pro
2024-05-04 00:55:26 -04:00
parent ea5cd3763d
commit dcfe8f3320
4 changed files with 10 additions and 34 deletions
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+8 -2
View File
@@ -1,6 +1,5 @@
import normalizeText from '@utils/normalize-text';
import htmlTableToString from '@utils/html-table-to-string';
import getVisibleText from '@utils/get-visible-text';
/**
* Normalize the question as text and add sub informations
@@ -9,7 +8,14 @@ import getVisibleText from '@utils/get-visible-text';
* @returns
*/
function createAndNormalizeQuestion(questionContainer: HTMLElement) {
let question = getVisibleText(questionContainer);
let question = questionContainer.innerText;
// We remove unnecessary information
const accesshideElements: NodeListOf<HTMLElement> =
questionContainer.querySelectorAll('.accesshide');
for (const useless of accesshideElements) {
question = question.replace(useless.innerText, '');
}
// Make tables more readable for chat-gpt
const tables: NodeListOf<HTMLTableElement> = questionContainer.querySelectorAll('.qtext table');
-30
View File
@@ -1,30 +0,0 @@
/**
* Get only the visible text of an element
* @param element
* @returns
*/
function getVisibleText(element: HTMLElement): string {
function traverse(node: Node): string {
let text = '';
for (const child of node.childNodes) {
if (child.nodeType === Node.TEXT_NODE) {
if (isVisible(child.parentNode as HTMLElement)) {
text += (child as Text).textContent;
}
} else if (child.nodeType === Node.ELEMENT_NODE) {
text += traverse(child);
}
}
return text;
}
function isVisible(el: HTMLElement): boolean {
const style = window.getComputedStyle(el);
return style.display !== 'none' && style.visibility !== 'hidden' && style.opacity !== '0';
}
return traverse(element);
}
export default getVisibleText;