Answer Grabber

Revel answers to questions on your Ximera homework

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği indirebilmeniz için ayrıca Tampermonkey gibi bir eklenti kurmanız gerekmektedir.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @name         Answer Grabber
// @namespace    http://tampermonkey.net/
// @version      2024-09-20
// @description  Revel answers to questions on your Ximera homework
// @author       PsychedelicPalimpsest
// @match        *://ximera.osu.edu/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=osu.edu
// @license      MIT
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    let lastInputCount = -1;

    const old_log = console.log;
    console.log = (arg) =>{
        old_log(arg);
        if (arg != "Recorded gradebook") return;
        let c = document.querySelectorAll("input[type=text]").length;
        if (c == lastInputCount) return;
        lastInputCount = c;


        document.head.innerHTML += "<style>.correct{background-color: green;}</style>";
        function stripr(str){
            let parcount = 0;
            for (let index in str){
                let c = str[index];
                if (c == "{")
                    parcount++;
                else if(c == "}")
                    parcount--;
                if (parcount == -1)
                    return str.substring(0, index);
            }
        }

        let texs = document.querySelectorAll("script[type='math/tex; mode=display']")
                .values()
                .toArray()
                .concat(
                    document.querySelectorAll("script[type='math/tex']")
                            .values()
                            .toArray()
                );
        for (let tex of texs){
            let answers = tex.innerText.matchAll(/\\answer/g).toArray();
            if (document.getElementById(tex.id + "-Frame") == undefined) continue;
            let boxes = document.getElementById(tex.id + "-Frame").querySelectorAll("input[type=text]")


            for (let i in answers){

                let astr = tex.innerText.substring(answers[i].index);
                let a = stripr(astr.substring(astr.match(/\{/).index+1));
                if (boxes[i] == undefined) break;
                boxes[i].value = a
            }
        }
    }


})();