|
| 1 | +document.addEventListener('DOMContentLoaded', async () => { |
| 2 | + const status = document.getElementById('aaps-eol-status'); |
| 3 | + if (!status) return; |
| 4 | + |
| 5 | + function showRows(id, rows) { |
| 6 | + const container = document.getElementById(id); |
| 7 | + const body = container.querySelector('tbody'); |
| 8 | + for (const values of rows) { |
| 9 | + const row = body.insertRow(); |
| 10 | + for (const value of values) row.insertCell().textContent = value; |
| 11 | + } |
| 12 | + container.hidden = rows.length === 0; |
| 13 | + } |
| 14 | + |
| 15 | + try { |
| 16 | + const response = await fetch('https://raw.githubusercontent.com/nightscout/AndroidAPS/refs/heads/versions/definition.json'); |
| 17 | + if (!response.ok) throw new Error(`HTTP ${response.status}`); |
| 18 | + const data = await response.json(); |
| 19 | + if (!Array.isArray(data)) throw new Error('Invalid version data'); |
| 20 | + |
| 21 | + const versions = data.filter(entry => |
| 22 | + entry && typeof entry.version === 'string' && |
| 23 | + typeof entry.endDate === 'string' && /^\d{4}-\d{2}-\d{2}$/.test(entry.endDate) |
| 24 | + ).sort((a, b) => b.version.localeCompare(a.version, undefined, { numeric: true })); |
| 25 | + const android = data.filter(entry => |
| 26 | + entry && Number.isInteger(entry.minAndroid) && Number.isInteger(entry.maxAndroid) |
| 27 | + ).sort((a, b) => b.minAndroid - a.minAndroid); |
| 28 | + if (!versions.length && !android.length) throw new Error('No version data'); |
| 29 | + |
| 30 | + showRows('aaps-eol-versions', versions.map(entry => [entry.version, entry.endDate])); |
| 31 | + showRows('aaps-eol-android', android.map(entry => [ |
| 32 | + entry.minAndroid === entry.maxAndroid |
| 33 | + ? String(entry.minAndroid) : `${entry.minAndroid}–${entry.maxAndroid}`, |
| 34 | + typeof entry.supported === 'string' && entry.supported ? entry.supported : 'None listed' |
| 35 | + ])); |
| 36 | + status.remove(); |
| 37 | + } catch { |
| 38 | + status.textContent = 'Could not load AAPS version data. Please try again later.'; |
| 39 | + } |
| 40 | +}); |
0 commit comments