www.dcos.net/app.js

111 lines
3.6 KiB
JavaScript

/**
* DCOS.NET Framework Logic
* Handles UI Injections, System Stats, and Terminal Simulation
*/
async function injectSharedUI() {
try {
// 1. Load Header Fragment
const hRes = await fetch('header.html');
document.getElementById('header-shared').innerHTML = await hRes.text();
// 2. Load Footer Fragment
const fRes = await fetch('footer.html');
document.getElementById('footer-shared').innerHTML = await fRes.text();
// 3. Trigger Post-Load Functions
fetchStats();
fetchTerm();
} catch (e) {
console.error("UI Fragment Load Failed:", e);
}
}
// Global System Stats (Geo & Git Metadata)
async function fetchStats() {
// 1. Give the DOM a split second to breathe after fragment injection
setTimeout(async () => {
try {
// Fetch Version Metadata (Git Push Info)
const vRes = await fetch('version.json?t=' + Date.now());
if (vRes.ok) {
const vData = await vRes.json();
const pushElem = document.getElementById('last-push');
if (pushElem) pushElem.innerText = vData.last_deploy;
}
// Fetch Geo-Location (HTTPS IS REQUIRED)
const gRes = await fetch('https://ipapi.co/json/');
if (gRes.ok) {
const gData = await gRes.json();
const tickerElem = document.getElementById('visitor-ticker');
if (tickerElem) {
// Using a formatted string: "City, Country Code"
tickerElem.innerText = `${gData.city}, ${gData.country_code}`;
}
}
} catch (e) {
console.warn("DCOS_MONITOR: Stats satellite uplink failed.", e);
const tickerElem = document.getElementById('visitor-ticker');
if (tickerElem) tickerElem.innerText = "VPN_ENCRYPTED / ANONYMOUS";
}
}, 100); // 100ms delay ensures footer.html is rendered
}
// Terminal Simulation
function fetchTerm() {
const logs = [
"> dcosnet --init --ai",
"> [OK] Kernel 7.0rc4 optimized",
"> [OK] libvirtd/LXC Containers active",
"> [OK] Caddy Reverse Proxy active",
"> [OK] Current project: Compiling...",
"> [READY] Systems stable since 1999"
];
const container = document.getElementById('term-content');
if (!container) return;
container.innerHTML = ''; // Clear any existing content
let i = 0;
function typeLog() {
if (i < logs.length) {
const line = document.createElement('div');
line.className = 'term-line';
// Re-applying the primary brand color to the success message
if (i === logs.length - 1) {
line.style.color = 'var(--primary)';
line.style.fontWeight = 'bold';
} else {
line.style.color = '#888';
}
container.appendChild(line);
let charIdx = 0;
const text = logs[i];
function char() {
if (charIdx < text.length) {
line.textContent += text.charAt(charIdx);
charIdx++;
// SPEED TWEAK: 20ms is "high-speed" terminal style
setTimeout(char, 20);
} else {
i++;
// DELAY BETWEEN LINES: 300ms feels snappier than 600ms
setTimeout(typeLog, 300);
}
}
char();
}
}
typeLog();
}
// Initialize on page load
window.onload = injectSharedUI;