This commit is contained in:
make
2025-04-12 22:45:39 +08:00
parent 23b082e3c1
commit f740eed79f
14 changed files with 310 additions and 835 deletions

View File

@@ -30,6 +30,25 @@
// );
// } 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() {
@@ -73,31 +92,31 @@ document.addEventListener("DOMContentLoaded", function () {
}
});
});
function handleRedirect() {
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
// 构建URL确保斜杠正确
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
// 移动端逻辑将PC路径重定向到移动端路径
if (strCurrentPath.startsWith(strPcPath)) {
const newPath = strCurrentPath.replace(strPcPath, '') || '/';
window.location.href = buildUrl(newPath);
}
} else {
// PC logic: Redirect non-PC paths to PC paths
// PC端逻辑将非PC路径重定向到PC路径
if (!strCurrentPath.startsWith(strPcPath)) {
const newPath = `${strPcPath}${strCurrentPath === '/' ? '' : strCurrentPath}`;
// 确保 PC 首页以斜杠结尾
const newPath = strCurrentPath === '/' ? `${strPcPath}/` : `${strPcPath}${strCurrentPath}`;
window.location.href = buildUrl(newPath);
}
}
@@ -200,13 +219,15 @@ function displayBookshelf() {
const DomBookshelfContainer = document.getElementById('bookshelfMod-head');
const DomBookshelfContainerH5 = document.getElementById('list');
arrBookshelf.forEach(book => {
console.log(isMobile())
let strNovelUrl = formatNovelUrl(book.og_novel_pin_yin, book.n_id)
let strNovelChapterUrl = formatNovelChapterUrl(book.og_novel_pin_yin, book.n_id, book.c_sort_num)
let strSearchUrl = formatSearchUrl(book.og_novel_author, 1)
if (isMobile()) {
const bookElement = document.createElement('li');
bookElement.classList.add('book-shelf'); // 添加类名
bookElement.classList.add('li2'); // 添加类名
bookElement.innerHTML = `
<a href='/xiaoshuo/${book.og_novel_pin_yin}-${book.n_id}'>
<a href='${strNovelUrl}'>
<div class="leftImage2 ">
<img class="lazyload-img" src="${book.n_cover_path}" >
</div>
@@ -218,8 +239,7 @@ function displayBookshelf() {
<span class="spanLi">${book.c_name}</span>
</span>
<span class="spanLi Time">${book.og_novel_update_time ?? ''}</span>
<span class="rightJustTime"
onclick="javascript:window.location.href='/xiaoshuo/${book.og_novel_pin_yin}-${book.n_id}/zhang-${book.c_sort_num}';return false;">
<span class="rightJustTime" onclick="javascript:window.location.href='${strNovelChapterUrl}';return false;">
继续阅读
</span>
</span>
@@ -234,24 +254,24 @@ function displayBookshelf() {
bookElement.classList.add('book-shelf'); // 添加类名
bookElement.innerHTML = `
<td>
<a href="/pc/xiaoshuo/${book.og_novel_pin_yin}-${book.n_id}" >
<a href="${strPcPath}${strNovelUrl}" >
<img src="${book.n_cover_path}" >
</a>
</td>
<td class="t2">
<a href="/pc/xiaoshuo/${book.og_novel_pin_yin}-${book.n_id}" >${book.og_novel_book_name}</a>
<a href="${strPcPath}${strNovelUrl}" >${book.og_novel_book_name}</a>
</td>
<td class="t3">
<a href="/pc/xiaoshuo/${book.og_novel_pin_yin}-${book.n_id}/zhang-${book.c_sort_num}" >${book.c_name}</a>
<a href="${strPcPath}${strNovelChapterUrl}" >${book.c_name}</a>
</td>
<td class="t4">
<a href="/pc/xiaoshuo/${book.og_novel_pin_yin}-${book.n_id}" >${book.og_novel_author}</a>
<a href="${strPcPath}${strSearchUrl}" >${book.og_novel_author}</a>
</td>
<td class="t5">${book.og_novel_update_time}</td>
<td class="t6">${book.og_novel_status}</td>
<td class="t7">
<a href="/pc/xiaoshuo/${book.og_novel_pin_yin}-${book.n_id}/zhang-${book.c_sort_num}" class="goon" >阅读</a>
<a href="${strPcPath}${strNovelChapterUrl}" class="goon" >阅读</a>
<i><span class="Collection" ajax-get="" onclick="delBookshelfFun(${book.n_id})">删除</span></i>
</td>
@@ -328,12 +348,15 @@ function displayHistory() {
const DomHistoryContainer = document.getElementById('bookshelfMod-head');
const DomBookshelfContainerH5 = document.getElementById('list');
arrHistory.forEach(book => {
let strNovelUrl = formatNovelUrl(book.og_novel_pin_yin, book.n_id)
let strNovelChapterUrl = formatNovelChapterUrl(book.og_novel_pin_yin, book.n_id, book.c_sort_num)
let strSearchUrl = formatSearchUrl(book.og_novel_author, 1)
if (isMobile()) {
const bookElement = document.createElement('li');
bookElement.classList.add('book-history'); // 添加类名
bookElement.classList.add('li2'); // 添加类名
bookElement.innerHTML = `
<a href='/xiaoshuo/${book.og_novel_pin_yin}-${book.n_id}'>
<a href='${strNovelUrl}'>
<div class="leftImage2 ">
<img class="lazyload-img" src="${book.n_cover_path}" >
</div>
@@ -345,8 +368,8 @@ function displayHistory() {
<span class="spanLi">${book.c_name}</span>
</span>
<span class="spanLi Time">${book.og_novel_update_time ?? ''}</span>
<span class="rightJustTime"
onclick="javascript:window.location.href='/xiaoshuo/${book.og_novel_pin_yin}-${book.n_id}/zhang-${book.c_sort_num}';return false;">继续阅读</span>
<span class="rightJustTime" onclick="javascript:window.location.href='${strNovelChapterUrl}';return false;"
>继续阅读</span>
</span>
</div>
</a>
@@ -358,24 +381,24 @@ function displayHistory() {
bookElement.classList.add('book-history'); // 添加类名
bookElement.innerHTML = `
<td>
<a href="/pc/xiaoshuo/${book.og_novel_pin_yin}-${book.n_id}" >
<a href="${strPcPath}${strNovelUrl}" >
<img src="${book.n_cover_path}" >
</a>
</td>
<td class="t2">
<a href="/pc/xiaoshuo/${book.og_novel_pin_yin}-${book.n_id}" >${book.og_novel_book_name}</a>
<a href="${strPcPath}${strNovelUrl}" >${book.og_novel_book_name}</a>
</td>
<td class="t3">
<a href="/pc/xiaoshuo/${book.og_novel_pin_yin}-${book.n_id}/zhang-${book.c_sort_num}" >${book.c_name}</a>
<a href="${strPcPath}${strNovelChapterUrl}" >${book.c_name}</a>
</td>
<td class="t4">
<a href="/pc/xiaoshuo/${book.og_novel_pin_yin}-${book.n_id}" >${book.og_novel_author}</a>
<a href="${strPcPath}${strSearchUrl}" >${book.og_novel_author}</a>
</td>
<td class="t5">${book.og_novel_update_time ?? ''}</td>
<td class="t6">${book.og_novel_status}</td>
<td class="t7">
<a href="/pc/xiaoshuo/${book.og_novel_pin_yin}-${book.n_id}/zhang-${book.c_sort_num}" class="goon" >阅读</a>
<a href="${strNovelChapterUrl}" class="goon" >阅读</a>
<i><span class="Collection" ajax-get="" onclick="delHistoryFun(${book.n_id})">删除</span></i>
</td>