Skip to content

Instantly share code, notes, and snippets.

@DarkMio
Last active May 3, 2024 19:34
Show Gist options
  • Save DarkMio/e6509d0325dd11ebde6306591d611540 to your computer and use it in GitHub Desktop.
Save DarkMio/e6509d0325dd11ebde6306591d611540 to your computer and use it in GitHub Desktop.
Gooboo School Math Solver
const cancel = (() => {
const handle = setInterval(() => {
const element = document.querySelector(".v-text-field__slot > input");
const questionElement = document.querySelector(".question-text > :nth-child(1)");
if(!element || !questionElement) {
return;
}
const text = questionElement.innerText.replaceAll('_', ' ');
element.value = text;
element.dispatchEvent(new Event("input", {
bubbles: true,
cancelable: true
}))
}, 16);
return () => clearInterval(handle);
})()
// I'm lazy, so why shouldn't math solve itself?
// for gooboo, the game
const cancel = (() => {
const handle = setInterval(() => {
const element = document.querySelector("#answer-input-math")
const question = document.querySelector(".question-text");
if (!element || !question) {
return;
}
const questionText = question.innerHTML;
if(questionText.includes("√")) {
const { number } = /(?<number>\d+)/.exec(questionText)?.groups
element.value = Math.sqrt(parseInt(number));
} else if(questionText.includes("^")) {
const { base, exponent } = /(?<base>\d+)\ \^\ (?<exponent>\d+)/.exec(questionText)?.groups;
element.value = Math.pow(parseInt(base), parseInt(exponent));
} else {
element.value = eval(question.innerHTML);
}
element.dispatchEvent(new Event("input", {
bubbles: true,
cancelable: true
}));
element.dispatchEvent(new KeyboardEvent('keydown', {
'key': 'Enter',
keyCode: 13,
code: "enter",
which: 13
}));
}, 16);
return () => clearInterval(handle);
})()
// I'd also like to point out that this code is shoddy, but I'm even too lazy for that.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment