修改配置文件

This commit is contained in:
2026-06-18 21:59:07 +08:00 Unverified
parent fc76f9949f
commit ed2ef30d22
23 changed files with 270 additions and 137 deletions
+15 -9
View File
@@ -11,6 +11,10 @@ function indexTalk() {
}
if (!document.getElementById('bber-talk')) return;
const config = window.SITE_CONFIG?.talks || {};
const talksCacheKey = config.cacheKey || cacheKey;
const talksCacheTimeKey = config.cacheTimeKey || cacheTimeKey;
const talksCacheDuration = config.cacheDurationMs || cacheDuration;
function toText(ls) {
return ls.map(item => {
@@ -57,29 +61,31 @@ function indexTalk() {
}, 3000);
}
const cachedData = localStorage.getItem(cacheKey);
const cachedTime = localStorage.getItem(cacheTimeKey);
const cachedData = localStorage.getItem(talksCacheKey);
const cachedTime = localStorage.getItem(talksCacheTimeKey);
const currentTime = new Date().getTime();
// 判断缓存是否有效
if (cachedData && cachedTime && (currentTime - cachedTime < cacheDuration)) {
if (cachedData && cachedTime && (currentTime - cachedTime < talksCacheDuration)) {
const data = toText(JSON.parse(cachedData));
talk(data.slice(0, 6)); // 使用缓存渲染数据
talk(data.slice(0, config.homeLimit || 6)); // 使用缓存渲染数据
} else {
fetch('https://mm.biss.click/api/echo/page', {
if (!config.apiUrl) return;
fetch(config.apiUrl, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ page: 1, pageSize: 30 })
body: JSON.stringify({ page: 1, pageSize: config.pageSize || 30 })
})
.then(res => res.json())
.then(data => {
// 适配新版结构:code=1 且 data.items 存在
if (data.code === 1 && data.data && Array.isArray(data.data.items)) {
localStorage.setItem(cacheKey, JSON.stringify(data.data.items));
localStorage.setItem(cacheTimeKey, currentTime.toString());
localStorage.setItem(talksCacheKey, JSON.stringify(data.data.items));
localStorage.setItem(talksCacheTimeKey, currentTime.toString());
const formattedData = toText(data.data.items);
talk(formattedData.slice(0, 6));
talk(formattedData.slice(0, config.homeLimit || 6));
} else {
console.warn('Unexpected API response format:', data);
}