From 1753b1d2ee2af05ac09c4afff952f00ee40b2b7d Mon Sep 17 00:00:00 2001 From: Akurosia Kamo Date: Thu, 21 May 2026 16:05:05 +0200 Subject: [PATCH] add translation of element, share page due to url params and default to analyse page --- api/abilities.php | 2 +- api/analysis.php | 2 +- api/debug-events.php | 20 +++++++++++++++++--- api/fight.php | 15 ++++++++++++++- js/analysis.js | 8 ++------ js/app.js | 10 ++++++++++ 6 files changed, 45 insertions(+), 12 deletions(-) diff --git a/api/abilities.php b/api/abilities.php index 1de90ba..5e29d8b 100644 --- a/api/abilities.php +++ b/api/abilities.php @@ -15,7 +15,7 @@ $startTime = (float)($_POST['start_time'] ?? 0); $endTime = (float)($_POST['end_time'] ?? 0); $language = strtolower(trim($_POST['language'] ?? 'en')); $language = in_array($language, ['en', 'de', 'fr', 'jp'], true) ? $language : 'en'; -$translate = $language === 'en' ? 'false' : 'true'; +$translate = 'true'; if (!$reportCode || !$fightId || !$endTime) { http_response_code(400); echo json_encode(['error' => 'Missing params']); exit; } diff --git a/api/analysis.php b/api/analysis.php index 9d45bd8..282d02f 100644 --- a/api/analysis.php +++ b/api/analysis.php @@ -26,7 +26,7 @@ $startTime = (float)($_POST['start_time'] ?? 0); $endTime = (float)($_POST['end_time'] ?? 0); $language = strtolower(trim($_POST['language'] ?? 'en')); $language = in_array($language, ['en', 'de', 'fr', 'jp'], true) ? $language : 'en'; -$translate = $language === 'en' ? 'false' : 'true'; +$translate = 'true'; if (!$reportCode || !$fightId || !$endTime) { http_response_code(400); diff --git a/api/debug-events.php b/api/debug-events.php index 4ab54ab..dc3554b 100644 --- a/api/debug-events.php +++ b/api/debug-events.php @@ -17,6 +17,9 @@ $playerName = trim($_POST['player_name'] ?? ''); $eventType = trim($_POST['event_type'] ?? ''); $abilityId = (int)($_POST['ability_id'] ?? 0); $limit = max(1, min(500, (int)($_POST['limit'] ?? 20))); +$language = strtolower(trim($_POST['language'] ?? 'en')); +$language = in_array($language, ['en', 'de', 'fr', 'jp'], true) ? $language : 'en'; +$translate = 'true'; $startOffset = (float)($_POST['start_offset'] ?? 0) * 1000; // s → ms $endOffset = isset($_POST['end_offset']) && $_POST['end_offset'] !== '' ? (float)$_POST['end_offset'] * 1000 @@ -33,14 +36,24 @@ $queryEnd = min($queryEnd, $endTime); $token = $_SESSION['access_token']; +function localized_graphql_uri(string $language): string { + $host = [ + 'de' => 'de.fflogs.com', + 'fr' => 'fr.fflogs.com', + 'jp' => 'ja.fflogs.com', + ][$language] ?? 'www.fflogs.com'; + return preg_replace('#https://[^/]+#', 'https://' . $host, GRAPHQL_URI); +} + function dbg_gql(string $query): array { - global $token; - $ch = curl_init(GRAPHQL_URI); + global $token, $language; + $acceptLanguage = $language === 'jp' ? 'ja' : $language; + $ch = curl_init(localized_graphql_uri($language)); curl_setopt_array($ch, [ CURLOPT_POST => true, CURLOPT_POSTFIELDS => json_encode(['query' => $query]), CURLOPT_RETURNTRANSFER => true, - CURLOPT_HTTPHEADER => ['Content-Type: application/json', 'Authorization: Bearer ' . $token], + CURLOPT_HTTPHEADER => ['Content-Type: application/json', 'Authorization: Bearer ' . $token, 'Accept-Language: ' . $acceptLanguage], CURLOPT_SSL_VERIFYPEER => !DEV_MODE, ]); $body = curl_exec($ch); @@ -85,6 +98,7 @@ $result = dbg_gql(<< ['reportCode' => $reportCode], ]); -$ch = curl_init(GRAPHQL_URI); +function localized_graphql_uri(string $language): string { + $host = [ + 'de' => 'de.fflogs.com', + 'fr' => 'fr.fflogs.com', + 'jp' => 'ja.fflogs.com', + ][$language] ?? 'www.fflogs.com'; + return preg_replace('#https://[^/]+#', 'https://' . $host, GRAPHQL_URI); +} + +$acceptLanguage = $language === 'jp' ? 'ja' : $language; +$ch = curl_init(localized_graphql_uri($language)); curl_setopt_array($ch, [ CURLOPT_POST => true, CURLOPT_POSTFIELDS => $payload, @@ -72,6 +84,7 @@ curl_setopt_array($ch, [ CURLOPT_HTTPHEADER => [ 'Content-Type: application/json', 'Authorization: Bearer ' . $_SESSION['access_token'], + 'Accept-Language: ' . $acceptLanguage, ], CURLOPT_SSL_VERIFYPEER => !DEV_MODE, ]); diff --git a/js/analysis.js b/js/analysis.js index 144eb4f..17a1f0f 100644 --- a/js/analysis.js +++ b/js/analysis.js @@ -265,10 +265,7 @@ let allSameReportFights = []; function populateRefFightSelect() { - const currentName = (window.App.fights ?? []).find(f => f.id === window.App.fightId)?.name; - const visible = allSameReportFights.filter(f => - f.id !== window.App.fightId && (!currentName || f.name === currentName) - ); + const visible = allSameReportFights.filter(f => f.id !== window.App.fightId); refFightSelect.innerHTML = ''; visible.forEach(f => { const hp = f.kill ? 'Kill' : (f.fightPercentage != null ? f.fightPercentage.toFixed(2) + '%' : '?'); @@ -322,8 +319,7 @@ extFights = fights; extReportCode = code; - const currentName = (window.App.fights ?? []).find(f => f.id === window.App.fightId)?.name; - const visibleExt = currentName ? fights.filter(f => f.name === currentName) : fights; + const visibleExt = fights; refExtFightSelect.innerHTML = ''; visibleExt.forEach(f => { const hp = f.kill ? 'Kill' : (f.fightPercentage != null ? f.fightPercentage.toFixed(2) + '%' : '?'); diff --git a/js/app.js b/js/app.js index 06378c8..3389b1a 100644 --- a/js/app.js +++ b/js/app.js @@ -72,6 +72,9 @@ document.addEventListener('DOMContentLoaded', () => { window.App.language = normalizeLanguage(languageSelect.value); localStorage.setItem('ff14-mitigator-language', window.App.language); setUrlState({ language: window.App.language }); + if (window.App.reportCode) { + loadReport(window.App.reportCode, window.App.fightId); + } }); const codeInput = form.elements['report_code']; @@ -98,6 +101,10 @@ document.addEventListener('DOMContentLoaded', () => { outputCard.style.display = 'block'; } + function openAnalysisTab() { + document.querySelector('.tabs .tab[data-tab="analysis"]')?.click(); + } + function selectFight(id, updateUrl = true) { const fight = allFights.find(f => f.id === id); if (!fight) return false; @@ -298,6 +305,9 @@ document.addEventListener('DOMContentLoaded', () => { if (initialUrlState.reportCode) { form.elements['report_code'].value = initialUrlState.reportCode; loadReport(initialUrlState.reportCode, initialUrlState.fightId).then(() => { + if (initialUrlState.fightId) { + openAnalysisTab(); + } if (initialUrlState.compareFightId) { window.analysisTab?.selectSharedCompare?.(initialUrlState.compareFightId, initialUrlState.compareReportCode); }