重构课外书;更新侧边栏;修复模态框、分享海报异常
This commit is contained in:
+268
-120
@@ -674,8 +674,10 @@ $(document).on('click', '.push_item', function () {
|
||||
closeLoading?.()
|
||||
cocoMessage.success('发布成功!');
|
||||
const currentScrollTop = window.scrollY || document.documentElement.scrollTop;
|
||||
$.cookie('scrollParam', currentScrollTop, { path: '/', domain: 'anian.cc' });
|
||||
$.cookie('load_type', 'create', { path: '/', domain: 'anian.cc' });
|
||||
// $.cookie('scrollParam', currentScrollTop, { path: '/', domain: 'anian.cc' });
|
||||
// $.cookie('load_type', 'create', { path: '/', domain: 'anian.cc' });
|
||||
$.cookie('scrollParam', currentScrollTop, { path: '/' });
|
||||
$.cookie('load_type', 'create', { path: '/' });
|
||||
location.reload();
|
||||
},
|
||||
error() {
|
||||
@@ -729,8 +731,10 @@ $(document).on('click', '.push_item', function () {
|
||||
closeLoading?.()
|
||||
cocoMessage.success('更新成功!');
|
||||
const currentScrollTop = window.scrollY || document.documentElement.scrollTop;
|
||||
$.cookie('scrollParam', currentScrollTop, { path: '/', domain: 'anian.cc' });
|
||||
$.cookie('load_type', 'update', { path: '/', domain: 'anian.cc' });
|
||||
// $.cookie('scrollParam', currentScrollTop, { path: '/', domain: 'anian.cc' });
|
||||
// $.cookie('load_type', 'update', { path: '/', domain: 'anian.cc' });
|
||||
$.cookie('scrollParam', currentScrollTop, { path: '/' });
|
||||
$.cookie('load_type', 'update', { path: '/' });
|
||||
location.reload();
|
||||
},
|
||||
error() {
|
||||
@@ -929,7 +933,8 @@ $(document).on('click', '.moment_cat_nav ul li a', function () {
|
||||
history.pushState({ url: cat }, '', '/');
|
||||
}
|
||||
if (!$.cookie('scrollParam')) {
|
||||
$.removeCookie('page', { path: '/', domain: 'anian.cc' });
|
||||
// $.removeCookie('page', { path: '/', domain: 'anian.cc' });
|
||||
$.removeCookie('page', { path: '/' });
|
||||
}
|
||||
if (window._tagSwitchCallback) {
|
||||
window._tagSwitchCallback.resolve(); // 标记成功
|
||||
@@ -958,6 +963,9 @@ $(document).on('click', '.moment_cat_nav ul li a', function () {
|
||||
// ajax分类筛选朋友圈
|
||||
$(document).on('click', '.friends_cat_nav .cat-link', function () {
|
||||
var $this = $(this);
|
||||
if ($this.closest('.douban_cat_nav').length > 0) {
|
||||
return;
|
||||
}
|
||||
if ($this.hasClass('disabled')) {
|
||||
return false;
|
||||
}
|
||||
@@ -979,6 +987,10 @@ $(document).on('click', '.friends_cat_nav .cat-link', function () {
|
||||
|
||||
// 获取目标 URL(注意这里用的是 data-href)
|
||||
var url = $this.attr('data-href');
|
||||
if (!url) {
|
||||
$('.friends_cat_nav .cat-link').removeClass('disabled');
|
||||
return;
|
||||
}
|
||||
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
@@ -1020,12 +1032,15 @@ $(document).on('click', '.friends_cat_nav .cat-link', function () {
|
||||
initializeMomentFold();
|
||||
|
||||
// 更新浏览器历史状态
|
||||
url = url.replace('author', 'tag');
|
||||
history.pushState({ url: url }, '', url);
|
||||
if (typeof url === 'string') {
|
||||
url = url.replace('author', 'tag');
|
||||
history.pushState({ url: url }, '', url);
|
||||
}
|
||||
|
||||
// 清除分页 cookie(保持原样)
|
||||
if (!$.cookie('scrollParam')) {
|
||||
$.removeCookie('page', { path: '/', domain: 'anian.cc' });
|
||||
// $.removeCookie('page', { path: '/', domain: 'anian.cc' });
|
||||
$.removeCookie('page', { path: '/' });
|
||||
}
|
||||
|
||||
if (window._tagSwitchCallback) {
|
||||
@@ -1087,7 +1102,8 @@ $(document).on('click', '#t_pagination a', function () {
|
||||
initAgree();
|
||||
lazyLoadInstance.update();
|
||||
initializeMomentFold();
|
||||
$.cookie('page', currentPage, { path: '/', domain: 'anian.cc' });
|
||||
// $.cookie('page', currentPage, { path: '/', domain: 'anian.cc' });
|
||||
$.cookie('page', currentPage, { path: '/' });
|
||||
} else {
|
||||
$('#t_pagination a').hide();
|
||||
}
|
||||
@@ -1176,7 +1192,8 @@ $(document).ready(function () {
|
||||
history.pushState({ path: displayUrl }, '', displayUrl);
|
||||
|
||||
if (!$.cookie('scrollParam')) {
|
||||
$.removeCookie('page', { path: '/', domain: 'anian.cc' });
|
||||
// $.removeCookie('page', { path: '/', domain: 'anian.cc' });
|
||||
$.removeCookie('page', { path: '/' });
|
||||
}
|
||||
if (window._tagSwitchCallback) {
|
||||
window._tagSwitchCallback.resolve(); // 标记成功
|
||||
@@ -1237,7 +1254,8 @@ $(document).on('click', '#p_pagination a', function () {
|
||||
$body.animate({ scrollTop: targetOffsetTop - 358 }, 500);
|
||||
} else window.forceStopLoading = true;
|
||||
pix.initGalleryPhotos();
|
||||
$.cookie('page', currentPage, { path: '/', domain: 'anian.cc' });
|
||||
// $.cookie('page', currentPage, { path: '/', domain: 'anian.cc' });
|
||||
$.cookie('page', currentPage, { path: '/' });
|
||||
} else {
|
||||
$('#p_pagination a').hide();
|
||||
}
|
||||
@@ -1454,7 +1472,8 @@ $(document).on('click', '.posts_cat_nav ul li a', function (e) {
|
||||
}
|
||||
history.pushState({ url: newUrl }, '', newUrl);
|
||||
if (!$.cookie('scrollParam')) {
|
||||
$.removeCookie('page', { path: '/', domain: 'anian.cc' });
|
||||
// $.removeCookie('page', { path: '/', domain: 'anian.cc' });
|
||||
$.removeCookie('page', { path: '/'});
|
||||
}
|
||||
if (window._tagSwitchCallback) {
|
||||
window._tagSwitchCallback.resolve(); // 标记成功
|
||||
@@ -1517,7 +1536,8 @@ $('body').on('click', '#pagination a', function () {
|
||||
} else window.forceStopLoading = true;
|
||||
initAgree()
|
||||
lazyLoadInstance.update();
|
||||
$.cookie('page', currentPage, { path: '/', domain: 'anian.cc' });
|
||||
// $.cookie('page', currentPage, { path: '/', domain: 'anian.cc' });
|
||||
$.cookie('page', currentPage, { path: '/' });
|
||||
} else {
|
||||
$("#pagination a").hide();
|
||||
}
|
||||
@@ -1572,7 +1592,8 @@ $('body').on('click', '.arc_pagenav a', function () {
|
||||
} else window.forceStopLoading = true;
|
||||
initAgree()
|
||||
lazyLoadInstance.update();
|
||||
$.cookie('page', currentPage, { path: '/', domain: 'anian.cc' });
|
||||
// $.cookie('page', currentPage, { path: '/', domain: 'anian.cc' });
|
||||
$.cookie('page', currentPage, { path: '/' });
|
||||
},
|
||||
error: function () {
|
||||
$pagingArea.html(originalPagingHtml);
|
||||
@@ -1680,7 +1701,8 @@ $('body').on('click', '.s_set_box a', function () {
|
||||
var type = $(this).attr('data');
|
||||
$(this).addClass('active').siblings('a').removeClass('active');
|
||||
$('form#index_search input[type="hidden"]').val(type);
|
||||
$.cookie('s_type', type, { expires: 30, path: '/', domain: 'anian.cc' });
|
||||
// $.cookie('s_type', type, { expires: 30, path: '/', domain: 'anian.cc' });
|
||||
$.cookie('s_type', type, { expires: 30, path: '/' });
|
||||
});
|
||||
|
||||
$('body').on('click', '.top_s_box a', function () {
|
||||
@@ -1695,9 +1717,11 @@ $('body').on('click', '.top_s_box a', function () {
|
||||
$('body').on('click', '.t_dark a', function () {
|
||||
var t = $('html');
|
||||
if (t.hasClass('dark')) {
|
||||
$.cookie('dark', 'normal', { path: '/', domain: 'anian.cc', expires: 30 });
|
||||
// $.cookie('dark', 'normal', { path: '/', domain: 'anian.cc', expires: 30 });
|
||||
$.cookie('dark', 'normal', { path: '/', expires: 30 });
|
||||
} else {
|
||||
$.cookie('dark', 'dark', { path: '/', domain: 'anian.cc', expires: 30 });
|
||||
// $.cookie('dark', 'dark', { path: '/', domain: 'anian.cc', expires: 30 });
|
||||
$.cookie('dark', 'dark', { path: '/', expires: 30 });
|
||||
}
|
||||
t.toggleClass('dark');
|
||||
|
||||
@@ -1742,22 +1766,31 @@ $('body').on('click', '.m_offcanvas', function () {
|
||||
});
|
||||
|
||||
// 刷新内容(兼容一言和今日诗词API)
|
||||
let yiyanLoading = false; // 标志是否正在请求
|
||||
$('body').on('click', '.yiyan_box .change', function () {
|
||||
// 若请求还未恢复消息,直接return
|
||||
if (yiyanLoading) {
|
||||
return;
|
||||
}
|
||||
yiyanLoading = true; // 设置请求开始标志
|
||||
var url = Theme.widget_yiyan.api || 'https://v1.hitokoto.cn';
|
||||
fetch(url)
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
const targetElement = document.querySelector('.yiyan_box p');
|
||||
if (url.includes('jinrishici.com')) {
|
||||
// 今日诗词API处理逻辑:标题添加《》
|
||||
if (url.includes('api.anian.cc')) {
|
||||
// 新增处理逻辑
|
||||
targetElement.innerText = data.content;
|
||||
targetElement.setAttribute("uk-tooltip", `《${data.origin}》${data.author}`);
|
||||
targetElement.setAttribute("uk-tooltip", `《${data.title}》${data.author}`);
|
||||
} else {
|
||||
// 原有一言API处理逻辑
|
||||
targetElement.innerText = data.hitokoto;
|
||||
targetElement.setAttribute("uk-tooltip", data.from);
|
||||
}
|
||||
})
|
||||
.finally(() => {
|
||||
yiyanLoading = false; // 请求完成,重置标志
|
||||
})
|
||||
});
|
||||
|
||||
$('.yiyan_box .change').click();
|
||||
@@ -1789,7 +1822,8 @@ if (Theme.pjax) {
|
||||
initBlog();
|
||||
refreshCommentWidget();
|
||||
NProgress.done();
|
||||
$.removeCookie('page', { path: '/', domain: 'anian.cc' });
|
||||
// $.removeCookie('page', { path: '/', domain: 'anian.cc' });
|
||||
$.removeCookie('page', { path: '/' });
|
||||
})
|
||||
}
|
||||
|
||||
@@ -2270,21 +2304,18 @@ function showCenterImage(imageUrl) {
|
||||
// 侧边栏农历信息显示函数
|
||||
function anian_renderLunarUI() {
|
||||
const textEl = document.getElementById('anianLunarText');
|
||||
const cookieName = 'anian_lunar_info';
|
||||
const defaultText = '一日不见如隔三秋';
|
||||
const maxRetries = 20;
|
||||
|
||||
if (!textEl) return;
|
||||
|
||||
const doRender = (data) => {
|
||||
if (!data) {
|
||||
textEl.innerHTML = defaultText;
|
||||
textEl.innerHTML = '一日不见 · 如隔三秋';
|
||||
return;
|
||||
}
|
||||
|
||||
const { ganzhiYear = '', lunarMonth = '', lunarDay = '', jieqi = '', jijie = '', traditionalFestival = '' } = data;
|
||||
const { ganzhiYear = '', lunarMonth = '', lunarDay = '', jieqi = '', jijie = '', traditionalFestival = '', shengxiao = '' } = data;
|
||||
|
||||
let text = `${ganzhiYear}年${lunarMonth}${lunarDay}`;
|
||||
let text = `${ganzhiYear}${shengxiao}年 · ${lunarMonth}月${lunarDay}`;
|
||||
const extra = [];
|
||||
if (jieqi) extra.push(jieqi);
|
||||
if (traditionalFestival) extra.push(traditionalFestival);
|
||||
@@ -2299,13 +2330,13 @@ function anian_renderLunarUI() {
|
||||
const tryRender = (attempt) => {
|
||||
let data = null;
|
||||
try {
|
||||
const cookieVal = anian_getCookie(cookieName);
|
||||
const cookieVal = $.cookie('anian_lunar_info');
|
||||
if (cookieVal) data = JSON.parse(cookieVal);
|
||||
} catch (_) { }
|
||||
|
||||
if (data) {
|
||||
doRender(data);
|
||||
} else if (attempt < maxRetries) {
|
||||
} else if (attempt < 20) {
|
||||
setTimeout(() => tryRender(attempt + 1), 500);
|
||||
} else {
|
||||
doRender(null);
|
||||
@@ -2513,7 +2544,8 @@ function markAsRead(combinedDateStr) {
|
||||
const noticeBtn = document.getElementById('noticeBtn');
|
||||
if (!noticeBubble || !noticeBtn) return;
|
||||
|
||||
$.cookie('latest_notice_date', combinedDateStr, { path: '/', domain: 'anian.cc', expires: 365 });
|
||||
// $.cookie('latest_notice_date', combinedDateStr, { path: '/', domain: 'anian.cc', expires: 365 });
|
||||
$.cookie('latest_notice_date', combinedDateStr, { path: '/', expires: 365 });
|
||||
noticeBubble.classList.remove('show');
|
||||
noticeBtn.classList.remove('has-notice');
|
||||
}
|
||||
@@ -2587,78 +2619,131 @@ function anianxSpeedMoveArrow(btn) {
|
||||
anianxSpeedBubble.style.setProperty("--anianx-arrow", center + "px");
|
||||
}
|
||||
|
||||
if (location.hostname === "anian.cc") {
|
||||
anianxSpeedMainLine.classList.add("anianx-fixed");
|
||||
anianxSpeedBubbleText.classList.remove("anianx-loading");
|
||||
anianxSpeedBubbleText.innerText = "当前为主线路";
|
||||
anianxSpeedMoveArrow(anianxSpeedMainLine);
|
||||
} else if (location.hostname === "www.anian.cc") {
|
||||
anianxSpeedSubLine.classList.add("anianx-fixed");
|
||||
anianxSpeedBubbleText.classList.remove("anianx-loading");
|
||||
anianxSpeedBubbleText.innerText = "当前为副线路";
|
||||
anianxSpeedMoveArrow(anianxSpeedSubLine);
|
||||
} else {
|
||||
anianxSpeedBubbleText.classList.remove("anianx-loading");
|
||||
anianxSpeedBubbleText.innerText = "当前为测试线路";
|
||||
anianxSpeedMoveArrow(anianxSpeedTestLine);
|
||||
function anianxSpeedSetTooltip(btn, text) {
|
||||
if (!btn) return;
|
||||
btn.setAttribute("title", text);
|
||||
btn.setAttribute("uk-tooltip", "pos: top; offset: 2;");
|
||||
}
|
||||
|
||||
anianxSpeedMainLine.addEventListener("click", () => {
|
||||
if (anianxSpeedGlobalLock) return;
|
||||
anianxSpeedMoveArrow(anianxSpeedMainLine);
|
||||
anianxSpeedGlobalLock = true;
|
||||
if (anianxSpeedMainLine.classList.contains("anianx-fixed")) {
|
||||
anianxSpeedBubbleText.classList.remove("anianx-loading");
|
||||
anianxSpeedBubbleText.innerText = "当前为主线路";
|
||||
anianxSpeedGlobalLock = false;
|
||||
} else {
|
||||
anianxSpeedBubbleText.classList.add("anianx-loading");
|
||||
anianxSpeedBubbleText.innerText = "正在切换至主线路";
|
||||
anianxSpeedMoveArrow(anianxSpeedMainLine);
|
||||
const currentScrollTop = window.scrollY || document.documentElement.scrollTop;
|
||||
$.cookie('scrollParam', currentScrollTop, { path: '/', domain: 'anian.cc' });
|
||||
const finalUrl = anianxSpeedMainLine.dataset.anianxHref + location.pathname +
|
||||
location.search + location.hash;
|
||||
location.href = finalUrl;
|
||||
}
|
||||
});
|
||||
function anianxSpeedClearTooltip(btn) {
|
||||
if (!btn) return;
|
||||
btn.removeAttribute("title");
|
||||
btn.removeAttribute("uk-tooltip");
|
||||
}
|
||||
|
||||
anianxSpeedSubLine.addEventListener("click", () => {
|
||||
if (anianxSpeedGlobalLock) return;
|
||||
anianxSpeedMoveArrow(anianxSpeedSubLine);
|
||||
anianxSpeedGlobalLock = true;
|
||||
if (anianxSpeedSubLine.classList.contains("anianx-fixed")) {
|
||||
anianxSpeedBubbleText.classList.remove("anianx-loading");
|
||||
anianxSpeedBubbleText.innerText = "当前为副线路";
|
||||
anianxSpeedGlobalLock = false;
|
||||
} else {
|
||||
anianxSpeedBubbleText.classList.add("anianx-loading");
|
||||
anianxSpeedBubbleText.innerText = "正在切换至副线路";
|
||||
anianxSpeedMoveArrow(anianxSpeedSubLine);
|
||||
const currentScrollTop = window.scrollY || document.documentElement.scrollTop;
|
||||
const baseUrl = anianxSpeedSubLine.dataset.anianxHref + location.pathname + location.search;
|
||||
$.cookie('scrollParam', currentScrollTop, { path: '/', domain: 'anian.cc' });
|
||||
const finalUrl = baseUrl + location.hash;
|
||||
location.href = finalUrl;
|
||||
}
|
||||
});
|
||||
function anianxSpeedFetchLuckWithTimeout(timeout) {
|
||||
const controller = new AbortController();
|
||||
const timer = setTimeout(() => controller.abort(), timeout);
|
||||
|
||||
anianxSpeedTestLine.addEventListener("click", () => {
|
||||
if (anianxSpeedGlobalLock) return;
|
||||
anianxSpeedMoveArrow(anianxSpeedTestLine);
|
||||
anianxSpeedGlobalLock = true;
|
||||
anianxSpeedBubbleText.classList.add("anianx-loading");
|
||||
anianxSpeedBubbleText.innerText = "测速中";
|
||||
anianxSpeedTestWithTimeout(7500).then(result => {
|
||||
anianxSpeedBubbleText.classList.remove("anianx-loading");
|
||||
anianxSpeedBubbleText.innerText = result;
|
||||
}).catch(() => {
|
||||
anianxSpeedBubbleText.classList.remove("anianx-loading");
|
||||
anianxSpeedBubbleText.innerText = "请检查网络或切换线路";
|
||||
return fetch("https://api.anian.cc/luck", {
|
||||
signal: controller.signal
|
||||
}).then(response => {
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP ${response.status}`);
|
||||
}
|
||||
return response.json();
|
||||
}).finally(() => {
|
||||
anianxSpeedGlobalLock = false;
|
||||
clearTimeout(timer);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function anianxSpeedBuildLuckTooltip(idText, poetryText, meaningText, explanationText) {
|
||||
const signText = idText ? `第${idText}签。` : "第?签";
|
||||
return [
|
||||
signText,
|
||||
poetryText || "",
|
||||
meaningText || "",
|
||||
explanationText || ""
|
||||
].join("||  ");
|
||||
}
|
||||
|
||||
if (anianxSpeedMainLine) {
|
||||
anianxSpeedMainLine.addEventListener("click", () => {
|
||||
if (anianxSpeedGlobalLock) return;
|
||||
anianxSpeedMoveArrow(anianxSpeedMainLine);
|
||||
anianxSpeedGlobalLock = true;
|
||||
anianxSpeedClearTooltip(anianxSpeedBubbleText);
|
||||
anianxSpeedBubbleText.classList.add("anianx-loading");
|
||||
anianxSpeedBubbleText.innerText = "抽取中";
|
||||
|
||||
const request = anianxSpeedFetchLuckWithTimeout(5000);
|
||||
|
||||
request.then(data => {
|
||||
const result = data || {};
|
||||
const typeText = result.type || "";
|
||||
const titleText = result.title || "";
|
||||
const idText = result.id || "";
|
||||
const explanationText = result.explanation || "";
|
||||
const poetryText = result.poetry || "";
|
||||
const meaningText = result.meaning || "";
|
||||
anianxSpeedBubbleText.innerText = [typeText, titleText].filter(Boolean).join(" · ") || "抽取成功";
|
||||
anianxSpeedSetTooltip(anianxSpeedBubbleText, anianxSpeedBuildLuckTooltip(idText, poetryText, meaningText, explanationText));
|
||||
}).catch(() => {
|
||||
anianxSpeedClearTooltip(anianxSpeedBubbleText);
|
||||
anianxSpeedBubbleText.innerText = "失败:超时或发生错误";
|
||||
}).finally(() => {
|
||||
anianxSpeedBubbleText.classList.remove("anianx-loading");
|
||||
anianxSpeedGlobalLock = false;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
if (anianxSpeedTestLine) {
|
||||
anianxSpeedTestLine.addEventListener("click", () => {
|
||||
if (anianxSpeedGlobalLock) return;
|
||||
anianxSpeedMoveArrow(anianxSpeedTestLine);
|
||||
anianxSpeedGlobalLock = true;
|
||||
anianxSpeedClearTooltip(anianxSpeedBubbleText);
|
||||
anianxSpeedBubbleText.classList.add("anianx-loading");
|
||||
anianxSpeedBubbleText.innerText = "测速中";
|
||||
Promise.all([
|
||||
anianxSpeedTestWithTimeout(10000),
|
||||
anianxSpeedFetchIpWithTimeout(5000)
|
||||
]).then(([speedResult, ipResult]) => {
|
||||
anianxSpeedBubbleText.classList.remove("anianx-loading");
|
||||
anianxSpeedBubbleText.innerText = speedResult;
|
||||
// 设置tooltip显示IP地址
|
||||
const tooltipText = ipResult ? `IP地址: ${ipResult}` : "IP地址获取失败";
|
||||
anianxSpeedSetTooltip(anianxSpeedBubbleText, tooltipText);
|
||||
}).catch(() => {
|
||||
anianxSpeedClearTooltip(anianxSpeedBubbleText);
|
||||
anianxSpeedBubbleText.classList.remove("anianx-loading");
|
||||
anianxSpeedBubbleText.innerText = "失败:超时或发生错误";
|
||||
}).finally(() => {
|
||||
anianxSpeedGlobalLock = false;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
if (anianxSpeedSubLine) {
|
||||
anianxSpeedSubLine.addEventListener("click", () => {
|
||||
if (anianxSpeedGlobalLock) return;
|
||||
anianxSpeedMoveArrow(anianxSpeedSubLine);
|
||||
anianxSpeedGlobalLock = true;
|
||||
anianxSpeedClearTooltip(anianxSpeedBubbleText);
|
||||
anianxSpeedBubbleText.classList.add("anianx-loading");
|
||||
anianxSpeedBubbleText.innerText = "加载中";
|
||||
|
||||
anianxSpeedFetchXiehouyuWithTimeout(5000).then(data => {
|
||||
anianxSpeedBubbleText.classList.remove("anianx-loading");
|
||||
if (data && data.riddle) {
|
||||
anianxSpeedBubbleText.innerText = data.riddle;
|
||||
// 设置tooltip显示答案
|
||||
const tooltipText = data.answer || "暂无答案";
|
||||
anianxSpeedSetTooltip(anianxSpeedBubbleText, tooltipText);
|
||||
} else {
|
||||
anianxSpeedClearTooltip(anianxSpeedBubbleText);
|
||||
anianxSpeedBubbleText.innerText = "失败:超时或发生错误";
|
||||
}
|
||||
}).catch(() => {
|
||||
anianxSpeedClearTooltip(anianxSpeedBubbleText);
|
||||
anianxSpeedBubbleText.classList.remove("anianx-loading");
|
||||
anianxSpeedBubbleText.innerText = "失败:超时或发生错误";
|
||||
}).finally(() => {
|
||||
anianxSpeedGlobalLock = false;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function anianxSpeedTestWithTimeout(timeout) {
|
||||
const controller = new AbortController();
|
||||
@@ -2674,7 +2759,7 @@ function anianxSpeedTestWithTimeout(timeout) {
|
||||
const sec = (Date.now() - t0) / 1000;
|
||||
const mbps = ((size * 8) / (sec * 1024 * 1024)).toFixed(2);
|
||||
clearTimeout(timer);
|
||||
resolve("正常:" + mbps + " Mbps");
|
||||
resolve("访问速率:" + mbps + " Mbps");
|
||||
} catch (e) {
|
||||
clearTimeout(timer);
|
||||
reject(e);
|
||||
@@ -2682,6 +2767,46 @@ function anianxSpeedTestWithTimeout(timeout) {
|
||||
});
|
||||
}
|
||||
|
||||
function anianxSpeedFetchIpWithTimeout(timeout) {
|
||||
const controller = new AbortController();
|
||||
const timer = setTimeout(() => controller.abort(), timeout);
|
||||
|
||||
return fetch("https://api.anian.cc/ip", {
|
||||
signal: controller.signal
|
||||
}).then(response => {
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP ${response.status}`);
|
||||
}
|
||||
return response.json();
|
||||
}).then(data => {
|
||||
clearTimeout(timer);
|
||||
return data.ip || "";
|
||||
}).catch(e => {
|
||||
clearTimeout(timer);
|
||||
return "";
|
||||
});
|
||||
}
|
||||
|
||||
function anianxSpeedFetchXiehouyuWithTimeout(timeout) {
|
||||
const controller = new AbortController();
|
||||
const timer = setTimeout(() => controller.abort(), timeout);
|
||||
|
||||
return fetch("https://api.anian.cc/xiehouyu", {
|
||||
signal: controller.signal
|
||||
}).then(response => {
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP ${response.status}`);
|
||||
}
|
||||
return response.json();
|
||||
}).then(data => {
|
||||
clearTimeout(timer);
|
||||
return data;
|
||||
}).catch(e => {
|
||||
clearTimeout(timer);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function initTagSwitch() {
|
||||
return new Promise((resolve, reject) => {
|
||||
@@ -2714,6 +2839,11 @@ function initTagSwitch() {
|
||||
const linkText = $(this).clone().find('span').remove().end().text().trim();
|
||||
return linkText === activeTag;
|
||||
});
|
||||
} else if (pathname === '/douban') {
|
||||
targetLink = $('.douban_cat_nav ul li a').filter(function () {
|
||||
const linkText = $(this).clone().find('span').remove().end().text().trim();
|
||||
return linkText === activeTag;
|
||||
});
|
||||
}
|
||||
|
||||
if (targetLink.length > 0) {
|
||||
@@ -2731,6 +2861,8 @@ window.loadMoreTimeout = false;
|
||||
function loadMultiplePages(pageCount) {
|
||||
return new Promise((resolve) => {
|
||||
let loadedCount = 0;
|
||||
const bootstrapStartTime = Date.now();
|
||||
const bootstrapTimeout = 10000;
|
||||
window.forceStopLoading = false; // 每次启动重置标志位
|
||||
|
||||
const getCurrentBtn = () => {
|
||||
@@ -2749,6 +2881,11 @@ function loadMultiplePages(pageCount) {
|
||||
|
||||
const $btn = getCurrentBtn();
|
||||
if (!$btn || !$btn.length) {
|
||||
// 慢网下分页按钮可能尚未渲染,短暂等待后再尝试
|
||||
if (Date.now() - bootstrapStartTime < bootstrapTimeout) {
|
||||
setTimeout(loadNext, 120);
|
||||
return;
|
||||
}
|
||||
resolve();
|
||||
return;
|
||||
}
|
||||
@@ -2757,6 +2894,7 @@ function loadMultiplePages(pageCount) {
|
||||
const oldHref = $btn.attr('data');
|
||||
const pageStartTime = Date.now();
|
||||
$btn.trigger('click'); // 加载更多
|
||||
// console.log(`正在加载第 ${loadedCount + 1} 页,URL: ${oldHref}`);
|
||||
|
||||
const waitInterval = setInterval(() => {
|
||||
const now = Date.now();
|
||||
@@ -2798,44 +2936,54 @@ function initjump() {
|
||||
const page = $.cookie('page');
|
||||
const scrollParam = $.cookie('scrollParam');
|
||||
const loadType = $.cookie('load_type')
|
||||
$.removeCookie('scrollParam', { path: '/', domain: 'anian.cc' });
|
||||
$.removeCookie('page', { path: '/', domain: 'anian.cc' });
|
||||
$.removeCookie('load_type', { path: '/', domain: 'anian.cc' });
|
||||
const hasValidPage = page && !isNaN(page);
|
||||
const hasValidScroll = scrollParam && !isNaN(scrollParam);
|
||||
const shouldLoadAndScroll = hasValidPage && hasValidScroll;
|
||||
// $.removeCookie('scrollParam', { path: '/', domain: 'anian.cc' });
|
||||
// $.removeCookie('page', { path: '/', domain: 'anian.cc' });
|
||||
// $.removeCookie('load_type', { path: '/', domain: 'anian.cc' });
|
||||
$.removeCookie('scrollParam', { path: '/' });
|
||||
$.removeCookie('page', { path: '/' });
|
||||
$.removeCookie('load_type', { path: '/' });
|
||||
window.scroll_param = scrollParam;
|
||||
if (scrollParam && !isNaN(scrollParam)) {
|
||||
if (hasValidScroll) {
|
||||
closeLoading = cocoMessage.loading('自动恢复原内容中...');
|
||||
}
|
||||
initTagSwitch().then(() => {
|
||||
const loadPageTask = () => {
|
||||
if (page && !isNaN(page)) {
|
||||
if (shouldLoadAndScroll) {
|
||||
const targetPage = Number(page) - 1;
|
||||
return loadMultiplePages(targetPage);
|
||||
}
|
||||
return Promise.resolve();
|
||||
};
|
||||
if (scrollParam && !isNaN(scrollParam)) {
|
||||
loadPageTask().then(() => {
|
||||
closeLoading?.()
|
||||
loadPageTask().then(() => {
|
||||
closeLoading?.()
|
||||
if (hasValidScroll) {
|
||||
const recordScroll = Number(scrollParam);
|
||||
const maxScroll = document.documentElement.scrollHeight - window.innerHeight;
|
||||
const scrollDistance = Math.min(recordScroll, maxScroll);
|
||||
$('html, body').animate({ scrollTop: scrollDistance }, 500);
|
||||
if (recordScroll > maxScroll && (recordScroll - maxScroll) > 200) {
|
||||
cocoMessage.warning('请手动加载原线路内容');
|
||||
} else if (loadType === 'create') {
|
||||
cocoMessage.success('发布成功!');
|
||||
} else if (loadType === 'update') {
|
||||
cocoMessage.success('更新成功!');
|
||||
} else if (loadType === 'login') {
|
||||
cocoMessage.success('登录成功!');
|
||||
} else if (loadType === 'logout') {
|
||||
cocoMessage.success('登出成功!');
|
||||
} else {
|
||||
const msg = location.hostname === "anian.cc" ? '主线路' : (location.hostname === "www.anian.cc" ? '副线路' : '测试线路');
|
||||
cocoMessage.success('已成功切换至' + msg);
|
||||
switch (loadType) {
|
||||
case 'create':
|
||||
cocoMessage.success('发布成功!');
|
||||
break;
|
||||
case 'update':
|
||||
cocoMessage.success('更新成功!');
|
||||
break;
|
||||
case 'login':
|
||||
cocoMessage.success('登录成功!');
|
||||
break;
|
||||
case 'logout':
|
||||
cocoMessage.success('登出成功!');
|
||||
break;
|
||||
// default:
|
||||
// const line_msg = location.hostname === "anian.cc" ? '主线路' : (location.hostname === "www.anian.cc" ? '副线路' : '测试线路');
|
||||
// cocoMessage.success('已成功切换至' + line_msg);
|
||||
}
|
||||
}).catch(() => closeLoading?.());
|
||||
}
|
||||
if (recordScroll > maxScroll && (recordScroll - maxScroll) > 200) { cocoMessage.warning('请手动加载原内容'); }
|
||||
}
|
||||
}).catch(() => closeLoading?.());
|
||||
}).catch(() => closeLoading?.());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user