| 74 | }) |
| 75 | |
| 76 | async function downloadImages( |
| 77 | onProgress?: (current: number, total: number) => void |
| 78 | ) { |
| 79 | const imageUrls = Array.from(document.images).map((img) => img.src) |
| 80 | try { |
| 81 | const res = await sendToBackground({ |
| 82 | name: "download", |
| 83 | body: { |
| 84 | action: "downloadAllImages", |
| 85 | imageUrls: imageUrls, |
| 86 | title: articleTitle, |
| 87 | onProgress: onProgress |
| 88 | } |
| 89 | }) |
| 90 | if (res.code == 0) { |
| 91 | alert(i18n("downloadFailed")) |
| 92 | } |
| 93 | } catch (error) { |
| 94 | console.error(`Failed to download images:`, error) |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | return <CustomDomSelector /> |
| 99 | } |