(() => { document.documentElement.classList.add('js-enabled'); const feedback = document.getElementById('download-feedback'); const report = (message) => { if (feedback) { feedback.textContent = message; feedback.hidden = false; } }; const post = async (path, body = {}) => { const response = await fetch(path, { method: 'POST', credentials: 'same-origin', headers: {'Content-Type': 'application/json'}, body: JSON.stringify(body), }); const payload = await response.json(); if (!response.ok) throw new Error(payload.message || 'The request could not be completed.'); return payload; }; document.querySelectorAll('[data-auto-submit] select').forEach(select => { select.addEventListener('change', () => select.form.requestSubmit()); }); document.querySelectorAll('[data-artifact-select]').forEach(select => { select.addEventListener('change', () => { const option = select.selectedOptions[0]; const panel = select.closest('.platform-panel'); panel.querySelector('[data-file-info]').textContent = option.dataset.format + ' ยท ' + option.dataset.size; panel.querySelector('[data-system-info]').textContent = option.dataset.system; const download = panel.querySelector('[data-latest-download]'); download.href = option.value; download.setAttribute('aria-label', 'Download ' + option.dataset.file); download.lastChild.textContent = 'Download ' + option.dataset.format; }); }); const osText = navigator.userAgentData?.platform || navigator.platform || navigator.userAgent; const os = /mac/i.test(osText) ? 'macos' : /win/i.test(osText) ? 'windows' : /linux/i.test(osText) ? 'linux' : null; const recommended = os && document.querySelector('[data-platform="' + os + '"]'); if (recommended && recommended.querySelector('[data-latest-download]')) { recommended.classList.add('is-recommended'); recommended.querySelector('[data-recommendation]').textContent = 'Recommended for this device'; } const form = document.getElementById('private-download-form'); if (form) form.addEventListener('submit', async event => { event.preventDefault(); const input = document.getElementById('access-key'); const error = document.getElementById('key-error'); const submit = form.querySelector('button'); error.hidden = true; submit.disabled = true; submit.setAttribute('aria-busy', 'true'); try { const result = await post('/downloads/private', {access_key: input.value.trim()}); input.value = ''; window.location.assign(result.location); } catch (failure) { error.textContent = failure.message; error.hidden = false; } finally { submit.disabled = false; submit.removeAttribute('aria-busy'); } }); document.querySelectorAll('[data-clear-key], [data-logout]').forEach(button => { button.addEventListener('click', async () => { button.disabled = true; try { await post('/downloads/private/clear'); if (button.hasAttribute('data-logout')) await post('/auth/v2/web/logout'); window.location.assign('/downloads'); } catch (failure) { report(failure.message); button.disabled = false; } }); }); })();