Repository navigation
Expand file tree
/
Copy pathsite.js
More file actions
89 lines (74 loc) · 2.72 KB
/
Copy pathsite.js
File metadata and controls
89 lines (74 loc) · 2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// Mode: localStorage > default pve
let currentMode = _resolveMode(localStorage.getItem('goonMode'));
function setMode(mode) {
currentMode = mode;
localStorage.setItem('goonMode', mode);
document.querySelectorAll('.mode-btn').forEach(b =>
b.classList.toggle('active', b.dataset.mode === mode));
loadReports();
}
function escapeHtml(str) {
return str
.replace(/&/g, '&')
.replace(/</g, '<')
.replace(/>/g, '>')
.replace(/"/g, '"')
.replace(/'/g, ''');
}
async function loadReports() {
const statusEl = document.getElementById('update-status');
const bodyEl = document.getElementById('report-body');
const btn = document.getElementById('refresh-btn');
if (!statusEl || !bodyEl || !btn) return;
statusEl.textContent = 'Updating...';
btn.disabled = true;
try {
const reports = (await fetchGoonReports(currentMode)).slice(0, 10);
if (reports.length === 0) {
bodyEl.innerHTML = '<tr><td colspan="3" class="loading-row stale">No reports found</td></tr>';
statusEl.textContent = 'No data';
return;
}
bodyEl.innerHTML = reports
.map(({ timestamp, mapName, wiki, raidDuration }, i) => {
const cls = stalenessClass(timestamp);
const safeName = escapeHtml(mapName);
const safeWiki = wiki && wiki.startsWith('https://') ? wiki : null;
const mapLink = safeWiki
? `<a href="${escapeHtml(safeWiki)}" target="_blank" rel="noopener" class="map-link">${safeName}</a>`
: safeName;
const meta = raidDuration ? `${parseInt(raidDuration, 10)} min raid` : '';
return `<tr>
<td class="row-num">${i + 1}</td>
<td class="map-cell">
<span class="map-name">${mapLink}</span>
${meta ? `<span class="map-meta">${meta}</span>` : ''}
</td>
<td class="${cls}">${timeAgo(timestamp)}</td>
</tr>`;
})
.join('');
const now = new Date().toLocaleTimeString([], {
hour: '2-digit',
minute: '2-digit',
timeZoneName: 'short',
});
statusEl.textContent = `Updated ${now}`;
document.getElementById('header-goon').src = pickRandomImage();
} catch (err) {
console.error('Fetch failed:', err);
bodyEl.innerHTML = '<tr><td colspan="3" class="loading-row stale">Failed to fetch data</td></tr>';
statusEl.textContent = 'Error';
} finally {
btn.disabled = false;
}
}
// Init
document.addEventListener('DOMContentLoaded', () => {
document.querySelectorAll('.mode-btn').forEach(b =>
b.classList.toggle('active', b.dataset.mode === currentMode));
});
loadReports();
setInterval(loadReports, POLL_INTERVAL_MS);
updateTarkovClock();
setInterval(updateTarkovClock, 50); // 50ms real = ~350ms Tarkov time per tick