This commit is contained in:
yoannchb-pro
2023-03-22 22:25:17 -04:00
committed by GitHub
parent 02ac6bc494
commit 2663989b4e
9 changed files with 115 additions and 7 deletions
+5 -1
View File
@@ -16,7 +16,7 @@ See [changelog](./CHANGELOG.md)
## MoodleGPT don't complete my quiz ?
If MoodleGPT cannot complete one of your moodle quiz please provide the html code of the page. It will help us to add it in the futur version of MoodleGPT !
If MoodleGPT cannot complete one of your moodle quiz please provide the html code of the page. It will help us to add it in the futur version of MoodleGPT ! Check the [TODO](./TODO.md) to see what is comming in the futur version.
## Set up
@@ -78,6 +78,10 @@ Type back the <b>code</b> on the keyboard and the code will be removed from the
![True-false](./assets/true-false.gif)
### Number
![Number](./assets/number.gif)
### Text
![Text](./assets/text.gif)
+5
View File
@@ -0,0 +1,5 @@
# TODO
- [ ] Support multiple input type in a question
- [ ] Support drag and drop quiz
- [ ] Support media for gpt-4
+5 -1
View File
@@ -18,7 +18,11 @@
"content_scripts": [
{
"matches": ["*://*/mod/quiz/*", "http://localhost:*/*"],
"matches": [
"*://*/mod/quiz/*",
"http://localhost:*/*",
"http://127.0.0.1:*/*"
],
"js": ["moodle-gpt.js"],
"run_at": "document_end"
}
+41 -2
View File
@@ -249,6 +249,40 @@
navigator.clipboard.writeText(response);
}
/**
* Handle number input
* @param config
* @param inputList
* @param response
* @returns
*/
function handleNumber(config, inputList, response) {
var _a, _b;
const input = inputList[0];
if (inputList.length !== 1 || input.type !== "number")
return false;
const number = (_b = (_a = response.match(/\d+([,\.]\d+)?/gi)) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.replace(",", ".");
if (!number)
return false;
if (config.typing) {
let index = 0;
input.addEventListener("keydown", function (event) {
if (event.key === "Backspace")
index = number.length + 1;
if (index > number.length)
return;
event.preventDefault();
if (number.slice(index, index + 1) === ".")
++index;
input.value = number.slice(0, ++index);
});
}
else {
input.value = number;
}
return true;
}
/**
* Reply to the question
* @param config
@@ -272,7 +306,12 @@
}
if (config.cursor)
hiddenButton.style.cursor = config.infinite ? "pointer" : "initial";
const handlers = [handleTextbox, handleSelect, handleRadioAndCheckbox];
const handlers = [
handleTextbox,
handleNumber,
handleSelect,
handleRadioAndCheckbox,
];
for (const handler of handlers) {
if (handler(config, inputList, response))
return;
@@ -317,7 +356,7 @@
return;
}
//injection
const inputQuery = ["checkbox", "radio", "text"]
const inputQuery = ["checkbox", "radio", "text", "number"]
.map((e) => `input[type="${e}"]`)
.join(",");
const query = inputQuery + ", textarea, select";
File diff suppressed because one or more lines are too long
+2 -1
View File
@@ -41,7 +41,7 @@ function setUpMoodleGpt(config: Config) {
}
//injection
const inputQuery = ["checkbox", "radio", "text"]
const inputQuery = ["checkbox", "radio", "text", "number"]
.map((e) => `input[type="${e}"]`)
.join(",");
const query = inputQuery + ", textarea, select";
@@ -49,6 +49,7 @@ function setUpMoodleGpt(config: Config) {
for (const form of forms) {
const hiddenButton: HTMLElement = form.querySelector(".qtext");
if (config.cursor) hiddenButton.style.cursor = "pointer";
const fn = reply.bind(null, config, hiddenButton, form, query);
listeners.push({ element: hiddenButton, fn });
+39
View File
@@ -0,0 +1,39 @@
import Config from "../../types/config";
/**
* Handle number input
* @param config
* @param inputList
* @param response
* @returns
*/
function handleNumber(
config: Config,
inputList: NodeListOf<HTMLElement>,
response: string
): boolean {
const input = inputList[0] as HTMLInputElement | HTMLTextAreaElement;
if (inputList.length !== 1 || input.type !== "number") return false;
const number = response.match(/\d+([,\.]\d+)?/gi)?.[0]?.replace(",", ".");
if (!number) return false;
if (config.typing) {
let index = 0;
input.addEventListener("keydown", function (event: KeyboardEvent) {
if (event.key === "Backspace") index = number.length + 1;
if (index > number.length) return;
event.preventDefault();
if (number.slice(index, index + 1) === ".") ++index;
input.value = number.slice(0, ++index);
});
} else {
input.value = number;
}
return true;
}
export default handleNumber;
+7 -1
View File
@@ -6,6 +6,7 @@ import handleRadioAndCheckbox from "./questions/radio-checkbox";
import handleSelect from "./questions/select";
import handleTextbox from "./questions/textbox";
import handleClipboard from "./questions/clipboard";
import handleNumber from "./questions/number";
/**
* Reply to the question
@@ -38,7 +39,12 @@ async function reply(
if (config.cursor)
hiddenButton.style.cursor = config.infinite ? "pointer" : "initial";
const handlers = [handleTextbox, handleSelect, handleRadioAndCheckbox];
const handlers = [
handleTextbox,
handleNumber,
handleSelect,
handleRadioAndCheckbox,
];
for (const handler of handlers) {
if (handler(config, inputList, response)) return;
+10
View File
@@ -67,6 +67,16 @@
</div>
</section>
<!-- Number -->
<section class="formulation">
<div class="qtext">
<p>What is the result of 17/20</p>
</div>
<div>
<input type="number" />
</div>
</section>
<!-- Select -->
<section class="formulation">
<div class="qtext">