<style>
.spl-results-wrap {
font-family: Arial, sans-serif;
max-width: 700px;
margin: 0 auto;
}
.spl-results-wrap[dir="rtl"] { font-family: 'Segoe UI', Tahoma, Arial, sans-serif; }
.spl-section-title {
font-size: 18px;
font-weight: 700;
color: #1a1a2e;
margin-bottom: 14px;
}
.spl-match-card {
background: #fff;
border-radius: 10px;
box-shadow: 0 2px 8px rgba(0,0,0,0.07);
margin-bottom: 10px;
padding: 14px 16px;
display: flex;
align-items: center;
gap: 10px;
}
.spl-match-date {
font-size: 12px;
color: #888;
min-width: 52px;
text-align: center;
flex-shrink: 0;
line-height: 1.4;
}
.spl-match-teams {
flex: 1;
display: flex;
align-items: center;
gap: 8px;
justify-content: space-between;
}
.spl-team-block {
display: flex;
align-items: center;
gap: 6px;
flex: 1;
}
.spl-team-block.away { justify-content: flex-end; flex-direction: row-reverse; }
[dir="rtl"] .spl-team-block { flex-direction: row-reverse; }
[dir="rtl"] .spl-team-block.away { flex-direction: row; justify-content: flex-start; }
.spl-team-block img { width: 28px; height: 28px; object-fit: contain; flex-shrink: 0; }
.spl-team-name {
font-size: 13px;
font-weight: 600;
color: #222;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
max-width: 120px;
}
.spl-score-box {
background: #1a6b3c;
color: #fff;
font-size: 16px;
font-weight: 700;
padding: 6px 14px;
border-radius: 8px;
min-width: 70px;
text-align: center;
flex-shrink: 0;
letter-spacing: 2px;
}
.spl-loading { text-align: center; padding: 30px; color: #888; font-size: 14px; }
.spl-updated { font-size: 11px; color: #aaa; margin-top: 8px; text-align: right; }
[dir="rtl"] .spl-updated { text-align: left; }
@media (max-width: 480px) {
.spl-team-name { max-width: 70px; font-size: 11px; }
.spl-score-box { padding: 5px 8px; font-size: 14px; min-width: 55px; }
.spl-match-card { padding: 10px 8px; gap: 6px; }
}
</style>
<div class="spl-results-wrap" id="spl-results-root">
<div class="spl-section-title" id="spl-res-title">...</div>
<div id="spl-results-content">
<div class="spl-loading" id="spl-res-loading">...</div>
</div>
<div class="spl-updated" id="spl-results-updated"></div>
</div>
<script>
(function() {
var I18N = {
fr: {
title: 'Derniers Résultats',
loading: 'Chargement des résultats...',
error: 'Données temporairement indisponibles.',
updated: 'Mis à jour : ',
months: ['Jan','Fév','Mar','Avr','Mai','Jun','Jul','Aoû','Sep','Oct','Nov','Déc'],
dir: 'ltr'
},
en: {
title: 'Latest Results',
loading: 'Loading results...',
error: 'Data temporarily unavailable.',
updated: 'Updated: ',
months: ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'],
dir: 'ltr'
},
ar: {
title: 'آخر النتائج',
loading: 'جاري تحميل النتائج...',
error: 'البيانات غير متوفرة مؤقتاً.',
updated: 'آخر تحديث: ',
months: ['يناير','فبراير','مارس','أبريل','مايو','يونيو','يوليو','أغسطس','سبتمبر','أكتوبر','نوفمبر','ديسمبر'],
dir: 'rtl'
}
};
function detectLang() {
var lang = document.documentElement.lang || '';
lang = lang.toLowerCase().split('-')[0].split('_')[0];
return I18N[lang] ? lang : 'fr';
}
var lang = detectLang();
var t = I18N[lang];
var root = document.getElementById('spl-results-root');
root.setAttribute('dir', t.dir);
document.getElementById('spl-res-title').textContent = t.title;
document.getElementById('spl-res-loading').textContent = t.loading;
function formatDate(d) {
var parts = d.split('-');
return parts[2] + ' ' + t.months[parseInt(parts[1]) - 1];
}
function teamLogo(team) {
var logos = team.logos || [];
if (logos.length) return logos[0].href;
var tid = team.id || '';
return tid ? 'https://a.espncdn.com/i/teamlogos/soccer/500/' + tid + '.png' : '';
}
function parseEvents(data) {
var events = [];
(data.events || []).forEach(function(evt) {
var comp = (evt.competitions || [{}])[0];
var competitors = comp.competitors || [];
var status = (comp.status || {}).type || {};
var home = competitors.find(function(c) { return c.homeAway === 'home'; }) || {};
var away = competitors.find(function(c) { return c.homeAway === 'away'; }) || {};
var homeTeam = home.team || {};
var awayTeam = away.team || {};
events.push({
date: (evt.date || '').substring(0, 10),
time: (evt.date || '').substring(11, 16),
finished: status.completed || false,
homeTeam: homeTeam.displayName || '',
homeLogo: teamLogo(homeTeam),
homeScore: home.score || '',
awayTeam: awayTeam.displayName || '',
awayLogo: teamLogo(awayTeam),
awayScore: away.score || ''
});
});
return events;
}
function render(matches) {
if (!matches.length) {
document.getElementById('spl-results-content').innerHTML = '<div class="spl-loading">' + t.error + '</div>';
return;
}
var html = '';
matches.forEach(function(m) {
var homeClass = t.dir === 'rtl' ? 'spl-team-block away' : 'spl-team-block';
var awayClass = t.dir === 'rtl' ? 'spl-team-block' : 'spl-team-block away';
html += '<div class="spl-match-card">'
+ '<div class="spl-match-date">' + formatDate(m.date) + '</div>'
+ '<div class="spl-match-teams">'
+ '<div class="' + homeClass + '">'
+ '<img src="' + m.homeLogo + '" alt="' + m.homeTeam + '" onerror="this.style.display=\'none\'">'
+ '<span class="spl-team-name">' + m.homeTeam + '</span>'
+ '</div>'
+ '<div class="spl-score-box">' + m.homeScore + ' - ' + m.awayScore + '</div>'
+ '<div class="' + awayClass + '">'
+ '<img src="' + m.awayLogo + '" alt="' + m.awayTeam + '" onerror="this.style.display=\'none\'">'
+ '<span class="spl-team-name">' + m.awayTeam + '</span>'
+ '</div>'
+ '</div></div>';
});
document.getElementById('spl-results-content').innerHTML = html;
var now = new Date();
document.getElementById('spl-results-updated').textContent =
t.updated + now.toLocaleDateString() + ' ' + now.toLocaleTimeString([], {hour:'2-digit', minute:'2-digit'});
}
function loadResults() {
var today = new Date();
var start = new Date(today); start.setDate(start.getDate() - 45);
var fmt = function(d) { return d.getFullYear() + ('0'+(d.getMonth()+1)).slice(-2) + ('0'+d.getDate()).slice(-2); };
var url = 'https://site.api.espn.com/apis/site/v2/sports/soccer/ksa.1/scoreboard?limit=100&dates=' + fmt(start) + '-' + fmt(today);
fetch(url)
.then(function(r) { return r.json(); })
.then(function(data) {
var events = parseEvents(data).filter(function(e) { return e.finished; });
events.sort(function(a,b) { return b.date.localeCompare(a.date); });
render(events.slice(0, 20));
})
.catch(function() {
document.getElementById('spl-results-content').innerHTML = '<div class="spl-loading">' + t.error + '</div>';
});
}
loadResults();
setInterval(loadResults, 5 * 60 * 1000);
})();
</script>