Greasy Fork is available in English.

Edmentum Auto Tutorial

Clicks The "Next" Button And If Unavaliable Then Press "show sample answer" Then "submit" Then Repeats until Completed

// ==UserScript==
// @name         Edmentum Auto Tutorial
// @namespace    http://tampermonkey.net/
// @version      2.0
// @description  Clicks The "Next" Button And If Unavaliable Then Press "show sample answer" Then "submit" Then Repeats until Completed
// @author       UnknownQwertyz
// @match        https://f2.app.edmentum.com/*
// @match        https://f2.app.edmentum.com/
// @match        https://f2.app.edmentum.com/courseware-delivery/
// @match        https://f2.app.edmentum.com/courseware-delivery//ua/78/45609186/aHR0cHM6Ly9mMi5hcHAuZWRtZW50dW0uY29tL2xlYXJuZXItdWkvc2Vjb25kYXJ5L3VzZXItYXNzaWdubWVudC83OC9sYXVuY2hwYWQvNDU2MDkxNjc1
// @match        https://app.edmentum.com/*
// @match        https://app.edmentum.com/
// @match        https://*.app.edmentum.com/courseware-delivery/*
// @match        https://*.app.edmentum.com/courseware-delivery/
// @license      none
// @grant        none
// ==/UserScript==

// Immediately-invoked Function Expression (IIFE) to encapsulate the script and prevent variable conflicts
(function() {
    'use strict'; // Enable strict mode for better error handling and security

    // Function to auto click the next button
    function autoClickNextButton() {
        var nextButton = document.querySelector('.tutorial-nav-next'); // Select the next button element
        if (nextButton) { // Check if the next button exists
            nextButton.click(); // Simulate a click on the next button
            console.log("Next button pressed"); // Log that the next button has been pressed
            resetTimers(); // Reset timers after clicking the next button
            return true; // Return true to indicate success
        }
        return false; // Return false if the next button does not exist
    }

    // Function to auto click all "Show Correct Answer" buttons
    function autoClickShowAnswerButtons() {
        var showAnswerButtons = document.querySelectorAll('.btn.buttonCorrectToggle'); // Select all "Show Correct Answer" buttons
        if (showAnswerButtons) { // Check if any "Show Correct Answer" buttons are found
            showAnswerButtons.forEach(function(button) { // Iterate over each button
                button.click(); // Simulate a click on each button
            });
            console.log("Show Correct Answer buttons pressed"); // Log that "Show Correct Answer" buttons have been pressed
            setTimeout(autoClickSubmitButtons, 100); // Delay to ensure the "Show Correct Answer" action completes before clicking on "Submit"
        }
    }

    // Function to auto click all "Submit" buttons
    function autoClickSubmitButtons() {
        var submitButtons = document.querySelectorAll('.btn.buttonDone'); // Select all "Submit" buttons
        if (submitButtons) { // Check if any "Submit" buttons are found
            submitButtons.forEach(function(button) { // Iterate over each button
                button.click(); // Simulate a click on each button
            });
            console.log("Submit buttons pressed"); // Log that "Submit" buttons have been pressed
            setTimeout(autoClickNextButton, 100); // Delay to ensure the "Submit" action completes before attempting to click on "Next" button
        }
    }

    // Function to auto click the exit button when the congratulation message appears
    function autoClickExitButton() {
        var congratulationMessage = document.querySelector('.global-title.final'); // Select the congratulation message element
        if (congratulationMessage && congratulationMessage.innerText === "Congratulations!") { // Check if the congratulation message exists and contains the text "Congratulations!"
            var exitButton = document.querySelector('.tutorial-nav-exit'); // Select the exit button element
            if (exitButton) { // Check if the exit button exists
                exitButton.click(); // Simulate a click on the exit button
                console.log("Exit button pressed"); // Log that the exit button has been pressed
            }
        }
    }

    // Function to check if there are two occurrences of the same number within the progress element
    function checkProgressNumbers() {
        var progressElement = document.querySelector('.tutorial-nav-progress'); // Select the progress element
        if (progressElement) { // Check if the progress element exists
            var progressNumbers = progressElement.querySelectorAll('.tutorial-nav-progress-current'); // Select all progress numbers
            if (progressNumbers.length === 2 && progressNumbers[0].innerText === progressNumbers[1].innerText) { // Check if there are two progress numbers and they are the same
                autoClickExitButton(); // Press the "Save and Exit" button
            }
        }
    }

    // Function to repeatedly press the specified button until the "Next" button becomes active
    function autoClickSBSNextButton() {
        var sbsNextButton = document.getElementById('sbsNext'); // Select the SBS Next button element
        if (sbsNextButton) { // Check if the SBS Next button exists
            sbsNextButton.click(); // Simulate a click on the SBS Next button
            console.log("SBS Next button pressed"); // Log that the SBS Next button has been pressed
            resetTimers(); // Reset timers after clicking the SBS Next button
            setTimeout(autoClickSBSNextButton, 100); // Repeat every 100 milliseconds until the "Next" button becomes active
        }
    }

    // Function to apply styles to SampleAnswerNav and buttonCorrectToggle elements
    function applyStylesToElements() {
        var sampleAnswerNavs = document.getElementsByClassName('SampleAnswerNav'); // Select all SampleAnswerNav elements
        for (let nav of sampleAnswerNavs) { // Iterate over each SampleAnswerNav element
            nav.style = {}; // Reset the style attribute
            nav.firstElementChild.style.display = 'inline-block'; // Set the display style of the first child element to 'inline-block'
        }

        var correctToggleButtons = document.getElementsByClassName('buttonCorrectToggle'); // Select all buttonCorrectToggle elements
        for (let button of correctToggleButtons) { // Iterate over each buttonCorrectToggle element
            button.style.display = 'inline'; // Set the display style to 'inline'
            button.style.visibility = 'visible'; // Set the visibility to 'visible'
        }
    }

    // Function to simulate pressing Command + F and typing "tutorial"
    function searchForTutorial() {
        document.addEventListener("keydown", function(event) { // Add a keydown event listener to the document
            console.log("Keydown event detected"); // Log that a keydown event has been detected
            if (event.key === 'f' && (event.ctrlKey || event.metaKey)) { // Check if the key pressed is 'f' and the Ctrl or Command key is also pressed
                event.preventDefault(); // Prevent the default browser behavior
                var searchInput = document.querySelector('input[type="search"]'); // Select the search input element
                if (searchInput) { // Check if the search input exists
                    searchInput.focus(); // Focus on the search input
                    searchInput.value = 'tutorial'; // Set the value of the search input to 'tutorial'
                }
            }
        });
    }

    // Function to reset all timers
    function resetTimers() {
        clearTimeout(waitForPageLoad.timer); // Clear the timer for waitForPageLoad
        clearTimeout(repeatAutomation.timer); // Clear the timer for repeatAutomation
        clearTimeout(autoClickExitButton.timer); // Clear the timer for autoClickExitButton
        clearTimeout(autoClickNextButton.timer); // Clear the timer for autoClickNextButton
        clearTimeout(autoClickSBSNextButton.timer); // Clear the timer for autoClickSBSNextButton
        clearTimeout(autoClickSubmitButtons.timer); // Clear the timer for autoClickSubmitButtons
        clearTimeout(autoClickShowAnswerButtons.timer); // Clear the tiemr for autoClickShowAnswerButtons
    }

    // Function to wait for the page to fully load
    function waitForPageLoad() {
        if (document.readyState === "complete") { // Check if the document has fully loaded
            // Page fully loaded, call the functions
            autoClickNextButton(); // Automatically click the next button
            autoClickSBSNextButton(); // Start clicking the SBS Next button
            applyStylesToElements(); // Apply styles to elements
            searchForTutorial(); // Simulate search for "tutorial"
        } else {
            // Page still loading, wait and try again
            setTimeout(waitForPageLoad, 100); // Check every 100 milliseconds
        }
    }

    // Function to repeat all automation functions
    function repeatAutomation() {
        setInterval(function() { // Set an interval to repeat the automation functions
            autoClickNextButton(); // Automatically click the next button
            autoClickShowAnswerButtons(); // Automatically click all "Show Correct Answer" buttons
            autoClickSubmitButtons(); // Automatically click all "Submit" buttons
            autoClickExitButton(); // Automatically click the exit button when the congratulation message appears
            checkProgressNumbers(); // Check if there are two occurrences of the same number within the progress element
        }, 500); // Repeat every 500 milliseconds
    }

    // Call the function to start repeating automation
    repeatAutomation();

    // Call the function when the page loads initially
    waitForPageLoad();
})();