diff --git a/README.md b/README.md
index 8263c05..b0ed063 100644
--- a/README.md
+++ b/README.md
@@ -36,12 +36,15 @@ To test the code, you can run the index.js file located in the "test" fol
+- Api key\*: the openai api key.
+- Code\*: code that you will need to inject/remove the code.
+- Langage: the langage you want chatgpt reply (if it's not set it will take the question langage).
- Cursor indication: show a pointer cursor and a hourglass to know when the request is finished.
-- Title indication: Show some informations into the title to know for example if the code have been injected.
+- Title indication: show some informations into the title to know for example if the code have been injected.

- Console logs: show logs into the console.
-- Typing effect: create a typing effect for text.
+- Typing effect: create a typing effect for text. Type any text and it will be replaced by the correct one. If you want to stop it press Backspace key.

- Mouseover effect: you will need to hover (or click for select) the question response to complete it automaticaly.

diff --git a/extension/moodle-gpt.js b/extension/moodle-gpt.js
index baeb02f..72711cc 100644
--- a/extension/moodle-gpt.js
+++ b/extension/moodle-gpt.js
@@ -6,8 +6,8 @@ chrome.storage.sync.get(["moodleGPT"]).then(function (storage) {
//listening to the keys to inject moodleGPT
const pressedKeys = [];
const listeners = [];
- document.body.addEventListener("keypress", function (e) {
- pressedKeys.push(e.key);
+ document.body.addEventListener("keydown", function (event) {
+ pressedKeys.push(event.key);
if (pressedKeys.length > config.code.length) pressedKeys.shift();
if (pressedKeys.join("") === config.code) {
pressedKeys.length = 0;
@@ -70,8 +70,8 @@ chrome.storage.sync.get(["moodleGPT"]).then(function (storage) {
.replace(/[ \t]+/g, " ")
.toLowerCase()
.trim()
- .replace(/^[a-z\d]\.\s/gi, "")
- .replace(/\n[a-z\d]\.\s/gi, "\n");
+ .replace(/^[a-z\d]\.\s/gi, "") //a. text, b. text, c. text, 1. text, 2. text, 3.text
+ .replace(/\n[a-z\d]\.\s/gi, "\n"); //a. text, b. text, c. text, 1. text, 2. text, 3.text
}
/**
@@ -136,14 +136,19 @@ chrome.storage.sync.get(["moodleGPT"]).then(function (storage) {
const question = normalizeText(form.textContent);
const inputList = form.querySelectorAll(query);
- const response = await getChatGPTResponse(
- `Give a short response as possible for this question, reply in this langage "${config.langage}" and only show the result:
+
+ const finalQuestion = `Give a short response as possible for this question, reply in ${
+ config.langage && config.langage !== ""
+ ? 'this langage "' + config.langage + '"'
+ : "the following question langage"
+ } and only show the result:
${question}
- (If you have to choose between multiple results only show the corrects one and do not change the initial text)`
- );
+ (If you have to choose between multiple results only show the corrects one and seprate responses with new line)`;
+
+ const response = await getChatGPTResponse(finalQuestion);
if (config.logs) {
- Logs.question(question);
+ Logs.question(finalQuestion);
Logs.response(response);
}
@@ -162,12 +167,13 @@ chrome.storage.sync.get(["moodleGPT"]).then(function (storage) {
inputList[0].tagName === "TEXTAREA"
) {
if (config.typing) {
- for (let i = 0; i < response.length; ++i) {
- setTimeout(
- () => (inputList[0].value = response.slice(0, i + 1)),
- i * 50
- );
- }
+ let index = 0;
+ inputList[0].addEventListener("keydown", function (event) {
+ if (event.key === "Backspace") index = response.length + 1;
+ if (index > response.length) return;
+ event.preventDefault();
+ inputList[0].value = response.slice(0, ++index);
+ });
} else {
inputList[0].value = response;
}
diff --git a/extension/popup/index.html b/extension/popup/index.html
index 5797cc7..318e85b 100644
--- a/extension/popup/index.html
+++ b/extension/popup/index.html
@@ -20,11 +20,11 @@
/>