v1.0.0
This commit is contained in:
@@ -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 });
|
||||
|
||||
@@ -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
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user