From 92d591f70b1163ca820080eade23e26d684737c1 Mon Sep 17 00:00:00 2001 From: anian Date: Sat, 9 May 2026 09:45:17 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=82=E9=85=8D=E6=96=B0=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- templates/assets/js/app.js | 48 +++++++++++++++++++++++++---------- templates/modules/header.html | 2 +- 2 files changed, 36 insertions(+), 14 deletions(-) diff --git a/templates/assets/js/app.js b/templates/assets/js/app.js index 55630fb..51be2cd 100644 --- a/templates/assets/js/app.js +++ b/templates/assets/js/app.js @@ -1780,12 +1780,13 @@ $('body').on('click', '.yiyan_box .change', function () { const targetElement = document.querySelector('.yiyan_box p'); if (url.includes('api.anian.cc')) { // 新增处理逻辑 - targetElement.innerText = data.content; - targetElement.setAttribute("uk-tooltip", `《${data.title}》${data.author}`); + targetElement.innerText = data.content || '一日不见如隔三秋'; + const tooltipTitle = data.title || '失败:超时或发生错误'; + targetElement.setAttribute("uk-tooltip", tooltipTitle === '失败:超时或发生错误' ? `${tooltipTitle}${data.author || ''}` : `《${tooltipTitle}》${data.author || ''}`); } else { // 原有一言API处理逻辑 - targetElement.innerText = data.hitokoto; - targetElement.setAttribute("uk-tooltip", data.from); + targetElement.innerText = data.hitokoto || '一日不见如隔三秋'; + targetElement.setAttribute("uk-tooltip", data.from || '失败:超时或发生错误'); } }) .finally(() => { @@ -2635,7 +2636,7 @@ function anianxSpeedFetchLuckWithTimeout(timeout) { const controller = new AbortController(); const timer = setTimeout(() => controller.abort(), timeout); - return fetch("https://api.anian.cc/luck", { + return fetch("https://api.anian.cc/luck/api", { signal: controller.signal }).then(response => { if (!response.ok) { @@ -2676,7 +2677,7 @@ if (anianxSpeedMainLine) { const explanationText = result.explanation || ""; const poetryText = result.poetry || ""; const meaningText = result.meaning || ""; - anianxSpeedBubbleText.innerText = [typeText, titleText].filter(Boolean).join(" · ") || "抽取成功"; + anianxSpeedBubbleText.innerText = [typeText, titleText].filter(Boolean).join(" · ") || "失败:超时或发生错误"; anianxSpeedSetTooltip(anianxSpeedBubbleText, anianxSpeedBuildLuckTooltip(idText, poetryText, meaningText, explanationText)); }).catch(() => { anianxSpeedClearTooltip(anianxSpeedBubbleText); @@ -2702,8 +2703,7 @@ if (anianxSpeedTestLine) { ]).then(([speedResult, ipResult]) => { anianxSpeedBubbleText.classList.remove("anianx-loading"); anianxSpeedBubbleText.innerText = speedResult; - // 设置tooltip显示IP地址 - const tooltipText = ipResult ? `IP地址: ${ipResult}` : "IP地址获取失败"; + const tooltipText = anianxSpeedBuildIpTooltip(ipResult); anianxSpeedSetTooltip(anianxSpeedBubbleText, tooltipText); }).catch(() => { anianxSpeedClearTooltip(anianxSpeedBubbleText); @@ -2729,7 +2729,7 @@ if (anianxSpeedSubLine) { if (data && data.riddle) { anianxSpeedBubbleText.innerText = data.riddle; // 设置tooltip显示答案 - const tooltipText = data.answer || "暂无答案"; + const tooltipText = data.answer || "失败:超时或发生错误"; anianxSpeedSetTooltip(anianxSpeedBubbleText, tooltipText); } else { anianxSpeedClearTooltip(anianxSpeedBubbleText); @@ -2771,7 +2771,7 @@ function anianxSpeedFetchIpWithTimeout(timeout) { const controller = new AbortController(); const timer = setTimeout(() => controller.abort(), timeout); - return fetch("https://api.anian.cc/ip", { + return fetch("https://api.anian.cc/ip/api", { signal: controller.signal }).then(response => { if (!response.ok) { @@ -2780,18 +2780,40 @@ function anianxSpeedFetchIpWithTimeout(timeout) { return response.json(); }).then(data => { clearTimeout(timer); - return data.ip || ""; + return { + ip: data.ip || "", + region: data.region || "" + }; }).catch(e => { clearTimeout(timer); - return ""; + return { + ip: "", + region: "" + }; }); } +function anianxSpeedBuildIpTooltip(ipInfo) { + if (!ipInfo || (!ipInfo.ip && !ipInfo.region)) { + return "失败:超时或发生错误"; + } + + const lines = []; + if (ipInfo.ip) { + lines.push(`IP地址: ${ipInfo.ip}`); + } + if (ipInfo.region) { + lines.push(`
${ipInfo.region}`); + } + + return lines.join("\n"); +} + function anianxSpeedFetchXiehouyuWithTimeout(timeout) { const controller = new AbortController(); const timer = setTimeout(() => controller.abort(), timeout); - return fetch("https://api.anian.cc/xiehouyu", { + return fetch("https://api.anian.cc/riddle/api", { signal: controller.signal }).then(response => { if (!response.ok) { diff --git a/templates/modules/header.html b/templates/modules/header.html index be57ddd..4998937 100644 --- a/templates/modules/header.html +++ b/templates/modules/header.html @@ -102,7 +102,7 @@ function setBanner(lunarInfo) { // 初始化逻辑(优化版) // -------------------------- (function() { - const apiUrl = 'https://api.anian.cc/lunar'; + const apiUrl = 'https://api.anian.cc/lunar/api'; const cookieName = 'anian_lunar_info'; // 1. 优先尝试从 Cookie 读取