适配新接口

This commit is contained in:
anian
2026-05-09 09:45:17 +08:00
parent 061b00fc05
commit 92d591f70b
2 changed files with 36 additions and 14 deletions
+35 -13
View File
@@ -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(`<br>${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) {
+1 -1
View File
@@ -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 读取