adjusted the abort to 15s and fixed can't click back after error
This commit is contained in:
@@ -2,6 +2,7 @@ import Config from "../types/config";
|
||||
import titleIndications from "../utils/title-indications";
|
||||
import reply from "./reply";
|
||||
|
||||
let injectionFunction: (this: HTMLElement, ev: MouseEvent) => any = null;
|
||||
const pressedKeys: string[] = [];
|
||||
const listeners: {
|
||||
element: HTMLElement;
|
||||
@@ -52,12 +53,12 @@ function setUpMoodleGpt(config: Config) {
|
||||
|
||||
if (config.cursor) hiddenButton.style.cursor = "pointer";
|
||||
|
||||
const fn = reply.bind(null, config, hiddenButton, form, query);
|
||||
listeners.push({ element: hiddenButton, fn });
|
||||
hiddenButton.addEventListener("click", fn, { once: !config.infinite });
|
||||
injectionFunction = reply.bind(null, config, hiddenButton, form, query);
|
||||
listeners.push({ element: hiddenButton, fn: injectionFunction });
|
||||
hiddenButton.addEventListener("click", injectionFunction);
|
||||
}
|
||||
|
||||
if (config.title) titleIndications("Injected");
|
||||
}
|
||||
|
||||
export default codeListener;
|
||||
export { injectionFunction, codeListener };
|
||||
|
||||
@@ -12,7 +12,7 @@ async function getChatGPTResponse(
|
||||
question: string
|
||||
): Promise<string> {
|
||||
const controller = new AbortController();
|
||||
const timeoutControler = setTimeout(() => controller.abort(), 10000);
|
||||
const timeoutControler = setTimeout(() => controller.abort(), 15000);
|
||||
const req = await fetch("https://api.openai.com/v1/chat/completions", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
|
||||
+8
-7
@@ -8,6 +8,7 @@ import handleTextbox from "./questions/textbox";
|
||||
import handleClipboard from "./questions/clipboard";
|
||||
import handleNumber from "./questions/number";
|
||||
import handleContentEditable from "./questions/contenteditable";
|
||||
import { injectionFunction } from "./code-listener";
|
||||
|
||||
/**
|
||||
* Reply to the question
|
||||
@@ -33,18 +34,14 @@ async function reply(
|
||||
error,
|
||||
})
|
||||
);
|
||||
|
||||
const haveError = typeof response === "object" && "error" in response;
|
||||
const isAbortError = haveError && response.error.name === "AbortError";
|
||||
|
||||
if (config.cursor)
|
||||
hiddenButton.style.cursor =
|
||||
config.infinite || isAbortError ? "pointer" : "initial";
|
||||
config.infinite || haveError ? "pointer" : "initial";
|
||||
|
||||
if (haveError) {
|
||||
if (isAbortError) {
|
||||
//TODO: We need to inject back the event
|
||||
}
|
||||
|
||||
console.error(response.error);
|
||||
return;
|
||||
}
|
||||
@@ -83,8 +80,12 @@ async function reply(
|
||||
if (handler(config, inputList, response)) return;
|
||||
}
|
||||
|
||||
/** In the case we can't auto complete the question */
|
||||
/* In the case we can't auto complete the question */
|
||||
handleClipboard(config, response);
|
||||
|
||||
/* Better then set once on the event because if there is an error the user can click an other time on the question */
|
||||
if (!config.infinite)
|
||||
hiddenButton.removeEventListener("click", injectionFunction);
|
||||
}
|
||||
|
||||
export default reply;
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
import codeListener from "./core/code-listener";
|
||||
import { codeListener } from "./core/code-listener";
|
||||
|
||||
chrome.storage.sync.get(["moodleGPT"]).then(function (storage) {
|
||||
const config = storage.moodleGPT;
|
||||
|
||||
Reference in New Issue
Block a user