diff options
| author | ache <ache@ache.one> | 2025-08-16 04:14:57 +0200 |
|---|---|---|
| committer | ache <ache@ache.one> | 2025-08-16 04:44:21 +0200 |
| commit | cf116178ee9949334a7bafe61c8fd2971c7bd0f6 (patch) | |
| tree | 6a1d7024390cfcf72da45be1defd0dc3e079ecff | |
| parent | Remove unecessary logs (diff) | |
Replace the clipboard export with a download export
| -rw-r--r-- | control.js | 31 |
1 files changed, 22 insertions, 9 deletions
@@ -1,10 +1,30 @@ +function exportData(data, filename) { + const blob = new Blob([data], { type: 'text/plain' }); + const url = URL.createObjectURL(blob); + + browser.downloads.download({ + url, + filename: filename, + saveAs: false // Demande à l'utilisateur où enregistrer le fichier + }).catch(e => console.error(e)); + + const handleChanged = (delta) => { + if (delta.state && delta.state.current === "complete") { + console.info(`Download ${delta.id} has completed.`); + URL.revokeObjectURL(url); + browser.downloads.onChanged.removeListener(handleChanged); + } + }; + + browser.downloads.onChanged.addListener(handleChanged); +} + document.querySelector('#exportJSON').addEventListener('click', () => { const data = JSON.stringify(); - console.log("Ask to export in JSON"); chrome.runtime.sendMessage({export: "JSON"}, function(response) { if (response && response.data && response.data != "") { - writeClipboardText(response.data); + exportData(response.data, "cert_check_navigation_data.json"); } }); }); @@ -18,10 +38,3 @@ document.querySelector('#clearData').addEventListener('click', () => { }); }); -async function writeClipboardText(text) { - try { - await navigator.clipboard.writeText(text); - } catch (error) { - console.error(error.message); - } -} |