summaryrefslogtreecommitdiffstats
path: root/g4f/gui/client/js
diff options
context:
space:
mode:
authorHeiner Lohaus <hlohaus@users.noreply.github.com>2024-02-19 18:29:23 +0100
committerHeiner Lohaus <hlohaus@users.noreply.github.com>2024-02-19 18:29:23 +0100
commitd55a4c3ef5301ad7e5686c12513ee816bcf76e6c (patch)
tree33a201a66941a297f92917bdca1c2a4bfaca0575 /g4f/gui/client/js
parentTry to fix Captcha Issue (diff)
downloadgpt4free-d55a4c3ef5301ad7e5686c12513ee816bcf76e6c.tar
gpt4free-d55a4c3ef5301ad7e5686c12513ee816bcf76e6c.tar.gz
gpt4free-d55a4c3ef5301ad7e5686c12513ee816bcf76e6c.tar.bz2
gpt4free-d55a4c3ef5301ad7e5686c12513ee816bcf76e6c.tar.lz
gpt4free-d55a4c3ef5301ad7e5686c12513ee816bcf76e6c.tar.xz
gpt4free-d55a4c3ef5301ad7e5686c12513ee816bcf76e6c.tar.zst
gpt4free-d55a4c3ef5301ad7e5686c12513ee816bcf76e6c.zip
Diffstat (limited to '')
-rw-r--r--g4f/gui/client/js/chat.v1.js44
1 files changed, 27 insertions, 17 deletions
diff --git a/g4f/gui/client/js/chat.v1.js b/g4f/gui/client/js/chat.v1.js
index 2042d174..8461a8f7 100644
--- a/g4f/gui/client/js/chat.v1.js
+++ b/g4f/gui/client/js/chat.v1.js
@@ -32,6 +32,20 @@ const markdown_render = (content) => {
.replaceAll('<code>', '<code class="language-plaintext">')
}
+let typesetPromise = Promise.resolve();
+const highlight = (container) => {
+ container.querySelectorAll('code:not(.hljs').forEach((el) => {
+ if (el.className != "hljs") {
+ hljs.highlightElement(el);
+ }
+ });
+ typesetPromise = typesetPromise.then(
+ () => MathJax.typesetPromise([container])
+ ).catch(
+ (err) => console.log('Typeset failed: ' + err.message)
+ );
+}
+
const delete_conversations = async () => {
localStorage.clear();
await new_conversation();
@@ -73,9 +87,7 @@ const handle_ask = async () => {
</div>
</div>
`;
- document.querySelectorAll('code:not(.hljs').forEach((el) => {
- hljs.highlightElement(el);
- });
+ highlight(message_box);
await ask_gpt();
}
};
@@ -214,9 +226,7 @@ const ask_gpt = async () => {
html = html.substring(0, lastIndex) + '<span id="cursor"></span>' + lastElement;
}
content_inner.innerHTML = html;
- document.querySelectorAll('code:not(.hljs').forEach((el) => {
- hljs.highlightElement(el);
- });
+ highlight(content_inner);
}
window.scrollTo(0, 0);
@@ -331,8 +341,15 @@ const new_conversation = async () => {
const load_conversation = async (conversation_id) => {
let messages = await get_messages(conversation_id);
+ let elements = "";
for (item of messages) {
- message_box.innerHTML += `
+ let provider = item.provider ? `
+ <div class="provider">
+ <a href="${item.provider.url}" target="_blank">${item.provider.name}</a>
+ ${item.provider.model ? ' with ' + item.provider.model : ''}
+ </div>
+ ` : "";
+ elements += `
<div class="message">
<div class=${item.role == "assistant" ? "assistant" : "user"}>
${item.role == "assistant" ? gpt_image : user_image}
@@ -342,19 +359,15 @@ const load_conversation = async (conversation_id) => {
}
</div>
<div class="content">
- ${item.provider
- ? '<div class="provider"><a href="' + item.provider.url + '" target="_blank">' + item.provider.name + '</a></div>'
- : ''
- }
+ ${provider}
<div class="content_inner">${markdown_render(item.content)}</div>
</div>
</div>
`;
}
+ message_box.innerHTML = elements;
- document.querySelectorAll('code:not(.hljs').forEach((el) => {
- hljs.highlightElement(el);
- });
+ highlight(message_box);
message_box.scrollTo({ top: message_box.scrollHeight, behavior: "smooth" });
@@ -447,9 +460,6 @@ const load_conversations = async (limit, offset, loader) => {
`;
}
- document.querySelectorAll('code:not(.hljs').forEach((el) => {
- hljs.highlightElement(el);
- });
};
document.getElementById(`cancelButton`).addEventListener(`click`, async () => {