This commit is contained in:
make
2025-04-16 09:28:31 +08:00
parent 58fc0fb50b
commit d02aac7691
10 changed files with 364 additions and 405 deletions

View File

@@ -31,10 +31,60 @@
// } catch (err) { }
// })();
function formatNovelUrl(strPinYin, intNId) {
return strNovelUrlTemp
.replace('{strPinYin}', encodeURIComponent(strPinYin))
.replace('{intNId}', intNId);
}
function formatNovelChapterUrl(strPinYin, intNId, intSort,intPage=0) {
return strNovelChapterUrlTemp
.replace('{strPinYin}', encodeURIComponent(strPinYin))
.replace('{intNId}', intNId)
.replace('{intChapterPage}', intPage)
.replace('{intChapterSort}', intSort);
}
function formatSearchUrl(strKey,intPage=1) {
return strSearchUrlTemp
.replace('{strSearchKeywords}', strKey)
.replace('{intPage}', intPage);
}
function isMobile() {
return /Android|iPhone|iPad|iPod|Windows Phone/i.test(navigator.userAgent);
}
function handleRedirect() {
const { pathname, origin, search } = window.location;
// 规范化路径名,将多个斜杠替换为单个斜杠
const normalizedPath = pathname.replace(/\/+/g, '/');
const strCurrentPath = normalizedPath || '/index.html';
// 构建URL确保斜杠正确
const buildUrl = (path) => {
// 确保路径以单个斜杠开头,并移除多余斜杠
const cleanPath = `/${path.replace(/\/+/g, '/')}`.replace(/^\/+/, '/');
return `${origin}${cleanPath}${search}`;
};
if (isMobile()) {
// 移动端逻辑将PC路径重定向到移动端路径
if (strCurrentPath.startsWith(strPcPath)) {
const newPath = strCurrentPath.replace(strPcPath, '') || '/';
window.location.href = buildUrl(newPath);
}
} else {
// PC端逻辑将非PC路径重定向到PC路径
if (!strCurrentPath.startsWith(strPcPath)) {
// 确保 PC 首页以斜杠结尾
const newPath = strCurrentPath === '/' ? `${strPcPath}/` : `${strPcPath}${strCurrentPath}`;
window.location.href = buildUrl(newPath);
}
}
}
handleRedirect();
function layerPopup(strContent, intTime) {
layer.open({