Repository navigation
Expand file tree
/
Copy pathoverlay.js
More file actions
64 lines (52 loc) · 1.8 KB
/
Copy pathoverlay.js
File metadata and controls
64 lines (52 loc) · 1.8 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
// Mode: URL param > localStorage > default pve
const _urlMode = new URLSearchParams(window.location.search).get('mode');
let currentMode = _urlMode
? _resolveMode(_urlMode)
: _resolveMode(localStorage.getItem('goonMode'));
function setMode(mode) {
currentMode = mode;
localStorage.setItem('goonMode', mode);
const indicator = document.getElementById('mode-indicator');
if (indicator) indicator.textContent = mode === 'pve' ? 'PVE' : 'PVP';
fetchGoonReport();
}
async function fetchGoonReport() {
try {
const [latest] = await fetchGoonReports(currentMode);
if (!latest) {
showError('No reports found');
return;
}
updateDisplay(latest.mapName, latest.timestamp);
} catch (err) {
console.error('Fetch failed:', err);
showError('Failed to fetch');
}
}
function updateDisplay(mapName, timestamp) {
const imgEl = document.getElementById('goon-image');
const mapEl = document.getElementById('map-name');
const seenEl = document.getElementById('last-seen');
imgEl.src = pickRandomImage();
mapEl.textContent = mapName;
const ago = timeAgo(timestamp);
const cls = stalenessClass(timestamp);
seenEl.textContent = `Last reported ${ago}`;
seenEl.className = cls;
}
function showError(msg) {
const mapEl = document.getElementById('map-name');
const seenEl = document.getElementById('last-seen');
mapEl.textContent = 'Unknown';
seenEl.textContent = msg;
seenEl.className = 'stale';
}
// Init
document.addEventListener('DOMContentLoaded', () => {
const indicator = document.getElementById('mode-indicator');
if (indicator) indicator.textContent = currentMode === 'pve' ? 'PVE' : 'PVP';
updateTarkovClock();
setInterval(updateTarkovClock, 50); // 50ms real = ~350ms Tarkov time per tick
});
fetchGoonReport();
setInterval(fetchGoonReport, POLL_INTERVAL_MS);