| 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 | } |
| 61 | |
| 62 | if (hasTryAgainButton && buttons.length === 1) { |
| 63 | return true; |
| 64 | } |
| 65 | |
| 66 | // otherwise, check if open screen is not visible |
| 67 | const isOpenScreen = document.querySelector("h1.text-4xl"); |
| 68 | if (isOpenScreen) { |
| 69 | return false; |
| 70 | } |
| 71 | |
| 72 | // check if the conversation is finished and there are no share buttons |
| 73 | const finishedConversation = document.querySelector("form button>svg"); |
| 74 | const hasShareButtons = actionsArea.querySelectorAll("button[share-ext]"); |
| 75 | if (finishedConversation && !hasShareButtons.length) { |
| 76 | return true; |
| 77 | } |
| 78 | |
| 79 | return false; |
| 80 | } |
| 81 | |
| 82 | function removeButtons() { |
| 83 | const downloadPngButton = document.getElementById("download-png-button"); |