Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (() => {
- /**
- * Utility: Click a button matching a span text.
- */
- const clickButtonByText = (text) => {
- const button = [...document.querySelectorAll("button")].find(
- (btn) => btn.querySelector("span")?.innerText.trim() === text
- );
- button?.click();
- };
- /**
- * Utility: Click a button by selector if enabled.
- */
- const clickEnabledButton = (selector) => {
- const btn = document.querySelector(`${selector}:not([disabled])`);
- btn?.click();
- };
- /**
- * Quiz Interaction Steps
- */
- const actions = {
- selectFirstRadioOption: () => {
- const option = document.querySelector('input[type="radio"]:not([disabled])');
- option?.click();
- },
- checkAnswer: () => {
- const button = [...document.querySelectorAll("button")].findLast(
- (btn) => btn.querySelector("span")?.innerText.trim() === "Перевірити"
- );
- button?.click();
- },
- revealAnswer: () => clickButtonByText("Дізнатися відповідь"),
- nextSection: () => clickEnabledButton("#go-to-next-course-element"),
- nextModule: () => clickButtonByText("До наступного модуля"),
- goToPracticalTask: () => clickButtonByText("Перейти до практичного завдання"),
- next: () => clickButtonByText("Далі"),
- nextBlock: () => clickButtonByText("До наступного блоку"),
- scrollToBottom: () => window.scrollTo(0, document.body.scrollHeight),
- };
- /**
- * Observer Callback
- */
- const handleMutations = () => {
- actions.selectFirstRadioOption();
- actions.revealAnswer();
- actions.checkAnswer();
- actions.nextSection();
- actions.nextModule();
- actions.goToPracticalTask();
- actions.next();
- actions.nextBlock();
- actions.scrollToBottom();
- };
- /**
- * Start observing DOM changes
- */
- const observer = new MutationObserver(handleMutations);
- observer.observe(document.body, { childList: true, subtree: true });
- console.log("Quiz automation started.");
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement