diff --git a/src/index.html b/src/index.html index 4a116fc..ec72487 100644 --- a/src/index.html +++ b/src/index.html @@ -89,6 +89,9 @@ +
+ +
diff --git a/src/js/index.js b/src/js/index.js index b682c2a..d1e88f9 100644 --- a/src/js/index.js +++ b/src/js/index.js @@ -204,6 +204,33 @@ const checkProxy = async () => { }) } +_('download-lua').onclick = async () => { + downloadFile(`firmware/${versionSelect.value}/lua/elrsV3.lua`, 'elrsV3.lua') +} + +async function downloadFile (url, filename) { + try { + const response = await fetch(url) + if (response.status !== 200) { + throw new Error(`Unable to download file. HTTP status: ${response.status}`) + } + const blob = await response.blob() + const downloadLink = document.createElement('a') + downloadLink.href = URL.createObjectURL(blob) + downloadLink.download = filename + + document.body.appendChild(downloadLink) + downloadLink.click() + + setTimeout(() => { + URL.revokeObjectURL(downloadLink.href) + document.body.removeChild(downloadLink) + }, 100) + } catch (error) { + console.error('Error downloading the file:', error.message) + } +} + function initialise () { checkProxy() setInterval(() => { checkProxy() }, 30000)