diff --git a/public/assets/js/admin-stats.js b/public/assets/js/admin-stats.js index 41060b8..50865a4 100644 --- a/public/assets/js/admin-stats.js +++ b/public/assets/js/admin-stats.js @@ -1,20 +1,87 @@ /* Admin stats : groupes AS + chargement pages via flux RSS XML /trending?period=14d */ -// ── Groupes de réseaux ──────────────────────────────────────────────────────── + +// ── Visiteurs par pays ──────────────────────────────────────────────────────── (function () { - var addBtn = document.getElementById('as-group-add'); - if (!addBtn) { return; } + var el = document.getElementById('stats-country-container'); + var asList = (typeof FOLIO_AS_LIST !== 'undefined') ? FOLIO_AS_LIST : []; + if (!el || !asList.length) { return; } - addBtn.addEventListener('click', function () { - var tpl = document.getElementById('as-group-tpl').content.cloneNode(true); - document.getElementById('as-groups-list').appendChild(tpl); + // Noms de pays en français via l'API Intl + var dispNames = null; + try { dispNames = new Intl.DisplayNames(['fr'], { type: 'region' }); } catch (e) {} + function countryName(code) { + if (!code || code === '??') { return 'Inconnu'; } + try { return dispNames ? dispNames.of(code) : code; } catch (e) { return code; } + } + + // Drapeau emoji depuis le code ISO-2 + function flag(code) { + if (!code || code.length !== 2) { return ''; } + var cp = Array.from(code.toUpperCase()).map(function (c) { + return 0x1F1E6 + c.charCodeAt(0) - 65; + }); + return String.fromCodePoint(cp[0], cp[1]) + ' '; + } + + // Agréger par pays + var byCountry = {}; + var asByCountry = {}; // country → [{name, asn, hits}] + asList.forEach(function (as) { + var c = as.country || '??'; + byCountry[c] = (byCountry[c] || 0) + as.hits; + if (!asByCountry[c]) { asByCountry[c] = []; } + asByCountry[c].push(as); }); - document.getElementById('as-groups-list').addEventListener('click', function (e) { - if (e.target.classList.contains('as-group-delete')) { - e.target.closest('.as-group-row').remove(); - } + var countries = Object.keys(byCountry).map(function (c) { + return { code: c, hits: byCountry[c], networks: asByCountry[c] }; + }).sort(function (a, b) { return b.hits - a.hits; }).slice(0, 20); + + if (!countries.length) { el.innerHTML = '
Aucune donnée.
'; return; } + + var maxH = countries[0].hits || 1; + + var html = '14 derniers jours · visiteurs uniques · flux RSS XML
- +Chargement…
+Regroupez plusieurs réseaux sous un label. Chaque ligne est un motif cherché dans le nom du réseau (insensible à la casse).
- -