vasylmartyniv

GoIT Scroller Script

Jun 21st, 2025 (edited)
1,656
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 1.97 KB | Software | 0 0
  1. (() => {
  2.   const clickButtonByText = (text) => {
  3.     const button = [...document.querySelectorAll("button")].find(
  4.       (btn) => btn.querySelector("span")?.innerText.trim() === text
  5.     );
  6.     button?.click();
  7.   };
  8.  
  9.   const clickEnabledButton = (selector) => {
  10.     const btn = document.querySelector(`${selector}:not([disabled])`);
  11.     btn?.click();
  12.   };
  13.  
  14.   const actions = {
  15.     selectFirstRadioOption: () => {
  16.       const option = document.querySelector('input[type="radio"]:not([disabled])');
  17.       option?.click();
  18.     },
  19.  
  20.     checkAnswer: () => {
  21.       const button = [...document.querySelectorAll("button")].findLast(
  22.         (btn) => btn.querySelector("span")?.innerText.trim() === "Перевірити"
  23.       );
  24.       button?.click();
  25.     },
  26.  
  27.     revealAnswer: () => clickButtonByText("Дізнатися відповідь"),
  28.     nextSection: () => clickEnabledButton("#go-to-next-course-element"),
  29.     nextModule: () => clickButtonByText("До наступного модуля"),
  30.     goToPracticalTask: () => clickButtonByText("Перейти до практичного завдання"),
  31.     next: () => clickButtonByText("Далі"),
  32.     nextBlock: () => clickButtonByText("До наступного блоку"),
  33.     scrollToBottom: () => window.scrollTo(0, document.body.scrollHeight),
  34.   };
  35.    
  36.     const enableButtons = ()=>{
  37.     document.querySelectorAll("button").forEach(btn => {
  38.   btn.disabled = false;
  39.   btn.removeAttribute("disabled");
  40. });
  41.     }
  42.  
  43.   const handleMutations = () => {
  44.       enableButtons();
  45.     actions.selectFirstRadioOption();
  46.     actions.revealAnswer();
  47.     actions.checkAnswer();
  48.     actions.nextSection();
  49.     actions.nextModule();
  50.     actions.goToPracticalTask();
  51.     actions.next();
  52.     actions.nextBlock();
  53.     actions.scrollToBottom();
  54.   };
  55.  
  56.   const observer = new MutationObserver(handleMutations);
  57.   observer.observe(document.body, { childList: true, subtree: true });
  58.  
  59.   console.log("Quiz automation started.");
  60. })();
  61.  
Advertisement
Add Comment
Please, Sign In to add comment