debug
This commit is contained in:
@@ -151,6 +151,7 @@ function incShouCangFun(intId){
|
||||
}
|
||||
|
||||
const strBookshelfKey = window.location.hostname + 'strBookshelfKey';
|
||||
const strHistoryKey = window.location.hostname + 'strHistoryKey';
|
||||
|
||||
// 加入书架
|
||||
function addBookshelfFun(NovelInfo) {
|
||||
@@ -179,6 +180,7 @@ function addBookshelfFun(NovelInfo) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
function displayShujia() {
|
||||
|
||||
// 获取书架数据
|
||||
@@ -194,18 +196,21 @@ function displayShujia() {
|
||||
shujiaContainer.innerHTML = ''; // 清空原内容
|
||||
shujia.forEach(book => {
|
||||
const bookElement = document.createElement('div');
|
||||
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.n_author, 1)
|
||||
if (isMobile()) {
|
||||
bookElement.innerHTML = `
|
||||
<dl class="rec-focus-book">
|
||||
<dt class="book-img">
|
||||
<a href="/shu/${book.xsxq_id}.html">
|
||||
<img height="100" width="80" src="${book.xsxq_feng_mian_url}" >
|
||||
<a href='${strNovelUrl}'>
|
||||
<img height="100" width="80" src="${book.n_cover_path}" >
|
||||
</a>
|
||||
</dt>
|
||||
<dd class="book-info">
|
||||
<h2><a href="/shu/${book.xsxq_id}.html">${book.xsxq_ming_zi}</a></h2>
|
||||
<p>作者: ${book.xsxq_zuozhe}</p>
|
||||
<p> ${book.xsxq_jie_shao}</p>
|
||||
<h2><a href='${strNovelUrl}'>${book.n_name}</a></h2>
|
||||
<p>作者: ${book.n_author}</p>
|
||||
<p> ${book.c_name}</p>
|
||||
</dd>
|
||||
</dl>
|
||||
|
||||
@@ -215,18 +220,109 @@ function displayShujia() {
|
||||
bookElement.innerHTML = `
|
||||
<div class="item">
|
||||
<div class="image">
|
||||
<a href="/shu/${book.xsxq_id}.html">
|
||||
<img style="min-height:120px;" src="${book.xsxq_feng_mian_url}" alt="${book.xsxq_ming_zi}">
|
||||
<a href='${strNovelUrl}'>
|
||||
<img style="min-height:120px;" src="${book.n_cover_path}" alt="${book.n_name}">
|
||||
</a>
|
||||
</div>
|
||||
<dl>
|
||||
<dt>
|
||||
<span>${book.xsxq_zuozhe}</span>
|
||||
<a href="/shu/${book.xsxq_id}.html">${book.xsxq_ming_zi}</a>
|
||||
<span>${book.n_author}</span>
|
||||
<a href='${strNovelUrl}'>${book.n_name}</a>
|
||||
</dt>
|
||||
<dd style="height:90px">
|
||||
<a href="/shu/${book.xsxq_id}.html"
|
||||
style="color: #555">${book.xsxq_jie_shao}</a>
|
||||
<a href='${strNovelChapterUrl}'
|
||||
style="color: #555">${book.c_name}</a>
|
||||
</dd>
|
||||
</dl>
|
||||
</div>
|
||||
|
||||
`;
|
||||
}
|
||||
|
||||
shujiaContainer.appendChild(bookElement);
|
||||
});
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
// 加入阅读记录
|
||||
function addHistoryFun(NovelInfo) {
|
||||
// 如果没有传入 NovelInfo,则使用 arrNovel 并补充字段
|
||||
if (!NovelInfo) {
|
||||
NovelInfo = arrNovel
|
||||
|
||||
}
|
||||
|
||||
// 获取本地存储中的历史记录
|
||||
let arrBookshelf = JSON.parse(localStorage.getItem(strHistoryKey)) || [];
|
||||
// 检查书籍是否已存在
|
||||
const index = arrBookshelf.findIndex(item => item.n_id == NovelInfo.n_id);
|
||||
|
||||
if (index !== -1) {
|
||||
// 如果存在,更新该书籍的信息
|
||||
arrBookshelf[index] = { ...arrBookshelf[index], ...NovelInfo };
|
||||
} else {
|
||||
// 如果不存在,添加到历史记录
|
||||
arrBookshelf.push(NovelInfo);
|
||||
}
|
||||
|
||||
// 更新本地存储
|
||||
localStorage.setItem(strHistoryKey, JSON.stringify(arrBookshelf));
|
||||
}
|
||||
|
||||
|
||||
function displayHistory() {
|
||||
|
||||
// 获取书架数据
|
||||
const shujia = JSON.parse(localStorage.getItem(strHistoryKey)) || [];
|
||||
|
||||
if (shujia.length === 0) {
|
||||
console.log('书架为空');
|
||||
return;
|
||||
}
|
||||
|
||||
// 渲染书籍列表
|
||||
const shujiaContainer = document.getElementById('shujiaContainer');
|
||||
shujiaContainer.innerHTML = ''; // 清空原内容
|
||||
shujia.forEach(book => {
|
||||
const bookElement = document.createElement('div');
|
||||
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.n_author, 1)
|
||||
if (isMobile()) {
|
||||
bookElement.innerHTML = `
|
||||
<dl class="rec-focus-book">
|
||||
<dt class="book-img">
|
||||
<a href='${strNovelUrl}'>
|
||||
<img height="100" width="80" src="${book.n_cover_path}" >
|
||||
</a>
|
||||
</dt>
|
||||
<dd class="book-info">
|
||||
<h2><a href='${strNovelUrl}'>${book.n_name}</a></h2>
|
||||
<p>作者: ${book.n_author}</p>
|
||||
<p> ${book.c_name}</p>
|
||||
</dd>
|
||||
</dl>
|
||||
|
||||
|
||||
`;
|
||||
} else {
|
||||
bookElement.innerHTML = `
|
||||
<div class="item">
|
||||
<div class="image">
|
||||
<a href='${strNovelUrl}'>
|
||||
<img style="min-height:120px;" src="${book.n_cover_path}" alt="${book.n_name}">
|
||||
</a>
|
||||
</div>
|
||||
<dl>
|
||||
<dt>
|
||||
<span>${book.n_author}</span>
|
||||
<a href='${strNovelUrl}'>${book.n_name}</a>
|
||||
</dt>
|
||||
<dd style="height:90px">
|
||||
<a href='${strNovelChapterUrl}'
|
||||
style="color: #555">${book.c_name}</a>
|
||||
</dd>
|
||||
</dl>
|
||||
</div>
|
||||
@@ -243,6 +339,48 @@ function displayShujia() {
|
||||
|
||||
|
||||
|
||||
// 方法1:使用 fetch API
|
||||
async function reportStats(data) {
|
||||
console.log(strPushApi)
|
||||
try {
|
||||
const response = await fetch(strPushApi+'/publish', {
|
||||
method: 'POST',
|
||||
// mode: 'no-cors', // 添加这行
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
// 如果需要认证可以添加
|
||||
// 'Authorization': 'Bearer your-token'
|
||||
},
|
||||
body: JSON.stringify(data)
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error('上报失败');
|
||||
}
|
||||
|
||||
// const result = await response.json();
|
||||
// console.log('上报成功:', result);
|
||||
// return result;
|
||||
} catch (error) {
|
||||
console.error('上报错误:', error);
|
||||
}
|
||||
}
|
||||
|
||||
document.addEventListener("DOMContentLoaded", function () {
|
||||
|
||||
if (typeof strNovelId !== "undefined") {
|
||||
|
||||
// 使用示例
|
||||
const statsData = {
|
||||
n_id: strNovelId,
|
||||
};
|
||||
// 调用方法1
|
||||
reportStats(statsData);
|
||||
|
||||
addHistoryFun()
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
// // 生成二维码
|
||||
// async function generateQRCode() {
|
||||
|
||||
@@ -222,7 +222,7 @@ function displayBookshelf() {
|
||||
arrBookshelf.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)
|
||||
let strSearchUrl = formatSearchUrl(book.n_author, 1)
|
||||
if (isMobile()) {
|
||||
const bookElement = document.createElement('li');
|
||||
bookElement.classList.add('book-shelf'); // 添加类名
|
||||
@@ -233,8 +233,8 @@ function displayBookshelf() {
|
||||
<img class="lazyload-img" src="${book.n_cover_path}" >
|
||||
</div>
|
||||
<div class="rightBlock">
|
||||
<span class="rightBlock_title">${book.og_novel_book_name}</span>
|
||||
<span class="rightBlock_name">${book.og_novel_author}</span>
|
||||
<span class="rightBlock_title">${book.n_namen}</span>
|
||||
<span class="rightBlock_name">${book.n_author}</span>
|
||||
<span class="rightBlock_con rightBlock_con2">
|
||||
<span class="con">
|
||||
<span class="spanLi">${book.c_name}</span>
|
||||
@@ -260,13 +260,13 @@ function displayBookshelf() {
|
||||
</a>
|
||||
</td>
|
||||
<td class="t2">
|
||||
<a href="${strPcPath}${strNovelUrl}" >${book.og_novel_book_name}</a>
|
||||
<a href="${strPcPath}${strNovelUrl}" >${book.n_namen}</a>
|
||||
</td>
|
||||
<td class="t3">
|
||||
<a href="${strPcPath}${strNovelChapterUrl}" >${book.c_name}</a>
|
||||
</td>
|
||||
<td class="t4">
|
||||
<a href="${strPcPath}${strSearchUrl}" >${book.og_novel_author}</a>
|
||||
<a href="${strPcPath}${strSearchUrl}" >${book.n_author}</a>
|
||||
</td>
|
||||
<td class="t5">${book.og_novel_update_time}</td>
|
||||
|
||||
@@ -351,7 +351,7 @@ function displayHistory() {
|
||||
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)
|
||||
let strSearchUrl = formatSearchUrl(book.n_author, 1)
|
||||
if (isMobile()) {
|
||||
const bookElement = document.createElement('li');
|
||||
bookElement.classList.add('book-history'); // 添加类名
|
||||
@@ -362,8 +362,8 @@ function displayHistory() {
|
||||
<img class="lazyload-img" src="${book.n_cover_path}" >
|
||||
</div>
|
||||
<div class="rightBlock">
|
||||
<span class="rightBlock_title">${book.og_novel_book_name}</span>
|
||||
<span class="rightBlock_name">${book.og_novel_author}</span>
|
||||
<span class="rightBlock_title">${book.n_namen}</span>
|
||||
<span class="rightBlock_name">${book.n_author}</span>
|
||||
<span class="rightBlock_con rightBlock_con2">
|
||||
<span class="con">
|
||||
<span class="spanLi">${book.c_name}</span>
|
||||
@@ -387,13 +387,13 @@ function displayHistory() {
|
||||
</a>
|
||||
</td>
|
||||
<td class="t2">
|
||||
<a href="${strPcPath}${strNovelUrl}" >${book.og_novel_book_name}</a>
|
||||
<a href="${strPcPath}${strNovelUrl}" >${book.n_name}</a>
|
||||
</td>
|
||||
<td class="t3">
|
||||
<a href="${strPcPath}${strNovelChapterUrl}" >${book.c_name}</a>
|
||||
</td>
|
||||
<td class="t4">
|
||||
<a href="${strPcPath}${strSearchUrl}" >${book.og_novel_author}</a>
|
||||
<a href="${strPcPath}${strSearchUrl}" >${book.n_author}</a>
|
||||
</td>
|
||||
<td class="t5">${book.og_novel_update_time ?? ''}</td>
|
||||
|
||||
@@ -413,7 +413,7 @@ function displayHistory() {
|
||||
|
||||
// 方法1:使用 fetch API
|
||||
async function reportStats(data) {
|
||||
console.log(strPushApi)
|
||||
|
||||
try {
|
||||
const response = await fetch(strPushApi+'/publish', {
|
||||
method: 'POST',
|
||||
|
||||
Reference in New Issue
Block a user