修复
This commit is contained in:
@@ -4,11 +4,13 @@
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>随机JavaScript趣味题</title>
|
||||
<link rel="preconnect" href="https://cdnjs.cloudflare.com">
|
||||
<link rel="dns-prefetch" href="https://60s.api.shumengya.top">
|
||||
<link rel="stylesheet" href="css/style.css">
|
||||
<link rel="stylesheet" href="css/background.css">
|
||||
<link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/highlight.js/11.9.0/styles/github.min.css">
|
||||
<script src="https://cdn.bootcdn.net/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
|
||||
<script src="https://cdn.bootcdn.net/ajax/libs/highlight.js/11.9.0/languages/javascript.min.js"></script>
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/github.min.css">
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/languages/javascript.min.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
|
||||
@@ -2,19 +2,17 @@
|
||||
class JSQuizApp {
|
||||
constructor() {
|
||||
this.apiEndpoints = [
|
||||
'https://60s-cf.viki.moe',
|
||||
'https://60s.viki.moe',
|
||||
'https://60s.b23.run',
|
||||
'https://60s.114128.xyz',
|
||||
'https://60s-cf.114128.xyz'
|
||||
'https://60s.api.shumengya.top',
|
||||
];
|
||||
this.currentApiIndex = 0;
|
||||
this.currentQuestion = null;
|
||||
this.selectedOption = null;
|
||||
this.isAnswered = false;
|
||||
this.loadStartTime = null;
|
||||
|
||||
this.initElements();
|
||||
this.bindEvents();
|
||||
this.preloadResources();
|
||||
this.loadQuestion();
|
||||
}
|
||||
|
||||
@@ -41,6 +39,17 @@ class JSQuizApp {
|
||||
};
|
||||
}
|
||||
|
||||
// 预加载资源
|
||||
preloadResources() {
|
||||
// 预连接API服务器
|
||||
this.apiEndpoints.forEach(endpoint => {
|
||||
const link = document.createElement('link');
|
||||
link.rel = 'preconnect';
|
||||
link.href = endpoint;
|
||||
document.head.appendChild(link);
|
||||
});
|
||||
}
|
||||
|
||||
// 绑定事件
|
||||
bindEvents() {
|
||||
this.elements.submitBtn.addEventListener('click', () => this.submitAnswer());
|
||||
@@ -84,6 +93,7 @@ class JSQuizApp {
|
||||
|
||||
// 加载题目
|
||||
async loadQuestion() {
|
||||
this.loadStartTime = Date.now();
|
||||
this.showLoading();
|
||||
this.resetQuestion();
|
||||
|
||||
@@ -92,15 +102,20 @@ class JSQuizApp {
|
||||
|
||||
while (attempts < maxAttempts) {
|
||||
try {
|
||||
const controller = new AbortController();
|
||||
const timeoutId = setTimeout(() => controller.abort(), 5000);
|
||||
|
||||
const response = await fetch(this.getCurrentApiUrl(), {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
timeout: 10000
|
||||
signal: controller.signal
|
||||
});
|
||||
|
||||
clearTimeout(timeoutId);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
||||
}
|
||||
@@ -109,6 +124,8 @@ class JSQuizApp {
|
||||
|
||||
if (data.code === 200 && data.data) {
|
||||
this.currentQuestion = data.data;
|
||||
const loadTime = Date.now() - this.loadStartTime;
|
||||
console.log(`题目加载完成,耗时: ${loadTime}ms`);
|
||||
this.displayQuestion();
|
||||
return;
|
||||
} else {
|
||||
|
||||
@@ -1,47 +1 @@
|
||||
{
|
||||
"api_name": "60s-api",
|
||||
"api_version": "2.22.1",
|
||||
"api_docs": "https://docs.60s-api.viki.moe",
|
||||
"author": "Viki <hi@viki.moe>",
|
||||
"user_group": "595941841",
|
||||
"github_repo": "https://github.com/vikiboss/60s",
|
||||
"updated": "2025/09/01 11:12:08",
|
||||
"updated_at": 1756696328000,
|
||||
"endpoints": [
|
||||
"/v2/60s",
|
||||
"/v2/answer",
|
||||
"/v2/baike",
|
||||
"/v2/bili",
|
||||
"/v2/bing",
|
||||
"/v2/changya",
|
||||
"/v2/chemical",
|
||||
"/v2/douyin",
|
||||
"/v2/duanzi",
|
||||
"/v2/epic",
|
||||
"/v2/exchange_rate",
|
||||
"/v2/fabing",
|
||||
"/v2/hitokoto",
|
||||
"/v2/ip",
|
||||
"/v2/kfc",
|
||||
"/v2/luck",
|
||||
"/v2/maoyan",
|
||||
"/v2/today_in_history",
|
||||
"/v2/toutiao",
|
||||
"/v2/weibo",
|
||||
"/v2/zhihu",
|
||||
"/v2/lunar",
|
||||
"/v2/ai-news",
|
||||
"/v2/awesome-js",
|
||||
"/v2/qrcode",
|
||||
"/v2/dad-joke",
|
||||
"/v2/hacker-news/:type",
|
||||
"/v2/og",
|
||||
"/v2/hash",
|
||||
"/v2/fanyi",
|
||||
"/v2/fanyi/langs",
|
||||
"/v2/weather",
|
||||
"/v2/weather/forecast",
|
||||
"/v2/ncm-rank",
|
||||
"/v2/ncm-rank/:id"
|
||||
]
|
||||
}
|
||||
["https://60s.api.shumengya.top"]
|
||||
@@ -1,47 +1 @@
|
||||
{
|
||||
"api_name": "60s-api",
|
||||
"api_version": "2.22.1",
|
||||
"api_docs": "https://docs.60s-api.viki.moe",
|
||||
"author": "Viki <hi@viki.moe>",
|
||||
"user_group": "595941841",
|
||||
"github_repo": "https://github.com/vikiboss/60s",
|
||||
"updated": "2025/09/01 11:12:08",
|
||||
"updated_at": 1756696328000,
|
||||
"endpoints": [
|
||||
"/v2/60s",
|
||||
"/v2/answer",
|
||||
"/v2/baike",
|
||||
"/v2/bili",
|
||||
"/v2/bing",
|
||||
"/v2/changya",
|
||||
"/v2/chemical",
|
||||
"/v2/douyin",
|
||||
"/v2/duanzi",
|
||||
"/v2/epic",
|
||||
"/v2/exchange_rate",
|
||||
"/v2/fabing",
|
||||
"/v2/hitokoto",
|
||||
"/v2/ip",
|
||||
"/v2/kfc",
|
||||
"/v2/luck",
|
||||
"/v2/maoyan",
|
||||
"/v2/today_in_history",
|
||||
"/v2/toutiao",
|
||||
"/v2/weibo",
|
||||
"/v2/zhihu",
|
||||
"/v2/lunar",
|
||||
"/v2/ai-news",
|
||||
"/v2/awesome-js",
|
||||
"/v2/qrcode",
|
||||
"/v2/dad-joke",
|
||||
"/v2/hacker-news/:type",
|
||||
"/v2/og",
|
||||
"/v2/hash",
|
||||
"/v2/fanyi",
|
||||
"/v2/fanyi/langs",
|
||||
"/v2/weather",
|
||||
"/v2/weather/forecast",
|
||||
"/v2/ncm-rank",
|
||||
"/v2/ncm-rank/:id"
|
||||
]
|
||||
}
|
||||
["https://60s.api.shumengya.top"]
|
||||
@@ -17,7 +17,7 @@
|
||||
this.endpoints = endpoints.map(endpoint => `${endpoint}/v2/changya`);
|
||||
} catch (e) {
|
||||
// 如果无法加载接口集合,使用默认接口
|
||||
this.endpoints = ['https://60s.viki.moe/v2/changya'];
|
||||
this.endpoints = ['https://60s.api.shumengya.top/v2/changya'];
|
||||
}
|
||||
},
|
||||
// 获取当前接口URL
|
||||
|
||||
@@ -8,7 +8,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
const jokeCard = document.getElementById('joke-card');
|
||||
|
||||
// API
|
||||
const apiBaseUrls = ["https://60s.api.shumengya.top", "https://60s-cf.viki.moe", "https://60s.viki.moe"];
|
||||
const apiBaseUrls = ["https://60s.api.shumengya.top"];
|
||||
const apiPath = "/v2/duanzi";
|
||||
let currentApiIndex = 0;
|
||||
|
||||
|
||||
@@ -1,47 +1 @@
|
||||
{
|
||||
"api_name": "60s-api",
|
||||
"api_version": "2.22.1",
|
||||
"api_docs": "https://docs.60s-api.viki.moe",
|
||||
"author": "Viki <hi@viki.moe>",
|
||||
"user_group": "595941841",
|
||||
"github_repo": "https://github.com/vikiboss/60s",
|
||||
"updated": "2025/09/01 11:12:08",
|
||||
"updated_at": 1756696328000,
|
||||
"endpoints": [
|
||||
"/v2/60s",
|
||||
"/v2/answer",
|
||||
"/v2/baike",
|
||||
"/v2/bili",
|
||||
"/v2/bing",
|
||||
"/v2/changya",
|
||||
"/v2/chemical",
|
||||
"/v2/douyin",
|
||||
"/v2/duanzi",
|
||||
"/v2/epic",
|
||||
"/v2/exchange_rate",
|
||||
"/v2/fabing",
|
||||
"/v2/hitokoto",
|
||||
"/v2/ip",
|
||||
"/v2/kfc",
|
||||
"/v2/luck",
|
||||
"/v2/maoyan",
|
||||
"/v2/today_in_history",
|
||||
"/v2/toutiao",
|
||||
"/v2/weibo",
|
||||
"/v2/zhihu",
|
||||
"/v2/lunar",
|
||||
"/v2/ai-news",
|
||||
"/v2/awesome-js",
|
||||
"/v2/qrcode",
|
||||
"/v2/dad-joke",
|
||||
"/v2/hacker-news/:type",
|
||||
"/v2/og",
|
||||
"/v2/hash",
|
||||
"/v2/fanyi",
|
||||
"/v2/fanyi/langs",
|
||||
"/v2/weather",
|
||||
"/v2/weather/forecast",
|
||||
"/v2/ncm-rank",
|
||||
"/v2/ncm-rank/:id"
|
||||
]
|
||||
}
|
||||
["https://60s.api.shumengya.top"]
|
||||
@@ -14,11 +14,6 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
|
||||
const apiBaseUrls = [
|
||||
"https://60s.api.shumengya.top",
|
||||
"https://60s-cf.viki.moe",
|
||||
"https://60s.viki.moe",
|
||||
"https://60s.b23.run",
|
||||
"https://60s.114128.xyz",
|
||||
"https://60s-cf.114128.xyz"
|
||||
];
|
||||
const apiPath = "/v2/luck";
|
||||
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
[
|
||||
"https://60s-cf.viki.moe",
|
||||
"https://60s.viki.moe",
|
||||
"https://60s.b23.run",
|
||||
"https://60s.114128.xyz",
|
||||
"https://60s-cf.114128.xyz"
|
||||
"https://60s.api.shumengya.top"
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user