39 lines
1.4 KiB
JavaScript
39 lines
1.4 KiB
JavaScript
// ── UPDATE CHECKER ────────────────────────────────────────────────────────────
|
|
(async function checkForUpdate() {
|
|
try {
|
|
const [localRes, remoteRes] = await Promise.all([
|
|
fetch('version.json'),
|
|
fetch('https://api.github.com/repos/Johnnybegood90/GridTV/releases/latest')
|
|
]);
|
|
if (!localRes.ok || !remoteRes.ok) return;
|
|
|
|
const local = (await localRes.json()).version ?? '0.0.0';
|
|
const remote = (await remoteRes.json()).tag_name ?? '0.0.0';
|
|
|
|
const clean = v => v.replace(/^v/, '');
|
|
const toNum = v => v.split('.').map(Number);
|
|
|
|
const [lMaj, lMin, lPat] = toNum(clean(local));
|
|
const [rMaj, rMin, rPat] = toNum(clean(remote));
|
|
|
|
const hasUpdate =
|
|
rMaj > lMaj ||
|
|
(rMaj === lMaj && rMin > lMin) ||
|
|
(rMaj === lMaj && rMin === lMin && rPat > lPat);
|
|
|
|
if (!hasUpdate) return;
|
|
|
|
const badge = document.createElement('a');
|
|
badge.className = 'update-badge';
|
|
badge.href = `https://github.com/Johnnybegood90/GridTV/releases/latest`;
|
|
badge.target = '_blank';
|
|
badge.rel = 'noopener';
|
|
badge.innerHTML = `${L.update_available} ${clean(remote)}`;
|
|
badge.title = L.update_title;
|
|
|
|
document.querySelector('.topbar')?.appendChild(badge);
|
|
} catch (_) {
|
|
// Silencieux — pas de connexion ou rate limit GitHub
|
|
}
|
|
})();
|