From 2f2f4752269484f1ec1e563d921a984f3af21808 Mon Sep 17 00:00:00 2001 From: edde746 <86283021+edde746@users.noreply.github.com> Date: Fri, 18 Aug 2023 12:59:16 +0200 Subject: [PATCH] loading indicator --- plugins/gpt/index.jsx | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/plugins/gpt/index.jsx b/plugins/gpt/index.jsx index 9af2fa9..0d61bbb 100644 --- a/plugins/gpt/index.jsx +++ b/plugins/gpt/index.jsx @@ -40,6 +40,31 @@ const getMessageHistory = () => { }, []); }; +const loadingIndicator = () => ( + + + + + + +); + // Credits to yellowsink for this messagebar stuff // https://github.com/yellowsink const appendTextToMessagebar = (text) => { @@ -130,6 +155,20 @@ export function onLoad() { }, ]; + // add loading indicator + const messageBar = document.querySelector( + '[class*="slateContainer-"]' + ); + // get absolute position of messagebar + const { x, y } = messageBar.getBoundingClientRect(); + const loadingIndicatorElem = document.body.appendChild( + loadingIndicator() + ); + + loadingIndicatorElem.style.position = "absolute"; + loadingIndicatorElem.style.left = `${x}px`; + loadingIndicatorElem.style.top = `${y + 12}px`; + fetch("https://api.openai.com/v1/chat/completions", { method: "POST", headers: { @@ -149,6 +188,8 @@ export function onLoad() { .replace(/^(?=.{0,49}:)([\w\s\-]+?[^ ]):/, "") .trim() ); + + loadingIndicatorElem.remove(); }); }} >