diff --git a/equipment/equipment.js b/equipment/equipment.js index 031da5f..b3d5598 100644 --- a/equipment/equipment.js +++ b/equipment/equipment.js @@ -2,61 +2,56 @@ fetch("../header.html") .then(res => res.text()) .then(html => { const headerContainer = document.getElementById("header-container"); - if (headerContainer) { - headerContainer.innerHTML = html; - } + if (headerContainer) headerContainer.innerHTML = html; if (typeof CONFIG !== 'undefined') { const apiBase = CONFIG.API_BASE_URL.replace(/\/$/, ""); - const logoutForm = document.getElementById("logout-form"); + if (logoutForm) { logoutForm.action = apiBase + "/api/v1/spfn/logout"; const originInput = document.getElementById("logout_frontend_origin"); if (originInput) originInput.value = window.location.origin; + + logoutForm.addEventListener('submit', () => { + sessionStorage.removeItem('user_cache'); + }); } + const renderData = (data) => { + if (typeof data === 'string') { + try { data = JSON.parse(data); } + catch (e) { console.error(e); } + } + const nameEl = document.getElementById('mii-name'); + const imgEl = document.getElementById('mii-img'); + if (nameEl) { + nameEl.textContent = (data.mii && data.mii.name) || data.nickname || data.user_id || data.username || "User"; + } + if (imgEl) { + const miiBlob = (data.mii && data.mii.data) || data.mii_data; + if (miiBlob) { + imgEl.src = `https://mii-unsecure.ariankordi.net/miis/image.png?erri=s6u7r-rsp&data=${encodeURIComponent(miiBlob)}&type=face&width=270`; + imgEl.style.display = 'block'; + } + } + }; + + const cached = sessionStorage.getItem('user_cache'); + if (cached) renderData(JSON.parse(cached)); + fetch(apiBase + "/api/v1/me", { credentials: 'include' }) - .then(res => { - if (!res.ok) throw new Error("Status: " + res.status); - return res.json(); - }) + .then(res => res.ok ? res.json() : Promise.reject(res)) .then(data => { - if (typeof data === 'string') { - try { - data = JSON.parse(data); - } catch (e) { - console.error("Failed to parse inner JSON:", e); - } - } - - const nameEl = document.getElementById('mii-name'); - const imgEl = document.getElementById('mii-img'); - - if (nameEl) { - const displayName = - (data.mii && data.mii.name) || - data.nickname || - data.user_id || - data.username || - "User"; - - nameEl.textContent = displayName; - } - - if (imgEl) { - const miiBlob = (data.mii && data.mii.data) || data.mii_data; - if (miiBlob) { - const encodedData = encodeURIComponent(miiBlob); - imgEl.src = `https://mii-unsecure.ariankordi.net/miis/image.png?erri=s6u7r-rsp&data=${encodedData}&type=face&width=270`; - imgEl.style.display = 'block'; - } - } + sessionStorage.setItem('user_cache', JSON.stringify(data)); + renderData(data); }) .catch(err => { - const nameEl = document.getElementById('mii-name'); - if (nameEl) nameEl.textContent = "Guest"; - console.error("Profile Error:", err); + if (!cached) { + const nameEl = document.getElementById('mii-name'); + if (nameEl) nameEl.textContent = "Guest"; + } + console.error(err); }); } diff --git a/friend_list/friendlist.js b/friend_list/friendlist.js index c25e952..6d9a462 100644 --- a/friend_list/friendlist.js +++ b/friend_list/friendlist.js @@ -2,61 +2,56 @@ fetch("../header.html") .then(res => res.text()) .then(html => { const headerContainer = document.getElementById("header-container"); - if (headerContainer) { - headerContainer.innerHTML = html; - } + if (headerContainer) headerContainer.innerHTML = html; if (typeof CONFIG !== 'undefined') { const apiBase = CONFIG.API_BASE_URL.replace(/\/$/, ""); - const logoutForm = document.getElementById("logout-form"); + if (logoutForm) { logoutForm.action = apiBase + "/api/v1/spfn/logout"; const originInput = document.getElementById("logout_frontend_origin"); if (originInput) originInput.value = window.location.origin; + + logoutForm.addEventListener('submit', () => { + sessionStorage.removeItem('user_cache'); + }); } + const renderData = (data) => { + if (typeof data === 'string') { + try { data = JSON.parse(data); } + catch (e) { console.error(e); } + } + const nameEl = document.getElementById('mii-name'); + const imgEl = document.getElementById('mii-img'); + if (nameEl) { + nameEl.textContent = (data.mii && data.mii.name) || data.nickname || data.user_id || data.username || "User"; + } + if (imgEl) { + const miiBlob = (data.mii && data.mii.data) || data.mii_data; + if (miiBlob) { + imgEl.src = `https://mii-unsecure.ariankordi.net/miis/image.png?erri=s6u7r-rsp&data=${encodeURIComponent(miiBlob)}&type=face&width=270`; + imgEl.style.display = 'block'; + } + } + }; + + const cached = sessionStorage.getItem('user_cache'); + if (cached) renderData(JSON.parse(cached)); + fetch(apiBase + "/api/v1/me", { credentials: 'include' }) - .then(res => { - if (!res.ok) throw new Error("Status: " + res.status); - return res.json(); - }) + .then(res => res.ok ? res.json() : Promise.reject(res)) .then(data => { - if (typeof data === 'string') { - try { - data = JSON.parse(data); - } catch (e) { - console.error("Failed to parse inner JSON:", e); - } - } - - const nameEl = document.getElementById('mii-name'); - const imgEl = document.getElementById('mii-img'); - - if (nameEl) { - const displayName = - (data.mii && data.mii.name) || - data.nickname || - data.user_id || - data.username || - "User"; - - nameEl.textContent = displayName; - } - - if (imgEl) { - const miiBlob = (data.mii && data.mii.data) || data.mii_data; - if (miiBlob) { - const encodedData = encodeURIComponent(miiBlob); - imgEl.src = `https://mii-unsecure.ariankordi.net/miis/image.png?erri=s6u7r-rsp&data=${encodedData}&type=face&width=270`; - imgEl.style.display = 'block'; - } - } + sessionStorage.setItem('user_cache', JSON.stringify(data)); + renderData(data); }) .catch(err => { - const nameEl = document.getElementById('mii-name'); - if (nameEl) nameEl.textContent = "Guest"; - console.error("Profile Error:", err); + if (!cached) { + const nameEl = document.getElementById('mii-name'); + if (nameEl) nameEl.textContent = "Guest"; + } + console.error(err); }); } diff --git a/ranking/rank.js b/ranking/rank.js index 08e6ae4..9051a3c 100644 --- a/ranking/rank.js +++ b/ranking/rank.js @@ -2,61 +2,56 @@ fetch("../header.html") .then(res => res.text()) .then(html => { const headerContainer = document.getElementById("header-container"); - if (headerContainer) { - headerContainer.innerHTML = html; - } + if (headerContainer) headerContainer.innerHTML = html; if (typeof CONFIG !== 'undefined') { const apiBase = CONFIG.API_BASE_URL.replace(/\/$/, ""); - const logoutForm = document.getElementById("logout-form"); + if (logoutForm) { logoutForm.action = apiBase + "/api/v1/spfn/logout"; const originInput = document.getElementById("logout_frontend_origin"); if (originInput) originInput.value = window.location.origin; + + logoutForm.addEventListener('submit', () => { + sessionStorage.removeItem('user_cache'); + }); } + const renderData = (data) => { + if (typeof data === 'string') { + try { data = JSON.parse(data); } + catch (e) { console.error(e); } + } + const nameEl = document.getElementById('mii-name'); + const imgEl = document.getElementById('mii-img'); + if (nameEl) { + nameEl.textContent = (data.mii && data.mii.name) || data.nickname || data.user_id || data.username || "User"; + } + if (imgEl) { + const miiBlob = (data.mii && data.mii.data) || data.mii_data; + if (miiBlob) { + imgEl.src = `https://mii-unsecure.ariankordi.net/miis/image.png?erri=s6u7r-rsp&data=${encodeURIComponent(miiBlob)}&type=face&width=270`; + imgEl.style.display = 'block'; + } + } + }; + + const cached = sessionStorage.getItem('user_cache'); + if (cached) renderData(JSON.parse(cached)); + fetch(apiBase + "/api/v1/me", { credentials: 'include' }) - .then(res => { - if (!res.ok) throw new Error("Status: " + res.status); - return res.json(); - }) + .then(res => res.ok ? res.json() : Promise.reject(res)) .then(data => { - if (typeof data === 'string') { - try { - data = JSON.parse(data); - } catch (e) { - console.error("Failed to parse inner JSON:", e); - } - } - - const nameEl = document.getElementById('mii-name'); - const imgEl = document.getElementById('mii-img'); - - if (nameEl) { - const displayName = - (data.mii && data.mii.name) || - data.nickname || - data.user_id || - data.username || - "User"; - - nameEl.textContent = displayName; - } - - if (imgEl) { - const miiBlob = (data.mii && data.mii.data) || data.mii_data; - if (miiBlob) { - const encodedData = encodeURIComponent(miiBlob); - imgEl.src = `https://mii-unsecure.ariankordi.net/miis/image.png?erri=s6u7r-rsp&data=${encodedData}&type=face&width=270`; - imgEl.style.display = 'block'; - } - } + sessionStorage.setItem('user_cache', JSON.stringify(data)); + renderData(data); }) .catch(err => { - const nameEl = document.getElementById('mii-name'); - if (nameEl) nameEl.textContent = "Guest"; - console.error("Profile Error:", err); + if (!cached) { + const nameEl = document.getElementById('mii-name'); + if (nameEl) nameEl.textContent = "Guest"; + } + console.error(err); }); } diff --git a/stages/index.html b/stages/index.html index 096d6df..77970eb 100644 --- a/stages/index.html +++ b/stages/index.html @@ -49,66 +49,58 @@ fetch("../header.html") const headerContainer = document.getElementById("header-container"); if (headerContainer) { headerContainer.innerHTML = html; - const friendButton = headerContainer.querySelector('.menu-item.stage'); - if (friendButton) { - friendButton.classList.add('active'); - } + if (friendButton) friendButton.classList.add('active'); } if (typeof CONFIG !== 'undefined') { const apiBase = CONFIG.API_BASE_URL.replace(/\/$/, ""); - const logoutForm = document.getElementById("logout-form"); if (logoutForm) { logoutForm.action = apiBase + "/api/v1/spfn/logout"; const originInput = document.getElementById("logout_frontend_origin"); if (originInput) originInput.value = window.location.origin; + logoutForm.addEventListener('submit', () => sessionStorage.removeItem('user_cache')); } + const renderData = (data) => { + if (typeof data === 'string') { + try { data = JSON.parse(data); } catch (e) { console.error(e); } + } + const nameEl = document.getElementById('mii-name'); + const imgEl = document.getElementById('mii-img'); + if (nameEl) { + nameEl.textContent = (data.mii && data.mii.name) || data.nickname || data.user_id || data.username || "User"; + } + if (imgEl) { + const miiBlob = (data.mii && data.mii.data) || data.mii_data; + if (miiBlob) { + imgEl.src = `https://mii-unsecure.ariankordi.net/miis/image.png?erri=s6u7r-rsp&data=${encodeURIComponent(miiBlob)}&type=face&width=270`; + imgEl.style.display = 'block'; + } + } + }; + + const cached = sessionStorage.getItem('user_cache'); + if (cached) renderData(JSON.parse(cached)); + fetch(apiBase + "/api/v1/me", { credentials: 'include' }) - .then(res => { - if (!res.ok) throw new Error("Status: " + res.status); - return res.json(); - }) + .then(res => res.ok ? res.json() : Promise.reject(res)) .then(data => { - if (typeof data === 'string') { - try { - data = JSON.parse(data); - } catch (e) { - console.error("Failed to parse inner JSON:", e); - } - } - - const nameEl = document.getElementById('mii-name'); - const imgEl = document.getElementById('mii-img'); - - if (nameEl) { - const displayName = - (data.mii && data.mii.name) || - data.nickname || - data.user_id || - data.username || - "User"; - - nameEl.textContent = displayName; - } - - if (imgEl) { - const miiBlob = (data.mii && data.mii.data) || data.mii_data; - if (miiBlob) { - const encodedData = encodeURIComponent(miiBlob); - imgEl.src = `https://mii-unsecure.ariankordi.net/miis/image.png?erri=s6u7r-rsp&data=${encodedData}&type=face&width=270`; - imgEl.style.display = 'block'; - } - } + sessionStorage.setItem('user_cache', JSON.stringify(data)); + renderData(data); }) .catch(err => { - const nameEl = document.getElementById('mii-name'); - if (nameEl) nameEl.textContent = "Guest"; - console.error("Profile Error:", err); + if (!cached) { + const nameEl = document.getElementById('mii-name'); + if (nameEl) nameEl.textContent = "Guest"; + } + console.error(err); }); } + + const overlay = document.getElementById("loading-overlay"); + if (overlay) overlay.style.display = "none"; }) .catch(err => console.error("Failed to load header:", err));