This commit is contained in:
yoannchb-pro
2023-03-24 12:36:24 -04:00
parent c4913631ac
commit 790fdb0722
6 changed files with 61 additions and 6 deletions
+1 -1
View File
@@ -44,7 +44,7 @@ function setUpMoodleGpt(config: Config) {
const inputQuery = ["checkbox", "radio", "text", "number"]
.map((e) => `input[type="${e}"]`)
.join(",");
const query = inputQuery + ", textarea, select";
const query = inputQuery + ", textarea, select, [contenteditable]";
const forms = Array.from(document.querySelectorAll(".formulation"));
for (const form of forms) {
+31
View File
@@ -0,0 +1,31 @@
import Config from "../../types/config";
function handleContentEditable(
config: Config,
inputList: NodeListOf<HTMLElement>,
response: string
): boolean {
const input = inputList[0];
if (
inputList.length !== 1 ||
input.getAttribute("contenteditable") !== "true"
)
return false;
if (config.typing) {
let index = 0;
input.addEventListener("keydown", function (event: KeyboardEvent) {
if (event.key === "Backspace") index = response.length + 1;
if (index > response.length) return;
event.preventDefault();
input.textContent = response.slice(0, ++index);
});
} else {
input.textContent = response;
}
return true;
}
export default handleContentEditable;
+2
View File
@@ -7,6 +7,7 @@ import handleSelect from "./questions/select";
import handleTextbox from "./questions/textbox";
import handleClipboard from "./questions/clipboard";
import handleNumber from "./questions/number";
import handleContentEditable from "./questions/contenteditable";
/**
* Reply to the question
@@ -49,6 +50,7 @@ async function reply(
}
const handlers = [
handleContentEditable,
handleTextbox,
handleNumber,
handleSelect,