From 2547c4b974668f543d33ebb484127bc58e383189 Mon Sep 17 00:00:00 2001 From: yoannchb-pro <71560747+yoannchb-pro@users.noreply.github.com> Date: Tue, 21 Mar 2023 00:21:48 -0400 Subject: [PATCH] v1.0.0 --- README.md | 7 +++++-- extension/moodle-gpt.js | 36 +++++++++++++++++++++--------------- extension/popup/index.html | 6 +++--- extension/popup/index.js | 5 +---- 4 files changed, 30 insertions(+), 24 deletions(-) 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 Popup

+- 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.
![Injected](./assets/title-injected.png) - Console logs: show logs into the console.
Logs -- 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.
![Typing](./assets/typing.gif) - Mouseover effect: you will need to hover (or click for select) the question response to complete it automaticaly.
![Mouseover](./assets/mouseover.gif) 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 @@ />

MoodleGPT

- +
- +
@@ -32,7 +32,7 @@
- +
diff --git a/extension/popup/index.js b/extension/popup/index.js index bae5a3c..ef6b53d 100644 --- a/extension/popup/index.js +++ b/extension/popup/index.js @@ -20,7 +20,7 @@ saveBtn.addEventListener("click", function () { (selector) => document.querySelector("#" + selector).checked ); - if (!apiKey || !code || !langage) { + if (!apiKey || !code) { showMessage("Please comple all the form"); return; } @@ -56,8 +56,5 @@ chrome.storage.sync.get(["moodleGPT"]).then(function (storage) { inputsCheckbox.forEach( (key) => (document.querySelector("#" + key).checked = config[key] || "") ); - } else { - //set default config - document.querySelector("#langage").value = navigator.language; } });