// API接口列表
const API_ENDPOINTS = [
"https://60s.api.shumengya.top/v2/zhihu",
];
// 当前使用的API索引
let currentApiIndex = 0;
// DOM元素
const topicListElement = document.getElementById('topicList');
const updateTimeElement = document.getElementById('updateTime');
// 格式化时间
function formatDate(date) {
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, '0');
const day = String(date.getDate()).padStart(2, '0');
const hours = String(date.getHours()).padStart(2, '0');
const minutes = String(date.getMinutes()).padStart(2, '0');
const seconds = String(date.getSeconds()).padStart(2, '0');
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
}
// 格式化数字
function formatNumber(num) {
if (num >= 10000) {
return (num / 10000).toFixed(1) + '万';
}
return num.toString();
}
// 渲染话题列表
function renderTopicList(data) {
topicListElement.innerHTML = '';
data.forEach((item, index) => {
const topicItem = document.createElement('div');
topicItem.className = 'topic-item';
const rankClass = index < 3 ? `top-${index + 1}` : '';
// 处理封面图片
const coverImg = item.cover ?
`` : '';
// 判断文本内容长度,决定图片位置
// 如果detail存在且长度较长,或者没有detail但标题较长,则图片放在下方
const detailLength = item.detail ? item.detail.length : 0;
const titleLength = item.title ? item.title.length : 0;
const isLongContent = detailLength > 100 || (detailLength === 0 && titleLength > 30);
// 根据内容长度决定布局类名
const layoutClass = isLongContent ? 'long-content' : 'short-content';
topicItem.innerHTML = `