-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathping.user.js
More file actions
83 lines (70 loc) · 2.59 KB
/
Copy pathping.user.js
File metadata and controls
83 lines (70 loc) · 2.59 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
// ==UserScript==
// @name Outer Empires 2 Latency Display
// @namespace https://github.com/PlayMaGame/oe2-userscripts
// @author PlayMaGame
// @license MIT
// @version 0.5
// @description Replace version with color-coded ping and FPS for Outer Empires 2
// @match https://game.dev.outerempires.net/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
// FPS tracking
let currentFPS = 0;
let frameCount = 0;
let lastFPSTime = performance.now();
function trackFPS() {
frameCount++;
const now = performance.now();
const delta = now - lastFPSTime;
if (delta >= 1000) {
currentFPS = Math.round((frameCount * 1000) / delta);
frameCount = 0;
lastFPSTime = now;
}
requestAnimationFrame(trackFPS);
}
requestAnimationFrame(trackFPS);
function getFPSColor(fps) {
if (fps >= 60) return 'lime';
if (fps >= 30) return 'yellow';
return 'red';
}
function getLatencyColor(latency) {
if (latency === 'Error') return 'red';
if (latency < 50) return 'lime';
if (latency < 100) return 'yellow';
return 'red';
}
async function measureLatency() {
const start = performance.now();
try {
await fetch('https://game.dev.outerempires.net', {
method: 'HEAD',
cache: 'no-store'
});
return Math.round(performance.now() - start);
} catch (error) {
return 'Error';
}
}
async function updateDisplay() {
const versionDisplay = document.getElementById('ui_playversion_display');
if (!versionDisplay) return;
versionDisplay.style.zIndex = '200';
versionDisplay.style.whiteSpace = 'nowrap';
versionDisplay.style.overflow = 'visible';
versionDisplay.style.position = 'absolute';
versionDisplay.style.top = '60px'; // <-- add this
versionDisplay.style.left = '50%';
versionDisplay.style.transform = 'translateX(-50%)';
const latency = await measureLatency();
const sep = ` <span style="color:#555;"> | </span> `;
const pingHTML = `Ping: <span style="color:${getLatencyColor(latency)};font-weight:bold;">${latency}ms</span>`;
const fpsHTML = `FPS: <span style="color:${getFPSColor(currentFPS)};font-weight:bold;">${currentFPS}</span>`;
versionDisplay.innerHTML = [pingHTML, fpsHTML].join(sep);
}
updateDisplay();
setInterval(updateDisplay, 1000); // Faster refresh so FPS feels live
})();