feat: complete text quize
This commit is contained in:
parent
17c1d971d4
commit
294c17f7f6
1 changed files with 54 additions and 0 deletions
54
script.js
54
script.js
|
|
@ -60,6 +60,42 @@
|
|||
return false;
|
||||
}
|
||||
|
||||
function findTextQuiz() {
|
||||
const quizzes = document.querySelectorAll('section.quiz_type_text');
|
||||
for (const quiz of quizzes) {
|
||||
if (handledQuizzes.has(quiz)) continue;
|
||||
if (quiz.classList.contains('quiz_answered')) { handledQuizzes.add(quiz); continue; }
|
||||
const submitBtn = quiz.querySelector('button.quiz__submit');
|
||||
if (!submitBtn) { handledQuizzes.add(quiz); continue; }
|
||||
if (quiz.offsetParent !== null) return quiz;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
async function handleTextQuiz(quiz) {
|
||||
console.log('✏️ Текстовый квиз...');
|
||||
const textarea = quiz.querySelector('textarea.quiz__input-control');
|
||||
if (textarea) {
|
||||
simulateTyping(textarea, 'не знаю');
|
||||
console.log('✓ Введён ответ');
|
||||
await sleep(400);
|
||||
}
|
||||
|
||||
const submitBtn = quiz.querySelector('button.quiz__submit');
|
||||
if (submitBtn && !submitBtn.disabled) {
|
||||
submitBtn.click();
|
||||
console.log('✓ Нажата кнопка "Узнать ответ"');
|
||||
} else if (submitBtn) {
|
||||
submitBtn.disabled = false;
|
||||
submitBtn.click();
|
||||
console.log('✓ Принудительный клик "Узнать ответ"');
|
||||
}
|
||||
|
||||
handledQuizzes.add(quiz);
|
||||
await sleep(CLICK_DELAY);
|
||||
return true;
|
||||
}
|
||||
|
||||
function findCodingQuiz() {
|
||||
const quizzes = document.querySelectorAll('section.quiz_type_coding');
|
||||
for (const quiz of quizzes) {
|
||||
|
|
@ -271,6 +307,9 @@
|
|||
const codingQuiz = findCodingQuiz();
|
||||
if (codingQuiz) return { type: 'coding', element: codingQuiz };
|
||||
|
||||
const textQuiz = findTextQuiz();
|
||||
if (textQuiz) return { type: 'text', element: textQuiz };
|
||||
|
||||
const quiz = findQuizForm();
|
||||
if (quiz) return { type: 'quiz', element: quiz };
|
||||
|
||||
|
|
@ -299,6 +338,14 @@
|
|||
continue;
|
||||
}
|
||||
|
||||
let textQuiz = findTextQuiz();
|
||||
if (textQuiz) {
|
||||
scrollToElement(textQuiz);
|
||||
await sleep(300);
|
||||
await handleTextQuiz(textQuiz);
|
||||
continue;
|
||||
}
|
||||
|
||||
let quiz = findQuizForm();
|
||||
if (quiz) {
|
||||
scrollToElement(quiz);
|
||||
|
|
@ -338,6 +385,13 @@
|
|||
continue;
|
||||
}
|
||||
|
||||
if (result.type === 'text') {
|
||||
scrollToElement(result.element);
|
||||
await sleep(300);
|
||||
await handleTextQuiz(result.element);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (result.type === 'quiz') {
|
||||
scrollToElement(result.element);
|
||||
await sleep(300);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue