diff options
Diffstat (limited to 'g4f/gui/client/js/chat.v1.js')
-rw-r--r-- | g4f/gui/client/js/chat.v1.js | 59 |
1 files changed, 39 insertions, 20 deletions
diff --git a/g4f/gui/client/js/chat.v1.js b/g4f/gui/client/js/chat.v1.js index 86eef8c9..a243b1de 100644 --- a/g4f/gui/client/js/chat.v1.js +++ b/g4f/gui/client/js/chat.v1.js @@ -8,6 +8,7 @@ const stop_generating = document.querySelector(`.stop_generating`); const regenerate = document.querySelector(`.regenerate`); const send_button = document.querySelector(`#send-button`); const imageInput = document.querySelector('#image'); +const cameraInput = document.querySelector('#camera'); const fileInput = document.querySelector('#file'); let prompt_lock = false; @@ -63,6 +64,10 @@ const handle_ask = async () => { ? '<img src="' + imageInput.dataset.src + '" alt="Image upload">' : '' } + ${cameraInput.dataset.src + ? '<img src="' + cameraInput.dataset.src + '" alt="Image capture">' + : '' + } </div> </div> `; @@ -95,6 +100,11 @@ const ask_gpt = async () => { delete messages[i]["provider"]; } + // Remove history, if it is selected + if (document.getElementById('history')?.checked) { + messages = [messages[messages.length-1]] + } + window.scrollTo(0, 0); window.controller = new AbortController(); @@ -141,9 +151,10 @@ const ask_gpt = async () => { const headers = { accept: 'text/event-stream' } - if (imageInput && imageInput.files.length > 0) { + const input = imageInput && imageInput.files.length > 0 ? imageInput : cameraInput + if (input && input.files.length > 0) { const formData = new FormData(); - formData.append('image', imageInput.files[0]); + formData.append('image', input.files[0]); formData.append('json', body); body = formData; } else { @@ -211,8 +222,11 @@ const ask_gpt = async () => { message_box.scrollTo({ top: message_box.scrollHeight, behavior: "auto" }); } } - if (!error && imageInput) imageInput.value = ""; - if (!error && fileInput) fileInput.value = ""; + if (!error) { + if (imageInput) imageInput.value = ""; + if (cameraInput) cameraInput.value = ""; + if (fileInput) fileInput.value = ""; + } } catch (e) { console.error(e); @@ -482,7 +496,7 @@ document.querySelector(".mobile-sidebar").addEventListener("click", (event) => { }); const register_settings_localstorage = async () => { - for (id of ["switch", "model", "jailbreak", "patch", "provider"]) { + for (id of ["switch", "model", "jailbreak", "patch", "provider", "history"]) { element = document.getElementById(id); element.addEventListener('change', async (event) => { switch (event.target.type) { @@ -500,7 +514,7 @@ const register_settings_localstorage = async () => { } const load_settings_localstorage = async () => { - for (id of ["switch", "model", "jailbreak", "patch", "provider"]) { + for (id of ["switch", "model", "jailbreak", "patch", "provider", "history"]) { element = document.getElementById(id); value = localStorage.getItem(element.id); if (value) { @@ -668,21 +682,26 @@ observer.observe(message_input, { attributes: true }); } document.getElementById("version_text").innerHTML = text })() -imageInput.addEventListener('click', async (event) => { - imageInput.value = ''; - delete imageInput.dataset.src; -}); -imageInput.addEventListener('change', async (event) => { - if (imageInput.files.length) { - const reader = new FileReader(); - reader.addEventListener('load', (event) => { - imageInput.dataset.src = event.target.result; - }); - reader.readAsDataURL(imageInput.files[0]); - } else { - delete imageInput.dataset.src; +for (const el of [imageInput, cameraInput]) { + console.log(el.files); + el.addEventListener('click', async () => { + el.value = ''; + delete el.dataset.src; + }); + do_load = async () => { + if (el.files.length) { + delete imageInput.dataset.src; + delete cameraInput.dataset.src; + const reader = new FileReader(); + reader.addEventListener('load', (event) => { + el.dataset.src = event.target.result; + }); + reader.readAsDataURL(el.files[0]); + } } -}); + do_load() + el.addEventListener('change', do_load); +} fileInput.addEventListener('click', async (event) => { fileInput.value = ''; delete fileInput.dataset.text; |