Add cheats script

Co-authored-by: Julian; <JDobeshow@users.noreply.github.com>
This commit is contained in:
MrLetsplay 2022-05-01 19:40:29 +02:00
parent 47efa48032
commit 79172a3024
9 changed files with 432 additions and 4 deletions

File diff suppressed because one or more lines are too long

2
lzk/.htaccess Normal file
View File

@ -0,0 +1,2 @@
Header set Access-Control-Allow-Origin "*"
Header set Access-Control-Allow-Headers "content-type"

16
lzk/add-question.php Normal file
View File

@ -0,0 +1,16 @@
<?php
$post = json_decode(file_get_contents('php://input'), true);
$question = $post["question"];
$answers = $post["answers"];
$type = $post["type"];
var_dump($post);
if(!isset($question) || !isset($answers) || !isset($type)) {
echo "question and answers are null";
die();
}
$qs = json_decode(file_get_contents("questions-log.json"), true);
$qs[$question] = array("type" => $type, "answers" => $answers);
file_put_contents("questions-log.json", json_encode($qs, JSON_PRETTY_PRINT));
echo "Success";
?>

130
lzk/lzk-cheats.user.js Normal file
View File

@ -0,0 +1,130 @@
// ==UserScript==
// @name Moodle Cheats
// @namespace http://cringe-studios.com/
// @version 1.0
// @description Advanced cheat tools
// @author MrLetsplay, JDobeshow
// @match https://moodle.cringe-studios.com/mod/quiz/attempt.php*
// @icon https://nsfw.cringe-studios.com/grimacing.png
// @grant none
// ==/UserScript==
var questionAnswers = null;
function normalize(text) {
return text.replaceAll(/[^a-zA-Z0-9]/g, "").toLowerCase();
}
function msg(text) {
let form = document.getElementById("responseform");
let sad = document.getElementById("cheat-msg");
if(!sad){
sad = document.createElement("span");
sad.id = "cheat-msg";
sad.innerText = text;
sad.style.color = "gray";
let q = form.getElementsByClassName("qtext")[0];
q.parentElement.insertBefore(sad, q);
}else {
sad.innerText = text;
}
}
function insertAnswers() {
console.log("Solve");
let form = document.getElementById("responseform");
let qText = form.getElementsByClassName("qtext")[0];
if(qText.getElementsByTagName("select").length > 0) {
// Fixes bug in Chrome
let clone = form.cloneNode(true);
let selects;
while((selects = clone.getElementsByClassName("qtext")[0].getElementsByTagName("select")).length > 0) {
selects[0].remove();
}
qText = clone.getElementsByClassName("qtext")[0];
}
let question = normalize(qText.innerText);
let answer = questionAnswers[question];
if(answer == null) {
console.log("No answer for question:", question);
msg("No answer found");
return;
}
let answers = form.getElementsByClassName("answer")[0];
if(answers != null && answers.tagName == "TABLE") {
for(let tr of answers.getElementsByTagName("tr")) {
let ans = answer[normalize(tr.children[0].getElementsByTagName("p")[0].innerText)];
let s = tr.children[1].getElementsByTagName("select")[0];
for(let j = 0; j < s.options.length; j++) {
if(normalize(s.options[j].innerText) == ans) {
s.selectedIndex = j;
break;
}
}
}
}else {
let selects = form.getElementsByTagName("select");
if(selects.length > 0) { // Question with placeholders
for(let i = 0; i < selects.length; i++) {
let ans = answer[i];
let s = selects[i];
for(let j = 0; j < s.options.length; j++) {
if(normalize(s.options[j].innerText) == ans) {
s.selectedIndex = j;
break;
}
}
}
}else {
for(let a of answers.children) {
let aEl = a.getElementsByTagName("p")[0];
if(!aEl) aEl = a.getElementsByTagName("label")[0];
if(!aEl) aEl = a.getElementsByClassName("answernumber")[0].nextElementSibling;
let aText = normalize(aEl.innerText);
let input = a.getElementsByTagName("input")[0];
if(input.type == "hidden") input = a.getElementsByTagName("input")[1];
input.checked = answer.includes(aText);
}
}
}
}
function loadQuestions() {
let xhr = new XMLHttpRequest();
xhr.open("GET", "https://cringe-studios.com/lzk/questions.json");
xhr.send();
xhr.onload = () => {
questionAnswers = JSON.parse(xhr.responseText);
let newQAs = {};
for(let q in questionAnswers) {
let ans = questionAnswers[q];
let newAs = Array.isArray(ans) ? [] : {};
for(let k in ans) {
newAs[normalize(k)] = normalize(ans[k]);
}
newQAs[normalize(q)] = newAs;
}
questionAnswers = newQAs;
console.log(questionAnswers);
}
}
(function() {
'use strict';
loadQuestions();
document.addEventListener("keydown", event => {
if(event.key == "A") {
if(questionAnswers == null) {
msg("Not ready yet");
return;
}
insertAnswers();
}
});
})();

83
lzk/questions-log.json Executable file
View File

@ -0,0 +1,83 @@
{
"Choose \"Yay\", \"Woo\" and \"Sus\"": {
"type": "Multiple choice (mehrfach)",
"answers": [
"Amogus\n",
"Sus\n",
"Test\n",
"Woo\n",
"Yay\n"
]
},
"Answer is \"A\"\n": {
"type": "Multiple choice (einzeln)",
"answers": [
"A\n",
"C\n",
"D\n",
"B\n"
]
},
"Choose\n": {
"type": "Zuordnung",
"answers": {
"Choose \"C\"\n": [
"Ausw\u00e4hlen ...",
"A",
"C",
"B"
],
"Choose \"A\"\n": [
"Ausw\u00e4hlen ...",
"A",
"C",
"B"
],
"Choose \"B\"\n": [
"Ausw\u00e4hlen ...",
"A",
"C",
"B"
]
}
},
"The impostor is ___ and ___ .Crewmates are ___ and ___ .": {
"type": "L\u00fcckentext",
"answers": [
[
"\u00a0",
"sus",
"very nice"
],
[
"\u00a0",
"a sussy baka",
"innocent"
],
[
"\u00a0",
"sus",
"very nice"
],
[
"\u00a0",
"a sussy baka",
"innocent"
]
]
},
"Very weird formatting, but the answer is sus": {
"type": "Multiple choice (mehrfach)",
"answers": [
"The correct code is let a = \"sus\"; console.log(a);.\n",
"The correct code is console.log(\"amogus\");.\n"
]
},
"Is\n\n\n0 == true\n\nor\n\n\n0 == false?\n": {
"type": "Multiple choice (einzeln)",
"answers": [
"Wahr",
"Falsch"
]
}
}

View File

@ -0,0 +1,90 @@
// ==UserScript==
// @name Moodle Questions Logger
// @namespace http://cringe-studios.com/
// @version 1.0
// @description Advanced cheat tools
// @author MrLetsplay, JDobeshow
// @match https://moodle.cringe-studios.com/mod/quiz/attempt.php*
// @icon https://nsfw.cringe-studios.com/sus.png
// @grant none
// ==/UserScript==
function saveQuestion() {
let form = document.getElementById("responseform");
let qText = form.getElementsByClassName("qtext")[0];
if(qText.getElementsByTagName("select").length > 0) {
// Fixes bug in Chrome
let clone = form.cloneNode(true);
let selects;
while((selects = clone.getElementsByClassName("qtext")[0].getElementsByTagName("select")).length > 0) {
let span = document.createElement("span");
span.innerText = "___";
selects[0].parentElement.replaceChild(span, selects[0]);
}
qText = clone.getElementsByClassName("qtext")[0];
console.log(qText);
}
let question = qText.innerText;
let answers = [];
let type = "unknown";
for(let select of form.getElementsByClassName("qtext")[0].getElementsByTagName("select")) {
type = "Lückentext";
let a = [];
for(let op of select.children) {
a.push(op.innerText);
}
answers.push(a);
}
let answersEl = form.getElementsByClassName("answer")[0];
if(answersEl) {
if(answersEl.tagName == "TABLE") {
answers = {};
type = "Zuordnung";
for(let tr of answersEl.getElementsByTagName("tr")) {
let tx = tr.children[0].getElementsByTagName("p")[0].innerText;
let s = tr.children[1].getElementsByTagName("select")[0];
let ops = [];
for(let j = 0; j < s.options.length; j++) {
ops.push(s.options[j].innerText);
}
answers[tx] = ops;
}
}else {
let isMultiple = false;
for(let a of answersEl.children) {
let input = a.getElementsByTagName("input")[0];
if(input.type == "hidden") input = a.getElementsByTagName("input")[1];
if(input.type == "checkbox") isMultiple = true;
let aEl = a.getElementsByTagName("p")[0];
if(!aEl) aEl = a.getElementsByTagName("label")[0];
if(!aEl) aEl = a.getElementsByClassName("answernumber")[0].nextElementSibling;
answers.push(aEl.innerText);
}
type = isMultiple ? "Multiple choice (mehrfach)" : "Multiple choice (einzeln)";
}
}
let xhr = new XMLHttpRequest();
xhr.open("POST", "https://cringe-studios.com/lzk/add-question.php");
xhr.setRequestHeader("Content-Type", "application/json");
let obj = {
question: question,
answers: answers,
type: type
}
console.log(obj);
xhr.send(JSON.stringify(obj));
}
(function() {
'use strict';
saveQuestion();
})();

102
lzk/questions.json Normal file
View File

@ -0,0 +1,102 @@
{
"What is the correct tag for the largest heading in HTML?": ["<h1>"],
"What are semantic HTML elements?": ["Elements with meanings which allow a reader of the document to understand the meaning of the element"],
"The class attribute is defined as following:": ["class=\"name\""],
"The class Attribute is used to devide different into logical groups": ["elements"],
"What is the \"alt\" - Attribute for?": [
"It is used to display information about an element when the content cannot be displayed or loaded by the browser.",
"Disabled people can access the information of an element, which they wouldn't be able to understand due to their disabilities."
],
"The classname is": ["case sensitive"],
"Link the positions to corresponding persons.": {
"Who is W3C CEO?": "Jeffrey Jaffe",
"Who is W3C director?": "Who is W3C director?"
},
"An iframe is an element which is used to display a webpage within a web page. Is this statement true or false?": ["True"],
"URLs are used to define the to a destination site or to a ressource needed in the HTML file.": ["path"],
"What is the charset meta declaration used for?": ["It defines the character encoding of a document so that the browser can interpret it properly."],
"Choose how ids are referenced in CSS.": ["#idname"],
"Which of the following statements are true?": [
"With Javascript you can create new elements.",
"You can include a Javascript file at the end of the HTML body.",
"With the <noscript> tag you provide alternate content for users who disabled Javascript",
"The code document.getElementById(\"demo\").innterHTML = \"Hello JavaScript!\"; selects an element with the name \"demo\" and changes its text to \"Hello Javascript\"",
"Javascript can be used to change the css of an element."
],
"In some cases IDs should be used more than once. Is this statement true or false?": ["False"],
"An inline CSS is used to apply a unique style to HTML element.\nAn internal CSS is used to define a style for HTML .\nAn external style sheet is used to define the style for HTML .": [
"a single", "element", "a single", "a page", "many", "pages"
],
"Who develops the different standards for the Open Web Platform?": ["W3 Consortium (W3C)"],
"Who is responsible for HTML standards?": ["W3 Consortium (W3C)"],
"What does the abbreviation CSS mean?": ["Cascading Style Sheets"],
"What is the &nbsp; entity for?": ["Introduces a non-breaking space."],
"In HTML each element must have an ID. Is this statement true or false?": ["False"],
"What is new in HTML5? Select all corresponding answers.": [
"New multimedia element <audio>",
"New semantic elements like <header>, <footer>, <article>, and <section>.",
"New types for form input elements like time and date.",
"New multimedia element <video>",
"New types for form input elements like number.",
"New graphic elements: <svg> and <canvas>."
],
"An HTML page can have id(s) applied to one specific element, while a class name can be applied to elements.": ["one unique", "multiple"],
"An HTML page can have one unique id(s) applied to one specific element, while a class name can be applied to multiple elements.": ["False"],
"Match the tags to the fitting type.\n<ol>, <table>, <ul> \n<style> \n<i>, <strong>, <b> ": ["block elements", " CSS formatting", "text formatting"],
"What is the basic syntax of HTML tags that need one attribute?": ["<tagName attributeName=\"value\">content</tagName>"],
"What does the abbreviation HTML mean?": ["Hyper Text Markup Language"],
"What do you need as a preparation for coding HTML?": [
"A basic texteditor or an IDE.",
"A computer or a similar input device.",
"A webbrowser to display the results."
],
"What is the latest and recommended HTML5 version number?": ["HTML 5.2"],
"The form-handler is typically a server page with a script for processing input data. Is this statement true or false?": ["True"],
"Select all valid HTML elements.": [
"<a>",
"<abbr>",
"<h4>",
"<em>",
"<del>",
"<bdo>"
],
"Which attribute opens the action url in a new browser tab?": ["target=\"_blank\""],
"The Method is used to transfer form input which is sensitive and shouldn't be displayed open.\nThe Method is used to transfer form input in plaintext over the URL.": ["POST", "GET"],
"What is the correct tag for a line break in HTML?": ["<br>"],
"Select all statements which are true about the HTML canvas tag.": [
"You must use JavaScript to actually draw the graphics.",
"The HTML <canvas> elements is used to draw graphics",
"The code\nvar c = document.getElementById(\"myCanvas\");\nvar ctx = c.getContext(\"2d\");\nctx.beginPath();\nctx.arc(95,50,30,0,2*Math.PI);\nctx.stroke\ndraws a circle",
"The <canvas> element is only a container for graphics.",
"By default, a canvas has no border and no content."
],
"The HTML <body> element is used to store <style> and <link> elements. Is this statement true or false?": ["False"],
"Select all elements which should be in the head tag.": ["<title>", "<meta>", "<style>", "<link>"],
"Combine the tags to their purpose.": {
"<var>": "various text",
"<pre>": "preformated text",
"<code>": "used for program code",
"<kbd>": "denotes keyboard input",
"<samp>": "used for sample computer output"
},
"Select all contributions which contribute to an elements bounding box (pixel size) in the box model.": ["Height", "Width", "Border", "Padding"],
"The title tag specifies additional information about an element, which is often shown as a tooltip when the mouse moves over an element. Is this statement true or false?": [
"False"
],
"Choose 3 ways to specify a color in HTML or CSS.": [
"style=\"color:green\"",
"style=\"color:#ff6347\"",
"style=\"color:rgb(255, 99, 71)\""
],
"By whom Web Standards are made?": ["W3C", "World Wide Web Consortium"],
"How does the definition of the doctype of an HTML5 document look like?": ["<!DOCTYPE html>"],
"XHTML is a combination of the strength of both XML and HTML to allow browser to interpret the document more efficiently. Is this statement true or false?": ["True"],
"Select the right expression to introduce a special character using its entity number in your HTML code.": ["&#"],
"How a CSS class may be used?": [".classname"],
"Which input type does not exist?": [
"textfield",
"key",
"age",
"picture"
]
}

8
lzk/test-questions.json Normal file
View File

@ -0,0 +1,8 @@
{
"Answer is \"A\"": ["A"],
"Choose \"Yay\", \"Woo\" and \"Sus\"": ["Yay", "Woo", "Sus"],
"Is\n\n\n0 == true\n\nor\n\n\n0 == false?": ["Falsch"],
"The impostor is and .\n\nCrewmates are and .": ["sus", "a sussy baka", "very nice", "innocent"],
"Very weird formatting, but the answer is sus": ["The correct code is let a = \"sus\"; console.log(a);."],
"Choose": {"Choose \"A\"": "A", "Choose \"B\"": "B", "Choose \"C\"": "C"}
}

View File

@ -26,9 +26,6 @@
animation: blinkImg 1s infinite linear; animation: blinkImg 1s infinite linear;
} }
span {
}
@keyframes blinkImg { @keyframes blinkImg {
50% { 50% {
border: 10px solid red; border: 10px solid red;