DriversEd Auto-Next with Stop Button

Auto-click the "Next" button when timer ends, with a Stop button to cancel auto-clicking.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

You will need to install an extension such as Tampermonkey to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         DriversEd Auto-Next with Stop Button
// @namespace    https://driversed.com/
// @version      1.0.1
// @description  Auto-click the "Next" button when timer ends, with a Stop button to cancel auto-clicking.
// @author       NellowTCS
// @match        https://app.driversed.com/*
// @grant        none
// @run-at       document-idle
// @license      MIT
// ==/UserScript==

(function () {
  'use strict';

  function waitAndClickNext() {
    const btn = document.getElementById('arrow-next');
    if (!btn) {
      console.warn('Next button not found, retrying...');
      setTimeout(waitAndClickNext, 500);
      return;
    }

    const observer = new MutationObserver(() => {
      if (!btn.disabled) {
        console.log('Next button enabled! Clicking now...');
        btn.click();
        observer.disconnect();
        removeStopButton();
      }
    });

    observer.observe(btn, { attributes: true, attributeFilter: ['disabled'] });
    console.log('Waiting for button to be enabled...');

    if (!document.getElementById('stop-auto-next')) {
      const stopBtn = document.createElement('button');
      stopBtn.id = 'stop-auto-next';
      stopBtn.textContent = 'Stop Auto-Next';
      stopBtn.style.position = 'fixed';
      stopBtn.style.bottom = '20px';
      stopBtn.style.right = '20px';
      stopBtn.style.zIndex = 10000;
      stopBtn.style.background = '#ff4d4d';
      stopBtn.style.color = '#fff';
      stopBtn.style.border = 'none';
      stopBtn.style.padding = '10px 14px';
      stopBtn.style.borderRadius = '6px';
      stopBtn.style.cursor = 'pointer';
      stopBtn.style.fontSize = '14px';
      stopBtn.style.boxShadow = '0 2px 6px rgba(0,0,0,0.2)';

      stopBtn.onclick = () => {
        observer.disconnect();
        console.log('Auto-clicker stopped manually.');
        removeStopButton();
      };

      document.body.appendChild(stopBtn);
    }

    function removeStopButton() {
      const existing = document.getElementById('stop-auto-next');
      if (existing) existing.remove();
    }
  }

  waitAndClickNext();
})();