|
| 1 | +import { Chatbot } from '../types/chatbot' |
| 2 | +import { |
| 3 | + add_apply_response_button, |
| 4 | + observe_for_responses |
| 5 | +} from '../utils/add-apply-response-button' |
| 6 | +import { |
| 7 | + InitializationError, |
| 8 | + report_initialization_error |
| 9 | +} from '../utils/report-initialization-error' |
| 10 | + |
| 11 | +export const minimax: Chatbot = { |
| 12 | + wait_until_ready: async () => { |
| 13 | + await new Promise((resolve) => { |
| 14 | + const check_for_element = () => { |
| 15 | + if (document.querySelector('textarea')) { |
| 16 | + resolve(null) |
| 17 | + } else { |
| 18 | + setTimeout(check_for_element, 100) |
| 19 | + } |
| 20 | + } |
| 21 | + check_for_element() |
| 22 | + }) |
| 23 | + }, |
| 24 | + inject_apply_response_button: ( |
| 25 | + client_id: number, |
| 26 | + raw_instructions?: string, |
| 27 | + edit_format?: string |
| 28 | + ) => { |
| 29 | + const add_buttons = (footer: Element) => { |
| 30 | + add_apply_response_button({ |
| 31 | + client_id, |
| 32 | + raw_instructions, |
| 33 | + edit_format, |
| 34 | + footer, |
| 35 | + get_chat_turn: (f) => |
| 36 | + f.parentElement!.parentElement!.querySelector('.message'), |
| 37 | + perform_copy: (f) => { |
| 38 | + const copy_button = f.querySelector('div:first-child') as HTMLElement |
| 39 | + if (!copy_button) { |
| 40 | + report_initialization_error({ |
| 41 | + function_name: 'minimax.perform_copy', |
| 42 | + log_message: 'Copy button not found', |
| 43 | + alert_message: InitializationError.UNABLE_TO_COPY_RESPONSE |
| 44 | + }) |
| 45 | + return |
| 46 | + } |
| 47 | + copy_button.click() |
| 48 | + }, |
| 49 | + insert_button: (f, b) => |
| 50 | + f.insertBefore(b, f.children[f.children.length]) |
| 51 | + }) |
| 52 | + } |
| 53 | + |
| 54 | + observe_for_responses({ |
| 55 | + chatbot_name: 'Minimax', |
| 56 | + is_generating: () => |
| 57 | + !!document.querySelector( |
| 58 | + 'path[d="M0 3C0 1.34315 1.34315 0 3 0H9C10.6569 0 12 1.34315 12 3V9C12 10.6569 10.6569 12 9 12H3C1.34315 12 0 10.6569 0 9V3Z"]' |
| 59 | + ) || |
| 60 | + !document.querySelector( |
| 61 | + '.message.received + div > div > div:last-child' |
| 62 | + ), |
| 63 | + footer_selector: '.message.received + div > div', |
| 64 | + add_buttons |
| 65 | + }) |
| 66 | + } |
| 67 | +} |
0 commit comments