removed get visible text because not working
This commit is contained in:
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -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');
|
||||
|
||||
@@ -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;
|
||||
Reference in New Issue
Block a user