This commit is contained in:
make
2025-04-12 18:20:35 +08:00
parent 1d431ecce5
commit 760fe47b5e
40 changed files with 751 additions and 338 deletions

View File

@@ -75,22 +75,30 @@ document.addEventListener("DOMContentLoaded", function () {
});
function handleRedirect() {
// 获取当前路径和主机名
const strCurrentPath = window.location.pathname || '/index.html'; // 如果路径为空,默认设置为 /index.html
const strCurrentHost = window.location.origin;
const { pathname, origin, search } = window.location;
// Normalize pathname by replacing multiple slashes with a single slash
const normalizedPath = pathname.replace(/\/+/g, '/');
const strCurrentPath = normalizedPath || '/index.html';
// Build URL with proper slash handling
const buildUrl = (path) => {
// Ensure path starts with a single slash and remove duplicate slashes
const cleanPath = `/${path.replace(/\/+/g, '/')}`.replace(/^\/+/, '/');
return `${origin}${cleanPath}${search}`;
};
if (isMobile()) {
// 移动端逻辑
// Mobile logic: Redirect PC paths to mobile paths
if (strCurrentPath.startsWith(strPcPath)) {
// 如果路径包含 "/pc/",去除 "/pc/"
const newPath = strCurrentPath.replace(strPcPath, '/'); // 去除 "/pc/"
window.location.href = `${strCurrentHost}${newPath}`;
const newPath = strCurrentPath.replace(strPcPath, '') || '/';
window.location.href = buildUrl(newPath);
}
} else {
// PC 端逻辑
// PC logic: Redirect non-PC paths to PC paths
if (!strCurrentPath.startsWith(strPcPath)) {
// 如果路径不包含 "/pc/",添加 "/pc/"
window.location.href = `${strCurrentHost}${strPcPath}${strCurrentPath}`;
const newPath = `${strPcPath}${strCurrentPath === '/' ? '' : strCurrentPath}`;
window.location.href = buildUrl(newPath);
}
}
}