// /public/assets/js/fakecheck/fakecheck.core.js (function() { // Namespace window.usbcheck = window.usbcheck || {}; const cfg = window.usbConfig || {}; // URL-Detection function detectApiBaseUrl() { const host = window.location.hostname || ""; if (host === "staging.usbcheck.it" || host.endsWith(".staging.usbcheck.it")) { return "https://api.staging.usbcheck.it"; } return "https://api.usbcheck.it"; } // Config bereitstellen usbcheck.cfg = { baseUrl: cfg.baseUrl || "", locale: (cfg.lang || "en").toLowerCase(), apiBase: cfg.apiBaseUrl || detectApiBaseUrl(), loggedIn: !!cfg.isLoggedIn }; // ---------- Hilfsfunktionen ---------- usbcheck.log = function logLine(message, level = "info") { const logEl = document.querySelector("#fc-log"); if (!logEl) return; const line = document.createElement("div"); line.className = "fc-log-line"; const prefix = level === "error" ? "[ERROR] " : level === "warn" ? "[WARN] " : "[INFO] "; line.innerHTML = `${prefix}${message}`; logEl.appendChild(line); logEl.scrollTop = logEl.scrollHeight; }; usbcheck.setStatus = function(msg) { const el = document.querySelector("#fc-status-text"); if (el) el.textContent = msg; }; usbcheck.setModeLabel = function(msg) { const el = document.querySelector("#fc-status-mode"); if (el) el.textContent = msg; }; usbcheck.setProgress = function(percent) { const el = document.querySelector("#fc-progress-inner"); if (!el) return; const v = Math.min(100, Math.max(0, percent)); el.style.width = v + "%"; }; usbcheck.setOverallStatus = function(state, text) { const pill = document.querySelector("#fc-overall-status-pill"); const label = document.querySelector("#fc-overall-status-text"); if (!pill || !label) return; pill.classList.remove("fc-pill-ok","fc-pill-warn","fc-pill-bad"); if (state === "ok") pill.classList.add("fc-pill-ok"); else if (state === "warn") pill.classList.add("fc-pill-warn"); else pill.classList.add("fc-pill-bad"); label.textContent = text; }; usbcheck.formatBytes = function(bytes) { if (bytes == null) return "–"; const units = ["B", "KB", "MB", "GB", "TB"]; let u = 0, v = bytes; while (v >= 1024 && u < units.length - 1) { v /= 1024; u++; } return v.toFixed(1) + " " + units[u]; }; usbcheck.formatMbps = function(bytes, seconds) { if (!seconds || seconds <= 0) return "–"; const mbits = (bytes * 8) / 1e6; return mbits.toFixed(1) + " Mbit/s"; }; usbcheck.formatDuration = function(seconds) { if (!seconds) return "–"; const s = Math.round(seconds); if (s < 60) return s + " s"; const m = Math.floor(s / 60); const r = s % 60; if (m < 60) return `${m} min ${r}s`; const h = Math.floor(m / 60); const rm = m % 60; return `${h} h ${rm} min`; }; })();