import React, { useState } from 'react'; // 定义输入框信息类型 interface InputInfo { id: string; name: string; type: string; value: string; placeholder: string; } // 定义自动发送消息的配置 interface AutoSendConfig { inputSelector: string; buttonSelector: string; messages: string[]; } export default function AutoOptions() { const [inputs, setInputs] = useState([]); const [showInputs, setShowInputs] = useState(false); const [autoSendConfig, setAutoSendConfig] = useState({ inputSelector: '.semi-input-textarea', // 设置默认输入框选择器 buttonSelector: '#flow-end-msg-send', // 设置默认按钮选择器 messages: Array.from({ length: 10 }, (_, i) => { const num = i + 1; return num === 1 ? ['0', num.toString()] : [`0${num - 1}`, num.toString()]; }).flat() // 生成 ["0", "1", "01", "2", "02", "3", ..., "09", "10"] }); const [isAutoSending, setIsAutoSending] = useState(false); const [autoSendResults, setAutoSendResults] = useState([]); // 自动发送消息 const autoSendMessages = async () => { setIsAutoSending(true); setAutoSendResults([]); try { const [tab] = await browser.tabs.query({ active: true, currentWindow: true }); if (tab.id) { const response = await browser.tabs.sendMessage(tab.id, { action: "autoSendMessages", ...autoSendConfig }); if (response.success) { setAutoSendResults(response.results); } else { console.error('自动发送消息失败:', response.error); } } } catch (error) { console.error('自动发送消息出错:', error); } finally { setIsAutoSending(false); } }; // 更新自动发送配置 const updateAutoSendConfig = (field: keyof AutoSendConfig, value: string | string[]) => { setAutoSendConfig(prev => ({ ...prev, [field]: value })); }; return ( <>

页面分析工具

{/* 自动发送消息配置区域 */}

自动发送消息