Grade Randomizer

grade good ads gone 😉

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Grade Randomizer
// @namespace    http://tampermonkey.net/
// @version      1.3
// @description  grade good ads gone 😉
// @author       M1noa
// @match        *://campus.ccsd.net/*
// @license MIT 
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Function to generate a random percentage between 71.62 and 100.00
    function getRandomPercent() {
        const min = 71.62;
        const max = 100.00;
        return (Math.random() * (max - min) + min).toFixed(2); // Limit to 2 decimal places
    }

    // Function to determine the letter grade based on the percent
    function getLetterGrade(percent) {
        if (percent >= 90) return 'A';
        if (percent >= 80) return 'B';
        if (percent >= 70) return 'C';
        if (percent >= 60) return 'D';
        return 'F';
    }

    // Function to modify the text within the grading-score divs
    function modifyGrades() {
        const gradeDivs = document.querySelectorAll('.grading-score');

        gradeDivs.forEach(gradeDiv => {
            const percentDiv = gradeDiv.querySelector('.grading-score__row-spacing b');
            const letterDiv = gradeDiv.querySelector('b:first-child');

            if (percentDiv && letterDiv) {
                // Extract the percentage from the text like "(67.08%)"
                const percentMatch = percentDiv.innerText.match(/\((\d+\.?\d*)%\)/);
                if (percentMatch && percentMatch[1]) {
                    const originalPercent = parseFloat(percentMatch[1]);

                    // Generate a new random percentage
                    const newPercent = getRandomPercent();

                    // Get the corresponding letter grade
                    const newLetterGrade = getLetterGrade(newPercent);

                    // Update the div with the new values
                    percentDiv.innerText = `(${newPercent}%)`;
                    letterDiv.innerText = newLetterGrade;
                }
            }
        });
    }

    // Function to remove all divs with the class 'ng-star-inserted'
    function removeNgStarInsertedDivs() {
        const ngStarDivs = document.querySelectorAll('.router-link-reset');
        ngStarDivs.forEach(div => div.remove());
    }

    // Function to clear the page if URL contains 'classroom/grades'
    function clearPageOnSpecificURLs() {
        if (window.location.href.includes('classroom/grades')) {
            document.body.innerHTML = '';
        }
    }

    // Observe changes to the DOM and modify grades accordingly
    const observer = new MutationObserver(() => {
        modifyGrades();
        removeNgStarInsertedDivs();
    });
    observer.observe(document.body, { childList: true, subtree: true });

    // Initial run to modify grades and clean up on page load
    modifyGrades();
    removeNgStarInsertedDivs();
    clearPageOnSpecificURLs();

    // Listen for URL changes (in case of SPA navigation)
    window.addEventListener('popstate', clearPageOnSpecificURLs);
})();