Skip to content

Instantly share code, notes, and snippets.

@suaicat
Created May 7, 2025 08:28
Show Gist options
  • Save suaicat/8f27bf1ee1e14f171521a5f429f75fc1 to your computer and use it in GitHub Desktop.
Save suaicat/8f27bf1ee1e14f171521a5f429f75fc1 to your computer and use it in GitHub Desktop.
Автоматическое прохождение лекций с таймером
(() => {
// 1) Собираем все модули с нужным бейджем
const modules = Array.from(document.querySelectorAll("[id^='module-']")).map(node => {
const badge = node.querySelector(
"div:nth-child(1) > div:nth-child(1) > div:nth-child(1) > div:nth-child(2) > " +
"div:nth-child(1) > div:nth-child(1) > div:nth-child(1) > span:nth-child(1) > span:nth-child(2)"
);
if (!badge) return null;
const m = badge.textContent.match(/Провести в этой лекции не менее\s*(\d+)\s*мин/);
if (!m) return null;
const minutes = parseInt(m[1], 10);
const a = node.querySelector("a");
if (!a || !a.href) return null;
return { href: a.href, minutes };
}).filter(x => x);
if (!modules.length) {
console.warn("Не найдено лекций с требуемым бейджем.");
return;
}
console.log(`Найдено ${modules.length} лекций для автоматического прохождения.`);
// 2) Для каждой – открываем и планируем сабмит
modules.forEach(({ href, minutes }) => {
const w = window.open(href);
if (!w) {
console.error("Открытие вкладки заблокировано для", href);
return;
}
// Когда вкладка загрузится
w.onload = () => {
const form = w.document.querySelector('form[action*="mod/lesson/continue.php"]');
if (!form) {
console.warn("Форма продолжения не найдена в", href);
return;
}
console.log(`Вкладка ${href} готова. Ждём ${minutes} мин…`);
setTimeout(() => {
form.submit();
console.log(`Сабмит формы для ${href} выполнен.`);
}, minutes * 60 * 1000);
};
});
})();
@suaicat
Copy link
Author

suaicat commented May 7, 2025

Просто вставить в консоль курса в moodle

@suaicat
Copy link
Author

suaicat commented May 7, 2025

Отдельно отмечу, что фактически можно не открывать вкладки, а просто скрапить всё что надо из формы и куки и отправлять пост запрос подобного типа:

curl -L 'https://lms.guap.ru/mod/lesson/continue.php' \
  -X POST \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  -H 'Referer: https://lms.guap.ru/mod/lesson/view.php?id=' \
  -b 'MoodleSessionLMS4=;' \
  --data-urlencode 'id=' \
  --data-urlencode 'pageid=' \
  --data-urlencode 'sesskey=' \
  --data-urlencode 'jumpto=-1' 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment