This commit is contained in:
make
2025-04-17 18:25:55 +08:00
parent e0d9316ed7
commit d6656219ee
10 changed files with 298 additions and 339 deletions

View File

@@ -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() {