()
| 133 | } |
| 134 | |
| 135 | async function captureCurrentPayload(): Promise<void> { |
| 136 | if (!currentPayload) { |
| 137 | setStatus('No active page to capture.', true) |
| 138 | return |
| 139 | } |
| 140 | |
| 141 | settings = readSettingsFromForm() |
| 142 | await saveSettings(settings) |
| 143 | |
| 144 | if (!settings.apiToken.trim()) { |
| 145 | setStatus('Set the massCode API token first.', true) |
| 146 | return |
| 147 | } |
| 148 | |
| 149 | if (!canCaptureCurrentTarget()) { |
| 150 | setStatus('Select text on the page to save a snippet.', true) |
| 151 | return |
| 152 | } |
| 153 | |
| 154 | try { |
| 155 | const request = buildCaptureRequest( |
| 156 | activeTarget, |
| 157 | currentPayload, |
| 158 | captureNameInput?.value, |
| 159 | ) |
| 160 | const result = await postCapture(settings, request) |
| 161 | setStatus(`Saved ${result.target} item #${result.id}.`) |
| 162 | } |
| 163 | catch (error) { |
| 164 | setStatus(getErrorMessage(error), true) |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | async function getActiveTabCapture(): Promise<PageCapturePayload> { |
| 169 | const [tab] = await chrome.tabs.query({ active: true, currentWindow: true }) |
no test coverage detected