()
| 1 | // *** Core Script - Export *** |
| 2 | |
| 3 | async function init() { |
| 4 | if (window.location.pathname === '/auth/login') return; |
| 5 | const buttonOuterHTMLFallback = `<button class="btn flex justify-center gap-2 btn-neutral" id="download-png-button">Try Again</button>`; |
| 6 | removeButtons(); |
| 7 | if (window.buttonsInterval) { |
| 8 | clearInterval(window.buttonsInterval); |
| 9 | } |
| 10 | if (window.innerWidth < 767) return; |
| 11 | |
| 12 | const chatConf = await invoke('get_app_conf') || {}; |
| 13 | window.buttonsInterval = setInterval(() => { |
| 14 | const actionsArea = document.querySelector("form>div>div"); |
| 15 | if (!actionsArea) { |
| 16 | return; |
| 17 | } |
| 18 | |
| 19 | if (shouldAddButtons(actionsArea)) { |
| 20 | let TryAgainButton = actionsArea.querySelector("button"); |
| 21 | if (!TryAgainButton) { |
| 22 | const parentNode = document.createElement("div"); |
| 23 | parentNode.innerHTML = buttonOuterHTMLFallback; |
| 24 | TryAgainButton = parentNode.querySelector("button"); |
| 25 | } |
| 26 | addActionsButtons(actionsArea, TryAgainButton, chatConf); |
| 27 | } else if (shouldRemoveButtons()) { |
| 28 | removeButtons(); |
| 29 | } |
| 30 | }, 1000); |
| 31 | |
| 32 | const Format = { |
| 33 | PNG: "png", |
| 34 | PDF: "pdf", |
| 35 | }; |
| 36 | |
| 37 | function shouldRemoveButtons() { |
| 38 | if (document.querySelector("form .text-2xl")) { |
| 39 | return true; |
| 40 | } |
| 41 | return false; |
| 42 | } |
| 43 | |
| 44 | function shouldAddButtons(actionsArea) { |
| 45 | // first, check if there's a "Try Again" button and no other buttons |
| 46 | const buttons = actionsArea.querySelectorAll("button"); |
| 47 | |
| 48 | const hasTryAgainButton = Array.from(buttons).some((button) => { |
| 49 | return !/download-/.test(button.id); |
| 50 | }); |
| 51 | |
| 52 | const stopBtn = buttons?.[0]?.innerText; |
| 53 | |
| 54 | if (/Stop generating/ig.test(stopBtn)) { |
| 55 | return false; |
| 56 | } |
| 57 | |
| 58 | if (buttons.length === 2 && (/Regenerate response/ig.test(stopBtn) || buttons[1].innerText === '')) { |
| 59 | return true; |
| 60 | } |
no test coverage detected