feat: complete try coding
This commit is contained in:
parent
6243ccb470
commit
17c1d971d4
1 changed files with 119 additions and 37 deletions
106
script.js
106
script.js
|
|
@ -60,6 +60,37 @@
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function findCodingQuiz() {
|
||||||
|
const quizzes = document.querySelectorAll('section.quiz_type_coding');
|
||||||
|
for (const quiz of quizzes) {
|
||||||
|
if (handledQuizzes.has(quiz)) continue;
|
||||||
|
if (quiz.classList.contains('quiz_answered')) { handledQuizzes.add(quiz); continue; }
|
||||||
|
const runBtn = quiz.querySelector('button.quiz__coding-footer-action-button');
|
||||||
|
if (!runBtn) { handledQuizzes.add(quiz); continue; }
|
||||||
|
if (quiz.offsetParent !== null) return quiz;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleCodingQuiz(quiz) {
|
||||||
|
console.log('💻 Квиз с кодом — запускаем...');
|
||||||
|
const runBtn = quiz.querySelector('button.quiz__coding-footer-action-button');
|
||||||
|
runBtn.click();
|
||||||
|
|
||||||
|
// Ждём пока квиз пометится как решённый
|
||||||
|
const startTime = Date.now();
|
||||||
|
while (Date.now() - startTime < 60000) {
|
||||||
|
await sleep(CHECK_INTERVAL);
|
||||||
|
if (quiz.classList.contains('quiz_answered') || !quiz.querySelector('button.quiz__coding-footer-action-button')) {
|
||||||
|
console.log('✓ Код выполнен');
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
handledQuizzes.add(quiz);
|
||||||
|
await sleep(CLICK_DELAY);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
function findQuizForm() {
|
function findQuizForm() {
|
||||||
const forms = document.querySelectorAll(QUIZ_FORM_SELECTOR);
|
const forms = document.querySelectorAll(QUIZ_FORM_SELECTOR);
|
||||||
for (const form of forms) {
|
for (const form of forms) {
|
||||||
|
|
@ -184,12 +215,21 @@
|
||||||
async function handleQuizForm(form) {
|
async function handleQuizForm(form) {
|
||||||
console.log('❓ Квиз...');
|
console.log('❓ Квиз...');
|
||||||
|
|
||||||
|
const checkboxes = form.querySelectorAll('input[type="checkbox"]');
|
||||||
|
if (checkboxes.length > 0) {
|
||||||
|
for (const cb of checkboxes) {
|
||||||
|
if (!cb.checked) cb.click();
|
||||||
|
await sleep(100);
|
||||||
|
}
|
||||||
|
console.log(`✓ Выбраны все чекбоксы (${checkboxes.length})`);
|
||||||
|
} else {
|
||||||
const firstRadio = form.querySelector('input[type="radio"]');
|
const firstRadio = form.querySelector('input[type="radio"]');
|
||||||
if (firstRadio) {
|
if (firstRadio) {
|
||||||
firstRadio.click();
|
firstRadio.click();
|
||||||
console.log('✓ Выбран первый вариант');
|
console.log('✓ Выбран первый вариант');
|
||||||
await sleep(300);
|
await sleep(300);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const submitBtn = form.querySelector(QUIZ_SUBMIT_SELECTOR);
|
const submitBtn = form.querySelector(QUIZ_SUBMIT_SELECTOR);
|
||||||
if (submitBtn && !submitBtn.disabled) {
|
if (submitBtn && !submitBtn.disabled) {
|
||||||
|
|
@ -228,6 +268,9 @@
|
||||||
while (Date.now() - startTime < timeout) {
|
while (Date.now() - startTime < timeout) {
|
||||||
if (!isRunning) return null;
|
if (!isRunning) return null;
|
||||||
|
|
||||||
|
const codingQuiz = findCodingQuiz();
|
||||||
|
if (codingQuiz) return { type: 'coding', element: codingQuiz };
|
||||||
|
|
||||||
const quiz = findQuizForm();
|
const quiz = findQuizForm();
|
||||||
if (quiz) return { type: 'quiz', element: quiz };
|
if (quiz) return { type: 'quiz', element: quiz };
|
||||||
|
|
||||||
|
|
@ -248,6 +291,14 @@
|
||||||
|
|
||||||
async function processLesson() {
|
async function processLesson() {
|
||||||
while (isRunning) {
|
while (isRunning) {
|
||||||
|
let codingQuiz = findCodingQuiz();
|
||||||
|
if (codingQuiz) {
|
||||||
|
scrollToElement(codingQuiz);
|
||||||
|
await sleep(300);
|
||||||
|
await handleCodingQuiz(codingQuiz);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
let quiz = findQuizForm();
|
let quiz = findQuizForm();
|
||||||
if (quiz) {
|
if (quiz) {
|
||||||
scrollToElement(quiz);
|
scrollToElement(quiz);
|
||||||
|
|
@ -280,6 +331,13 @@
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (result.type === 'coding') {
|
||||||
|
scrollToElement(result.element);
|
||||||
|
await sleep(300);
|
||||||
|
await handleCodingQuiz(result.element);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (result.type === 'quiz') {
|
if (result.type === 'quiz') {
|
||||||
scrollToElement(result.element);
|
scrollToElement(result.element);
|
||||||
await sleep(300);
|
await sleep(300);
|
||||||
|
|
@ -331,6 +389,7 @@
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await sleep(1000);
|
||||||
scrollToElement(nextLessonBtn);
|
scrollToElement(nextLessonBtn);
|
||||||
await sleep(300);
|
await sleep(300);
|
||||||
nextLessonBtn.click();
|
nextLessonBtn.click();
|
||||||
|
|
@ -451,6 +510,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleTrainerPage() {
|
async function handleTrainerPage() {
|
||||||
|
if (!document.querySelector('button.trainer-footer__solution-button')) {
|
||||||
console.log('💡 Загружаем исходник страницы для поиска решения...');
|
console.log('💡 Загружаем исходник страницы для поиска решения...');
|
||||||
const answerPanes = await fetchAnswerPanes();
|
const answerPanes = await fetchAnswerPanes();
|
||||||
|
|
||||||
|
|
@ -467,7 +527,6 @@
|
||||||
|
|
||||||
console.log(`💡 Найдено решение (${answerPanes[0].name}), вставляем...`);
|
console.log(`💡 Найдено решение (${answerPanes[0].name}), вставляем...`);
|
||||||
insertSolutionIntoMonaco(solution);
|
insertSolutionIntoMonaco(solution);
|
||||||
|
|
||||||
await sleep(CLICK_DELAY);
|
await sleep(CLICK_DELAY);
|
||||||
|
|
||||||
const checkBtn = document.querySelector('button.trainer-footer__check-button');
|
const checkBtn = document.querySelector('button.trainer-footer__check-button');
|
||||||
|
|
@ -478,6 +537,9 @@
|
||||||
console.log('⚠️ Кнопка "Проверить" не найдена');
|
console.log('⚠️ Кнопка "Проверить" не найдена');
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
console.log('ℹ️ Задача уже решена');
|
||||||
|
}
|
||||||
|
|
||||||
// Ждём кнопку "Далее" без ограничения по времени
|
// Ждём кнопку "Далее" без ограничения по времени
|
||||||
let nextBtn = null;
|
let nextBtn = null;
|
||||||
|
|
@ -495,21 +557,41 @@
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function dispatch() {
|
||||||
|
// Сброс состояния при каждом вызове
|
||||||
|
isRunning = true;
|
||||||
|
clickedButtons = new WeakSet();
|
||||||
|
handledQuizzes = new WeakSet();
|
||||||
|
handledFeedbacks = new WeakSet();
|
||||||
|
|
||||||
|
const path = window.location.pathname;
|
||||||
|
console.log(`🔄 Страница: ${path}`);
|
||||||
|
|
||||||
|
if (path.includes('/profile/associated-programs-android-st-v2')) {
|
||||||
|
const found = handleAssociatedProgramsPage();
|
||||||
|
if (found) await handleCourseModal();
|
||||||
|
} else if (path.includes('/trainer/') && window.monaco?.editor.getEditors().length > 0) {
|
||||||
|
await handleTrainerPage();
|
||||||
|
} else if (path.includes('/trainer/') || path.includes('/topics/')) {
|
||||||
|
await run();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Перехват SPA-навигации
|
||||||
|
const _pushState = history.pushState.bind(history);
|
||||||
|
history.pushState = function(...args) {
|
||||||
|
_pushState(...args);
|
||||||
|
setTimeout(() => dispatch(), PAGE_LOAD_DELAY);
|
||||||
|
};
|
||||||
|
window.addEventListener('popstate', () => {
|
||||||
|
setTimeout(() => dispatch(), PAGE_LOAD_DELAY);
|
||||||
|
});
|
||||||
|
|
||||||
window.stopAutoClick = function() {
|
window.stopAutoClick = function() {
|
||||||
isRunning = false;
|
isRunning = false;
|
||||||
console.log('⏹ Остановлено');
|
console.log('⏹ Остановлено');
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log('💡 Для остановки: stopAutoClick()');
|
console.log('💡 Для остановки: stopAutoClick()');
|
||||||
|
await dispatch();
|
||||||
if (window.location.pathname.includes('/profile/associated-programs-android-st-v2')) {
|
|
||||||
const found = handleAssociatedProgramsPage();
|
|
||||||
if (found) {
|
|
||||||
await handleCourseModal();
|
|
||||||
}
|
|
||||||
} else if (window.location.pathname.includes('/trainer/') && window.monaco?.editor.getEditors().length > 0) {
|
|
||||||
await handleTrainerPage();
|
|
||||||
} else {
|
|
||||||
run();
|
|
||||||
}
|
|
||||||
})();
|
})();
|
||||||
Loading…
Add table
Reference in a new issue