()
| 4 | import { sendToBackground } from "@plasmohq/messaging" |
| 5 | |
| 6 | export default function BatchDownload() { |
| 7 | const [loading, setLoading] = useState(false) |
| 8 | const [message, setMessage] = useState("") |
| 9 | |
| 10 | async function batchDownload() { |
| 11 | if (loading) return |
| 12 | |
| 13 | setLoading(true) |
| 14 | setMessage("正在批量下载...") |
| 15 | |
| 16 | try { |
| 17 | const response = await sendToBackground({ |
| 18 | name: "batchDownload", |
| 19 | body: { |
| 20 | action: "batchDownloadAllTabs" |
| 21 | } |
| 22 | }) |
| 23 | |
| 24 | if (response.code === 200) { |
| 25 | setMessage(response.msg || "下载成功") |
| 26 | setTimeout(() => setMessage(""), 3000) |
| 27 | } else { |
| 28 | setMessage(response.msg || "下载失败") |
| 29 | setTimeout(() => setMessage(""), 3000) |
| 30 | } |
| 31 | } catch (error) { |
| 32 | console.error("Batch download error:", error) |
| 33 | setMessage("下载失败: " + error.message) |
| 34 | setTimeout(() => setMessage(""), 3000) |
| 35 | } finally { |
| 36 | setLoading(false) |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | return ( |
| 41 | <div className="item batch-download"> |
| 42 | <div onClick={batchDownload} style={{ cursor: loading ? "wait" : "pointer" }}> |
| 43 | <span> |
| 44 | <CloudDownloadOutlined |
| 45 | style={{ marginRight: "5px", color: loading ? "#999" : "#1890ff" }} |
| 46 | /> |
| 47 | 批量下载所有标签页 |
| 48 | </span> |
| 49 | <DownloadOutlined |
| 50 | style={{ color: loading ? "#999" : "#52c41a", fontSize: "16px" }} |
| 51 | /> |
| 52 | </div> |
| 53 | {message && ( |
| 54 | <div style={{ fontSize: "12px", color: "#666", marginTop: "5px" }}> |
| 55 | {message} |
| 56 | </div> |
| 57 | )} |
| 58 | </div> |
| 59 | ) |
| 60 | } |
nothing calls this directly
no outgoing calls
no test coverage detected