code from 3 to 2 chars
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
@@ -32,9 +32,9 @@ saveBtn.addEventListener('click', function () {
|
||||
return;
|
||||
}
|
||||
|
||||
if (code.length > 0 && code.length < 3) {
|
||||
if (code.length > 0 && code.length < 2) {
|
||||
showMessage({
|
||||
msg: 'The code should at least contain 3 characters',
|
||||
msg: 'The code should at least contain 2 characters',
|
||||
error: true
|
||||
});
|
||||
return;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
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
|
||||
@@ -8,14 +9,7 @@ import htmlTableToString from '@utils/html-table-to-string';
|
||||
* @returns
|
||||
*/
|
||||
function createAndNormalizeQuestion(questionContainer: HTMLElement) {
|
||||
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, '');
|
||||
}
|
||||
let question = getVisibleText(questionContainer);
|
||||
|
||||
// Make tables more readable for chat-gpt
|
||||
const tables: NodeListOf<HTMLTableElement> = questionContainer.querySelectorAll('.qtext table');
|
||||
|
||||
@@ -26,11 +26,13 @@ function handleCheckbox(
|
||||
|
||||
const possibleAnswers = Array.from(inputList)
|
||||
.map(inp => ({
|
||||
element: inp,
|
||||
element: inp as HTMLInputElement,
|
||||
value: normalizeText(inp?.parentElement?.textContent ?? '')
|
||||
}))
|
||||
.filter(obj => obj.value !== '');
|
||||
|
||||
// Find the best answers elements
|
||||
const correctElements: Set<HTMLInputElement> = new Set();
|
||||
for (const correct of corrects) {
|
||||
const bestAnswer = pickBestReponse(correct, possibleAnswers);
|
||||
|
||||
@@ -38,13 +40,23 @@ function handleCheckbox(
|
||||
Logs.bestAnswer(bestAnswer.value, bestAnswer.similarity);
|
||||
}
|
||||
|
||||
const correctInput = bestAnswer.element as HTMLInputElement;
|
||||
correctElements.add(bestAnswer.element as HTMLInputElement);
|
||||
}
|
||||
|
||||
// Check if it should be checked or not
|
||||
for (const element of possibleAnswers.map(e => e.element)) {
|
||||
const needAction =
|
||||
(element.checked && !correctElements.has(element)) ||
|
||||
(!element.checked && correctElements.has(element));
|
||||
|
||||
const action = () => needAction && element.click();
|
||||
|
||||
if (config.mouseover) {
|
||||
correctInput.addEventListener('mouseover', () => correctInput.click(), {
|
||||
element.addEventListener('mouseover', action, {
|
||||
once: true
|
||||
});
|
||||
} else {
|
||||
correctInput.click();
|
||||
action();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ function handleContentEditable(
|
||||
|
||||
if (
|
||||
inputList.length !== 1 || // for now we don't handle many input for editable textcontent
|
||||
input.getAttribute('contenteditable') !== 'true'
|
||||
typeof input.getAttribute('contenteditable') !== 'string'
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* 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