treker-po-trenirovkam-i-pit.../profile/tracker-guard.js
Peppa 3160f35fb8
All checks were successful
peppa/lint lint: success за 1с
peppa/test test: success за 1с
peppa/build build: success за 0с
ci / checks (pull_request) Successful in 10s
deploy / deploy (pull_request) Successful in 24s
TPTIP-4: совместить приватный профиль с дневником и планом тренировок
2026-11-17 11:25:11 +05:00

17 lines
845 B
JavaScript

import { initTelemetry } from '/profile/telemetry.js';
initTelemetry().catch(() => {});
async function refreshProfile() {
try {
const response = await fetch('/api/profile', {cache:'no-store'});
if (!response.ok) { document.body.replaceChildren(); location.replace('/'); return; }
const personal = await response.json();
if (personal.username !== window.TPTProfile.username) { document.body.replaceChildren(); location.replace('/'); return; }
window.TPTProfile = personal;
window.applyPrivateProfile();
window.render();
} catch { /* Keep the current view during a temporary connection failure. */ }
}
addEventListener('focus',refreshProfile);
addEventListener('pageshow',event => {if(event.persisted) refreshProfile();});
document.addEventListener('visibilitychange',()=>{if(!document.hidden) refreshProfile();});