diff --git a/extension/popup/js/index.js b/extension/popup/js/index.js
index c9487f4..304002e 100644
--- a/extension/popup/js/index.js
+++ b/extension/popup/js/index.js
@@ -10,7 +10,6 @@ const inputsCheckbox = [
"typing",
"mouseover",
"infinite",
- "table",
"timeout",
];
@@ -73,7 +72,7 @@ saveBtn.addEventListener("click", function () {
const [apiKey, code, model] = inputsText.map((selector) =>
document.querySelector("#" + selector).value.trim()
);
- const [logs, title, cursor, typing, mouseover, infinite, table, timeout] =
+ const [logs, title, cursor, typing, mouseover, infinite, timeout] =
inputsCheckbox.map((selector) => {
const element = document.querySelector("#" + selector);
return element.checked && element.parentElement.style.display !== "none";
@@ -100,7 +99,6 @@ saveBtn.addEventListener("click", function () {
typing,
mouseover,
infinite,
- table,
timeout,
mode: actualMode,
},
diff --git a/extension/popup/js/version.js b/extension/popup/js/version.js
index a245508..030532c 100644
--- a/extension/popup/js/version.js
+++ b/extension/popup/js/version.js
@@ -1,4 +1,4 @@
-const currentVersion = "1.0.2";
+const currentVersion = "1.0.3";
const versionDisplay = document.querySelector("#version");
/**
diff --git a/package.json b/package.json
index 5cd74ca..8a6f118 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "moodlegpt",
- "version": "1.0.2",
+ "version": "1.0.3",
"description": "This extension allows you to hide CHAT-GPT in a Moodle quiz.",
"scripts": {
"build": "rollup -c"
diff --git a/src/core/code-listener.ts b/src/core/code-listener.ts
index f281506..196674b 100644
--- a/src/core/code-listener.ts
+++ b/src/core/code-listener.ts
@@ -29,7 +29,7 @@ function codeListener(config: Config) {
* @returns
*/
function setUpMoodleGpt(config: Config) {
- //removing events
+ /* Removing events */
if (listeners.length > 0) {
for (const listener of listeners) {
if (config.cursor) listener.element.style.cursor = "initial";
@@ -40,7 +40,7 @@ function setUpMoodleGpt(config: Config) {
return;
}
- //injection
+ /* Code injection */
const inputQuery = ["checkbox", "radio", "text", "number"]
.map((e) => `input[type="${e}"]`)
.join(",");
diff --git a/src/core/normalize-question.ts b/src/core/create-question.ts
similarity index 54%
rename from src/core/normalize-question.ts
rename to src/core/create-question.ts
index 1be2239..bc14b38 100644
--- a/src/core/normalize-question.ts
+++ b/src/core/create-question.ts
@@ -1,32 +1,30 @@
-import Config from "../types/config";
-import normalizeText from "../utils/normalize-text";
-import htmlTableToString from "../utils/html-table-to-string";
-
-/**
- * Normalize the question and add sub informations
- * @param langage
- * @param question
- * @returns
- */
-function normalizeQuestion(config: Config, questionContainer: HTMLElement) {
- let question = questionContainer.textContent;
-
- if (config.table) {
- //make table more readable for chat-gpt
- const tables: NodeListOf
=
- questionContainer.querySelectorAll(".qtext table");
- for (const table of tables) {
- question = question.replace(
- table.textContent,
- "\n" + htmlTableToString(table) + "\n"
- );
- }
- }
-
- const finalQuestion = `Give a short response as possible for this question, reply in the following question langage and only show the result:
- ${question}
- (If you have to choose between multiple results only show the corrects one, separate them with new line and take the same text as the question)`;
- return normalizeText(finalQuestion);
-}
-
-export default normalizeQuestion;
+import Config from "../types/config";
+import normalizeText from "../utils/normalize-text";
+import htmlTableToString from "../utils/html-table-to-string";
+
+/**
+ * Normalize the question and add sub informations
+ * @param langage
+ * @param question
+ * @returns
+ */
+function createQuestion(config: Config, questionContainer: HTMLElement) {
+ let question = questionContainer.innerText;
+
+ /* Make tables more readable for chat-gpt */
+ const tables: NodeListOf =
+ questionContainer.querySelectorAll(".qtext table");
+ for (const table of tables) {
+ question = question.replace(
+ table.innerText,
+ "\n" + htmlTableToString(table) + "\n"
+ );
+ }
+
+ const finalQuestion = `Give a short response as possible for this question, reply in the following question langage and only show the result:
+ ${question}
+ (If you have to choose between multiple results only show the corrects one, separate them with new line and take the same text as the question)`;
+ return normalizeText(finalQuestion);
+}
+
+export default createQuestion;
diff --git a/src/core/questions/contenteditable.ts b/src/core/questions/contenteditable.ts
index 9870bc2..fbe9508 100644
--- a/src/core/questions/contenteditable.ts
+++ b/src/core/questions/contenteditable.ts
@@ -21,7 +21,7 @@ function handleContentEditable(
event.preventDefault();
input.textContent = response.slice(0, ++index);
- //put the cursor at the end
+ /* Put the cursor at the end of the typed text */
input.focus();
const range = document.createRange();
range.selectNodeContents(input);
diff --git a/src/core/questions/select.ts b/src/core/questions/select.ts
index 0b65e36..e310fb9 100644
--- a/src/core/questions/select.ts
+++ b/src/core/questions/select.ts
@@ -29,7 +29,7 @@ function handleSelect(
const content = normalizeText(option.textContent);
const valide = correct[j].includes(content);
- //if it's a put in order
+ /* Handle put in order question */
if (!isNaN(parseInt(content))) {
const content = normalizeText(
(option.parentNode as HTMLElement)
@@ -56,7 +56,7 @@ function handleSelect(
break;
}
}
- //end put in order
+ /* End */
if (config.logs) Logs.responseTry(content, valide);
diff --git a/src/core/reply.ts b/src/core/reply.ts
index 2a861b3..97b61b2 100644
--- a/src/core/reply.ts
+++ b/src/core/reply.ts
@@ -1,7 +1,7 @@
import Config from "../types/config";
import Logs from "../utils/logs";
import getChatGPTResponse from "./get-response";
-import normalizeQuestion from "./normalize-question";
+import createQuestion from "./create-question";
import handleRadioAndCheckbox from "./questions/radio-checkbox";
import handleSelect from "./questions/select";
import handleTextbox from "./questions/textbox";
@@ -25,9 +25,7 @@ async function reply(
) {
if (config.cursor) hiddenButton.style.cursor = "wait";
- form.querySelector(".accesshide")?.remove();
-
- const question = normalizeQuestion(config, form);
+ const question = createQuestion(config, form);
const inputList: NodeListOf = form.querySelectorAll(query);
const response = await getChatGPTResponse(config, question).catch(
diff --git a/src/types/config.d.ts b/src/types/config.d.ts
index 3259f61..dc5392a 100644
--- a/src/types/config.d.ts
+++ b/src/types/config.d.ts
@@ -8,7 +8,6 @@ type Config = {
cursor?: boolean;
logs?: boolean;
title?: boolean;
- table?: boolean;
timeout?: boolean;
mode?: "autocomplete" | "question-to-answer" | "clipboard";
};
diff --git a/src/utils/html-table-to-string.ts b/src/utils/html-table-to-string.ts
index e60cd58..0d23c7c 100644
--- a/src/utils/html-table-to-string.ts
+++ b/src/utils/html-table-to-string.ts
@@ -26,8 +26,11 @@ function htmlTableToString(table: HTMLTableElement) {
"\n" + Array(lineSeparationSize).fill("-").join("") + "\n";
const mappedTab = tab.map((line) => {
- const mappedLine = line.map(
- (content, index) => content.padEnd(maxColumnsLength[index], "\u00A0") //for no matching with \s
+ const mappedLine = line.map((content, index) =>
+ content.padEnd(
+ maxColumnsLength[index],
+ "\u00A0" /* For no matching with \s */
+ )
);
return "| " + mappedLine.join(" | ") + " |";
});
diff --git a/src/utils/normalize-text.ts b/src/utils/normalize-text.ts
index 7b65481..3442828 100644
--- a/src/utils/normalize-text.ts
+++ b/src/utils/normalize-text.ts
@@ -4,7 +4,8 @@
*/
function normalizeText(text: string) {
return text
- .replace(/(\n\s*)+/gi, "\n")
+ .replace(/\n+/gi, "\n")
+ .replace(/(\n\s*\n)+/g, "\n") //remove useless white sapce from textcontent
.replace(/[ \t]+/gi, " ")
.toLowerCase()
.trim()
diff --git a/test/css/style.css b/test/fake-moodle/css/style.css
similarity index 88%
rename from test/css/style.css
rename to test/fake-moodle/css/style.css
index ac8c39d..bc8746f 100644
--- a/test/css/style.css
+++ b/test/fake-moodle/css/style.css
@@ -1,67 +1,67 @@
-@font-face {
- font-family: Segeo UI;
- src: url(../../extension/fonts/Segoe\ UI.ttf);
-}
-
-* {
- box-sizing: border-box;
- padding: 0;
- margin: 0;
- font-family: "Segeo UI";
-}
-
-body {
- display: flex;
- align-items: center;
- flex-direction: column;
- padding: 1rem;
- gap: 1rem;
-}
-
-h1 {
- text-align: center;
-}
-
-.formulation {
- width: 60%;
- background-color: #e7f3f5;
- padding: 1.5rem;
- display: flex;
- flex-direction: column;
- gap: 1rem;
-}
-
-.inp {
- margin-top: 0.5rem;
- display: flex;
- gap: 0.5rem;
- align-items: center;
- position: relative;
-}
-
-select {
- position: absolute;
- right: 0;
-}
-
-.editable {
- background-color: #fff;
- height: 10rem;
- width: 100%;
- resize: vertical;
- overflow-y: auto;
- white-space: pre-wrap;
- padding: 0.5rem;
- outline: none;
- border: thin solid #000;
-}
-
-textarea {
- outline: none;
- padding: 0.5rem;
- height: 10rem;
- width: 100%;
- resize: vertical;
- white-space: pre-wrap;
- overflow-y: auto;
-}
+@font-face {
+ font-family: Segeo UI;
+ src: url(../../../extension/fonts/Segoe\ UI.ttf);
+}
+
+* {
+ box-sizing: border-box;
+ padding: 0;
+ margin: 0;
+ font-family: "Segeo UI";
+}
+
+body {
+ display: flex;
+ align-items: center;
+ flex-direction: column;
+ padding: 1rem;
+ gap: 1rem;
+}
+
+h1 {
+ text-align: center;
+}
+
+.formulation {
+ width: 60%;
+ background-color: #e7f3f5;
+ padding: 1.5rem;
+ display: flex;
+ flex-direction: column;
+ gap: 1rem;
+}
+
+.inp {
+ margin-top: 0.5rem;
+ display: flex;
+ gap: 0.5rem;
+ align-items: center;
+ position: relative;
+}
+
+select {
+ position: absolute;
+ right: 0;
+}
+
+.editable {
+ background-color: #fff;
+ height: 10rem;
+ width: 100%;
+ resize: vertical;
+ overflow-y: auto;
+ white-space: pre-wrap;
+ padding: 0.5rem;
+ outline: none;
+ border: thin solid #000;
+}
+
+textarea {
+ outline: none;
+ padding: 0.5rem;
+ height: 10rem;
+ width: 100%;
+ resize: vertical;
+ white-space: pre-wrap;
+ overflow-y: auto;
+}
diff --git a/test/index.html b/test/fake-moodle/index.html
similarity index 96%
rename from test/index.html
rename to test/fake-moodle/index.html
index b6631ad..aac6a83 100644
--- a/test/index.html
+++ b/test/fake-moodle/index.html
@@ -1,261 +1,261 @@
-
-
-
-
-
-
- Moodle test
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+ Moodle test
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/reset-moodle-inputs/reset.js b/test/reset-moodle-inputs/reset.js
similarity index 90%
rename from reset-moodle-inputs/reset.js
rename to test/reset-moodle-inputs/reset.js
index 63aef3a..2ba4d86 100644
--- a/reset-moodle-inputs/reset.js
+++ b/test/reset-moodle-inputs/reset.js
@@ -1,22 +1,21 @@
-//to try in real moodle env
-
-for (const option of document.querySelectorAll("option")) {
- option.selected = false;
- option.disabled = false;
- option.closest("select").disabled = false;
-}
-
-for (const input of document.querySelectorAll(
- 'input[type="radio"], input[type="checkbox"]'
-)) {
- input.checked = false;
- input.disabled = false;
-}
-
-for (const icon of document.querySelectorAll(".text-danger, .text-success")) {
- icon.remove();
-}
-
-for (const feedback of document.querySelectorAll(".specificfeedback")) {
- feedback.remove();
-}
+/* Reset real moodle inputs to try in real env */
+for (const option of document.querySelectorAll("option")) {
+ option.selected = false;
+ option.disabled = false;
+ option.closest("select").disabled = false;
+}
+
+for (const input of document.querySelectorAll(
+ 'input[type="radio"], input[type="checkbox"]'
+)) {
+ input.checked = false;
+ input.disabled = false;
+}
+
+for (const icon of document.querySelectorAll(".text-danger, .text-success")) {
+ icon.remove();
+}
+
+for (const feedback of document.querySelectorAll(".specificfeedback")) {
+ feedback.remove();
+}
diff --git a/extension/banner.png b/webstore-assets/banner1.png
similarity index 100%
rename from extension/banner.png
rename to webstore-assets/banner1.png
diff --git a/extension/128x128.png b/webstore-assets/icon-128x128.png
similarity index 100%
rename from extension/128x128.png
rename to webstore-assets/icon-128x128.png