// 在页面加载时自动获取一条文本
window.onload = function() {
fetch(‘
https://api.vvhan.com/api/text/joke’)
.then(response => response.text())
.then(data => {
const jokeContainer = document.getElementById(‘jokeContainer’);
jokeContainer.textContent = data;
// 根据窗口大小调整字体大小
const width = window.innerWidth;
if (width console.error(‘获取笑话失败:’, error));
};
function refreshJoke() {
fetch(‘
https://api.vvhan.com/api/text/joke’)
.then(response => response.text())
.then(data => {
const jokeContainer = document.getElementById(‘jokeContainer’);
jokeContainer.textContent = data;
// 根据窗口大小调整字体大小
const width = window.innerWidth;
if (width console.error(‘获取笑话失败:’, error));
}