Advertisement
Flattop

//== Tampermonkey script; auto-click "next page" in AARP Smart Driver's Course w/countdown timer ==\

Mar 16th, 2025
355
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 2.32 KB | Software | 0 0
  1. // ==UserScript==
  2. // @name         Auto Click "Next Page" with Countdown Timer Sync
  3. // @namespace    http://tampermonkey.net/
  4. // @version      1.5
  5. // @description  Clicks "Next Page" when countdown timer reaches 00:00
  6. // @author       Prajan Shrestha
  7. // @match        https://app.aarpdriversafety.org/courseflow/*
  8. // @grant        none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12.     'use strict';
  13.  
  14.     console.log("Tampermonkey script is running...");
  15.  
  16.     // Simulate a natural click
  17.     function simulateClick(element) {
  18.         const event = new MouseEvent("click", {
  19.             bubbles: true,
  20.             cancelable: true,
  21.             view: window
  22.         });
  23.         element.dispatchEvent(event);
  24.     }
  25.  
  26.     // Check timer and click button
  27.     function checkTimerAndClick() {
  28.         const timer = document.querySelector("[data-test='courseTimer']");
  29.         const button = document.getElementById("arrow-next");
  30.  
  31.         // Wait for timer to appear
  32.         if (!timer) {
  33.             console.log("Timer not found yet. Retrying in 1.5s...");
  34.             setTimeout(checkTimerAndClick, 1500);
  35.             return;
  36.         }
  37.  
  38.         const time = timer.textContent.trim(); // e.g., "00:00"
  39.         console.log(`Current timer value: ${time}`);
  40.  
  41.         // Wait for button to appear
  42.         if (!button) {
  43.             console.log("Button not found. Retrying in 1.5s...");
  44.             setTimeout(checkTimerAndClick, 1500);
  45.             return;
  46.         }
  47.  
  48.         // When timer hits 00:00 and button is enabled, click it
  49.         if (time === "00:00" && !button.disabled) {
  50.             console.log("Timer at 00:00 and button enabled. Clicking now...");
  51.             simulateClick(button);
  52.             setTimeout(checkTimerAndClick, 2000); // Check again after 2s for next page
  53.         } else {
  54.             if (button.disabled) {
  55.                 console.log("Button is disabled. Waiting for timer to reach 00:00... (retrying in 1.5s)");
  56.             } else {
  57.                 console.log(`Timer at ${time}, waiting for 00:00... (retrying in 1.5s)`);
  58.             }
  59.             setTimeout(checkTimerAndClick, 1500); // Retry every 1.5s
  60.         }
  61.     }
  62.  
  63.     // Start the script
  64.     console.log("Starting script. Waiting for timer and button...");
  65.     setTimeout(checkTimerAndClick, 1500); // Initial delay to let page load
  66. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement