适配新接口
This commit is contained in:
+35
-13
@@ -1780,12 +1780,13 @@ $('body').on('click', '.yiyan_box .change', function () {
|
|||||||
const targetElement = document.querySelector('.yiyan_box p');
|
const targetElement = document.querySelector('.yiyan_box p');
|
||||||
if (url.includes('api.anian.cc')) {
|
if (url.includes('api.anian.cc')) {
|
||||||
// 新增处理逻辑
|
// 新增处理逻辑
|
||||||
targetElement.innerText = data.content;
|
targetElement.innerText = data.content || '一日不见如隔三秋';
|
||||||
targetElement.setAttribute("uk-tooltip", `《${data.title}》${data.author}`);
|
const tooltipTitle = data.title || '失败:超时或发生错误';
|
||||||
|
targetElement.setAttribute("uk-tooltip", tooltipTitle === '失败:超时或发生错误' ? `${tooltipTitle}${data.author || ''}` : `《${tooltipTitle}》${data.author || ''}`);
|
||||||
} else {
|
} else {
|
||||||
// 原有一言API处理逻辑
|
// 原有一言API处理逻辑
|
||||||
targetElement.innerText = data.hitokoto;
|
targetElement.innerText = data.hitokoto || '一日不见如隔三秋';
|
||||||
targetElement.setAttribute("uk-tooltip", data.from);
|
targetElement.setAttribute("uk-tooltip", data.from || '失败:超时或发生错误');
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
@@ -2635,7 +2636,7 @@ function anianxSpeedFetchLuckWithTimeout(timeout) {
|
|||||||
const controller = new AbortController();
|
const controller = new AbortController();
|
||||||
const timer = setTimeout(() => controller.abort(), timeout);
|
const timer = setTimeout(() => controller.abort(), timeout);
|
||||||
|
|
||||||
return fetch("https://api.anian.cc/luck", {
|
return fetch("https://api.anian.cc/luck/api", {
|
||||||
signal: controller.signal
|
signal: controller.signal
|
||||||
}).then(response => {
|
}).then(response => {
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
@@ -2676,7 +2677,7 @@ if (anianxSpeedMainLine) {
|
|||||||
const explanationText = result.explanation || "";
|
const explanationText = result.explanation || "";
|
||||||
const poetryText = result.poetry || "";
|
const poetryText = result.poetry || "";
|
||||||
const meaningText = result.meaning || "";
|
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));
|
anianxSpeedSetTooltip(anianxSpeedBubbleText, anianxSpeedBuildLuckTooltip(idText, poetryText, meaningText, explanationText));
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
anianxSpeedClearTooltip(anianxSpeedBubbleText);
|
anianxSpeedClearTooltip(anianxSpeedBubbleText);
|
||||||
@@ -2702,8 +2703,7 @@ if (anianxSpeedTestLine) {
|
|||||||
]).then(([speedResult, ipResult]) => {
|
]).then(([speedResult, ipResult]) => {
|
||||||
anianxSpeedBubbleText.classList.remove("anianx-loading");
|
anianxSpeedBubbleText.classList.remove("anianx-loading");
|
||||||
anianxSpeedBubbleText.innerText = speedResult;
|
anianxSpeedBubbleText.innerText = speedResult;
|
||||||
// 设置tooltip显示IP地址
|
const tooltipText = anianxSpeedBuildIpTooltip(ipResult);
|
||||||
const tooltipText = ipResult ? `IP地址: ${ipResult}` : "IP地址获取失败";
|
|
||||||
anianxSpeedSetTooltip(anianxSpeedBubbleText, tooltipText);
|
anianxSpeedSetTooltip(anianxSpeedBubbleText, tooltipText);
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
anianxSpeedClearTooltip(anianxSpeedBubbleText);
|
anianxSpeedClearTooltip(anianxSpeedBubbleText);
|
||||||
@@ -2729,7 +2729,7 @@ if (anianxSpeedSubLine) {
|
|||||||
if (data && data.riddle) {
|
if (data && data.riddle) {
|
||||||
anianxSpeedBubbleText.innerText = data.riddle;
|
anianxSpeedBubbleText.innerText = data.riddle;
|
||||||
// 设置tooltip显示答案
|
// 设置tooltip显示答案
|
||||||
const tooltipText = data.answer || "暂无答案";
|
const tooltipText = data.answer || "失败:超时或发生错误";
|
||||||
anianxSpeedSetTooltip(anianxSpeedBubbleText, tooltipText);
|
anianxSpeedSetTooltip(anianxSpeedBubbleText, tooltipText);
|
||||||
} else {
|
} else {
|
||||||
anianxSpeedClearTooltip(anianxSpeedBubbleText);
|
anianxSpeedClearTooltip(anianxSpeedBubbleText);
|
||||||
@@ -2771,7 +2771,7 @@ function anianxSpeedFetchIpWithTimeout(timeout) {
|
|||||||
const controller = new AbortController();
|
const controller = new AbortController();
|
||||||
const timer = setTimeout(() => controller.abort(), timeout);
|
const timer = setTimeout(() => controller.abort(), timeout);
|
||||||
|
|
||||||
return fetch("https://api.anian.cc/ip", {
|
return fetch("https://api.anian.cc/ip/api", {
|
||||||
signal: controller.signal
|
signal: controller.signal
|
||||||
}).then(response => {
|
}).then(response => {
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
@@ -2780,18 +2780,40 @@ function anianxSpeedFetchIpWithTimeout(timeout) {
|
|||||||
return response.json();
|
return response.json();
|
||||||
}).then(data => {
|
}).then(data => {
|
||||||
clearTimeout(timer);
|
clearTimeout(timer);
|
||||||
return data.ip || "";
|
return {
|
||||||
|
ip: data.ip || "",
|
||||||
|
region: data.region || ""
|
||||||
|
};
|
||||||
}).catch(e => {
|
}).catch(e => {
|
||||||
clearTimeout(timer);
|
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) {
|
function anianxSpeedFetchXiehouyuWithTimeout(timeout) {
|
||||||
const controller = new AbortController();
|
const controller = new AbortController();
|
||||||
const timer = setTimeout(() => controller.abort(), timeout);
|
const timer = setTimeout(() => controller.abort(), timeout);
|
||||||
|
|
||||||
return fetch("https://api.anian.cc/xiehouyu", {
|
return fetch("https://api.anian.cc/riddle/api", {
|
||||||
signal: controller.signal
|
signal: controller.signal
|
||||||
}).then(response => {
|
}).then(response => {
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ function setBanner(lunarInfo) {
|
|||||||
// 初始化逻辑(优化版)
|
// 初始化逻辑(优化版)
|
||||||
// --------------------------
|
// --------------------------
|
||||||
(function() {
|
(function() {
|
||||||
const apiUrl = 'https://api.anian.cc/lunar';
|
const apiUrl = 'https://api.anian.cc/lunar/api';
|
||||||
const cookieName = 'anian_lunar_info';
|
const cookieName = 'anian_lunar_info';
|
||||||
|
|
||||||
// 1. 优先尝试从 Cookie 读取
|
// 1. 优先尝试从 Cookie 读取
|
||||||
|
|||||||
Reference in New Issue
Block a user