Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Auto Click "Next Page" with Countdown Timer Sync
- // @namespace http://tampermonkey.net/
- // @version 1.5
- // @description Clicks "Next Page" when countdown timer reaches 00:00
- // @author Prajan Shrestha
- // @match https://app.aarpdriversafety.org/courseflow/*
- // @grant none
- // ==/UserScript==
- (function() {
- 'use strict';
- console.log("Tampermonkey script is running...");
- // Simulate a natural click
- function simulateClick(element) {
- const event = new MouseEvent("click", {
- bubbles: true,
- cancelable: true,
- view: window
- });
- element.dispatchEvent(event);
- }
- // Check timer and click button
- function checkTimerAndClick() {
- const timer = document.querySelector("[data-test='courseTimer']");
- const button = document.getElementById("arrow-next");
- // Wait for timer to appear
- if (!timer) {
- console.log("Timer not found yet. Retrying in 1.5s...");
- setTimeout(checkTimerAndClick, 1500);
- return;
- }
- const time = timer.textContent.trim(); // e.g., "00:00"
- console.log(`Current timer value: ${time}`);
- // Wait for button to appear
- if (!button) {
- console.log("Button not found. Retrying in 1.5s...");
- setTimeout(checkTimerAndClick, 1500);
- return;
- }
- // When timer hits 00:00 and button is enabled, click it
- if (time === "00:00" && !button.disabled) {
- console.log("Timer at 00:00 and button enabled. Clicking now...");
- simulateClick(button);
- setTimeout(checkTimerAndClick, 2000); // Check again after 2s for next page
- } else {
- if (button.disabled) {
- console.log("Button is disabled. Waiting for timer to reach 00:00... (retrying in 1.5s)");
- } else {
- console.log(`Timer at ${time}, waiting for 00:00... (retrying in 1.5s)`);
- }
- setTimeout(checkTimerAndClick, 1500); // Retry every 1.5s
- }
- }
- // Start the script
- console.log("Starting script. Waiting for timer and button...");
- setTimeout(checkTimerAndClick, 1500); // Initial delay to let page load
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement