DreamLife_HomePage/javascape/daily_quote.js

30 lines
935 B
JavaScript
Raw Normal View History

2026-03-25 21:15:55 +08:00
// 每日一言功能
class DailyQuote {
constructor() {
this.init();
}
init() {
this.loadQuote();
}
async loadQuote() {
try {
// 使用一言API获取每日一句
const response = await fetch('https://v1.hitokoto.cn/?c=a&c=b&c=c&c=d&c=e&c=f&c=g&c=h');
const data = await response.json();
document.getElementById('quoteContent').textContent = data.hitokoto;
document.getElementById('quoteAuthor').textContent = data.from || '未知';
} catch (error) {
console.error('加载每日一言失败:', error);
document.getElementById('quoteContent').textContent = '加载失败';
document.getElementById('quoteAuthor').textContent = '';
}
}
}
// 页面加载完成后初始化每日一言
window.addEventListener('DOMContentLoaded', () => {
new DailyQuote();
});