상단 복귀 링크를 이전 페이지 기준으로 정리

This commit is contained in:
seo
2026-07-01 00:55:05 +09:00
parent a03c056e88
commit eeef4c008d
2 changed files with 99 additions and 35 deletions
+97 -34
View File
@@ -459,6 +459,83 @@ let langCode = localStorage.getItem("currentLang") || deviceLang,
_overrideRange,
wakeLock = null;
const FALLBACK_BACK_TARGET = 'https://chaegeon.com/blog';
const BACK_LINK_PATH_TITLE = {
'/': '채건닷컴',
'/home': '홈',
'/blog': '블로그',
};
function cleanPageTitle(title) {
return String(title || '')
.replace(/^채건닷컴\s*-\s*/i, '')
.replace(/\s*-\s*채건닷컴$/i, '')
.trim();
}
function sameSiteUrl(url) {
try {
const parsed = new URL(url, location.href);
return parsed.hostname === location.hostname || parsed.hostname.endsWith('.chaegeon.com') || parsed.hostname === 'chaegeon.com'
? parsed
: null;
} catch (e) {
return null;
}
}
function titleFromBackUrl(url) {
const parsed = sameSiteUrl(url);
if (!parsed) return '';
return BACK_LINK_PATH_TITLE[parsed.pathname.replace(/\/$/, '') || '/'] || cleanPageTitle(parsed.pathname.split('/').filter(Boolean).pop() || '');
}
async function resolveBackTarget() {
const ref = sameSiteUrl(document.referrer || '');
const current = new URL(location.href);
const target = ref && ref.href !== current.href ? ref.href : FALLBACK_BACK_TARGET;
let title = titleFromBackUrl(target);
if (ref && ref.origin === location.origin) {
try {
const res = await fetch(ref.href, { credentials: 'same-origin', cache: 'force-cache' });
if (res.ok) {
const html = await res.text();
const doc = new DOMParser().parseFromString(html, 'text/html');
title = cleanPageTitle(doc.querySelector('title')?.textContent) || title;
}
} catch (e) {}
}
return { href: target, label: title || '블로그' };
}
function updateBackLinkLabel(label) {
const blogBackLink = document.getElementById('blogBackLink');
if (!blogBackLink) return;
blogBackLink.innerHTML = `<span class="backArrow"></span> ${label}`;
}
function setupBackLink() {
const blogBackLink = document.getElementById('blogBackLink');
if (!blogBackLink) return;
blogBackLink.href = FALLBACK_BACK_TARGET;
blogBackLink.dataset.backLabel = '블로그';
updateBackLinkLabel(blogBackLink.dataset.backLabel);
resolveBackTarget().then(({ href, label }) => {
blogBackLink.href = href;
blogBackLink.dataset.backLabel = label;
updateBackLinkLabel(label);
});
blogBackLink.addEventListener('click', (e) => {
e.preventDefault();
location.href = blogBackLink.href || FALLBACK_BACK_TARGET;
});
}
function ensureFindMyDeviceShell() {
let mount = document.getElementById('findmydevice');
if (!mount) {
@@ -535,16 +612,9 @@ ensureFindMyDeviceShell();
applyLanguage(langCode);
document.querySelectorAll('.locateRow').forEach(row => {
row.addEventListener('pointerdown', () => {
row.style.background = '#d3d3d3';
});
row.addEventListener('pointerup', () => {
row.style.background = '#fff';
});
row.addEventListener('pointerleave', () => {
row.style.background = '#fff';
});
});
row.setAttribute('role', 'button');
row.tabIndex = 0;
});
document.getElementById('langToggle').addEventListener('click', () => {
langCode = langCode === 'ko' ? 'en' : 'ko';
@@ -607,10 +677,7 @@ document.addEventListener('DOMContentLoaded', () => {
container.style.webkitTouchCallout = 'none';
container.addEventListener('dragstart', e => e.preventDefault());
document.getElementById('blogBackLink').addEventListener('click', (e) => {
e.preventDefault();
location.href = '/blog';
});
setupBackLink();
function renderAuthErrorPage() {
document.body.innerHTML = `
@@ -971,7 +1038,7 @@ function applyLanguage(langCode) {
};
const blogBackLink = document.getElementById('blogBackLink');
if (blogBackLink) blogBackLink.innerHTML = `<span class="backArrow"></span> ${t.blog}`;
if (blogBackLink) updateBackLinkLabel(blogBackLink.dataset.backLabel || t.blog);
const headerTitle = document.querySelector('.headerTitle');
if (headerTitle) headerTitle.textContent = t.title;
@@ -2279,22 +2346,20 @@ function syncLocateBtn() {
exist.remove();
} else if (!isChecked && !exist && parent) {
const newDiv = document.createElement('div');
newDiv.className = 'settingRow locateRow';
newDiv.id = 'locateBtn';
newDiv.innerHTML = `<span style="color:#007AFF; cursor:default;" id="labelMoveToCurrent">${langCode === 'ko' ? '현재 위치로 이동하기' : 'Move to Current Location'}</span>`;
newDiv.className = 'settingRow locateRow';
newDiv.id = 'locateBtn';
newDiv.setAttribute('role', 'button');
newDiv.tabIndex = 0;
newDiv.innerHTML = `<span style="color:#007AFF; cursor:default;" id="labelMoveToCurrent">${langCode === 'ko' ? '현재 위치로 이동하기' : 'Move to Current Location'}</span>`;
newDiv.addEventListener('click', () => {
if (hasValidCoords(lastLat, lastLng)) {
mapState.map.panTo(new naver.maps.LatLng(lastLat, lastLng));
}
});
newDiv.addEventListener('pointerdown', () => newDiv.style.background = '#d3d3d3');
newDiv.addEventListener('pointerup', () => newDiv.style.background = '#fff');
newDiv.addEventListener('pointerleave', () => newDiv.style.background = '#fff');
parent.parentNode.insertBefore(newDiv, parent.nextSibling);
}
}
parent.parentNode.insertBefore(newDiv, parent.nextSibling);
}
}
function syncUpdateBtn() {
const isChecked = document.getElementById('autoUpdateSwitch').checked;
@@ -2305,15 +2370,13 @@ function syncUpdateBtn() {
exist.remove();
} else if (!isChecked && !exist && parent) {
const newDiv = document.createElement('div');
newDiv.className = 'settingRow locateRow';
newDiv.id = 'updateBtn';
newDiv.innerHTML = `<span style="color:#007AFF; cursor:default;" id="labelForceUpdate">${langCode === 'ko' ? '업데이트 하기' : 'Force Update'}</span>`;
newDiv.addEventListener('pointerdown', () => newDiv.style.background = '#d3d3d3');
newDiv.addEventListener('pointerup', () => newDiv.style.background = '#fff');
newDiv.addEventListener('pointerleave', () => newDiv.style.background = '#fff');
newDiv.addEventListener('click', triggerForceUpdate);
newDiv.className = 'settingRow locateRow';
newDiv.id = 'updateBtn';
newDiv.setAttribute('role', 'button');
newDiv.tabIndex = 0;
newDiv.innerHTML = `<span style="color:#007AFF; cursor:default;" id="labelForceUpdate">${langCode === 'ko' ? '업데이트 하기' : 'Force Update'}</span>`;
newDiv.addEventListener('click', triggerForceUpdate);
parent.parentNode.insertBefore(newDiv, parent.nextSibling);
}