重写目录样式;适配新域名

This commit is contained in:
anian
2026-07-18 00:48:46 +08:00
parent 048e4336d1
commit 1953fa86c8
15 changed files with 380 additions and 151 deletions
+102 -62
View File
@@ -1697,7 +1697,7 @@ $('body').on('click', '.yiyan_box .change', function () {
.then(response => response.json())
.then(data => {
const targetElement = document.querySelector('.yiyan_box p');
if (url.includes('api.anian.cc')) {
if (url.includes('api.anian.net')) {
// 新增处理逻辑
targetElement.innerText = data.content || '一日不见如隔三秋';
const tooltipTitle = data.title || '失败:超时或发生错误';
@@ -1842,91 +1842,134 @@ if (currentElement) {
});
}
$('body').on('click', '.listree-btn', function () {
"目录[+]" == $(".listree-btn").text() ? $(".listree-btn").attr("title", "收起").text("目录[-]").parent().next().show() : $(".listree-btn").attr("title", "展开").text("目录[+]").parent().next().hide();
return !1
$('body').on('click', '.listree-btn', function (event) {
event.preventDefault();
setListreeOpen(!$('.listree-box').hasClass('is-open'));
return false;
});
$(document).on('click.listreeOutside', function (event) {
if (!$('body').hasClass('toc-open')) return;
if ($(event.target).closest('.listree-box, .toc_nav').length) return;
setListreeOpen(false);
});
$(document).on('keydown.listree', function (event) {
if (event.key === 'Escape') {
setListreeOpen(false);
}
});
function resetListree() {
$('body').removeClass('toc-ready toc-open');
$('.toc_nav').attr('aria-hidden', 'true');
$('.listree-btn')
.removeClass('is-active')
.attr({
'title': '展开目录',
'aria-label': '展开目录',
'aria-expanded': 'false'
});
$('.listree-box')
.removeClass('is-open')
.attr('aria-hidden', 'true');
}
function setListreeOpen(open) {
if (open && !$('body').hasClass('toc-ready')) return;
$('body').toggleClass('toc-open', open);
$('.listree-box')
.toggleClass('is-open', open)
.attr('aria-hidden', open ? 'false' : 'true');
$('.listree-btn')
.toggleClass('is-active', open)
.attr({
'title': open ? '收起目录' : '展开目录',
'aria-label': open ? '收起目录' : '展开目录',
'aria-expanded': open ? 'true' : 'false'
});
}
// toc
function autotree() {
$(document).ready(function () {
$('.listree-titles').html('<a class="listree-btn" title="展开">目录[+]</a>')
$('#listree-ol').empty();
$("#listree-ol").css("display", "none")
resetListree();
$('#listree-ol').empty().hide();
// 获取所有标题元素
var headings = document.querySelectorAll('.post-single .single-content *:is(h1, h2, h3, h4, h5, h6)');
// 为标题元素添加 listree-list 类,并修改 id
headings.forEach(function (heading, index) {
heading.classList.add('listree-list');
heading.id = 'listree-list' + index;
});
// 创建一个空的目录列表
var tocList = document.querySelector('#listree-ol');
if (!tocList || headings.length < 1) {
$(window).off('scroll.listree resize.listree');
return;
}
// 保存每个级别的父列表项
var parentItems = {};
// 遍历每个标题元素
headings.forEach(function (heading, index) {
// 创建列表项
var listItem = document.createElement('li');
heading.classList.add('listree-list');
heading.id = 'listree-list' + index;
// 创建标题链接
var level = parseInt(heading.tagName.slice(1));
var listItem = document.createElement('li');
var link = document.createElement('a');
// 直接设置链接的href为标题元素的id
var parentItem = null;
listItem.setAttribute('data-level', level);
listItem.style.setProperty('--toc-index', index);
link.href = '#listree-list' + index;
link.classList.add('toc-link', 'node-name--' + heading.tagName);
link.textContent = heading.textContent.trim();
// 将标题链接添加到列表项中
listItem.appendChild(link);
// 获取当前标题级别
var level = parseInt(heading.tagName.slice(1));
// 查找当前标题的父级列表项
var parentItem = parentItems[level - 1];
// 如果存在父级列表项,则将当前列表项作为其子项
if (parentItem) {
// 如果父级列表项还没有子列表,则创建一个子列表
if (!parentItem.querySelector('ul')) {
var subList = document.createElement('ul');
parentItem.appendChild(subList);
for (var parentLevel = level - 1; parentLevel >= 1; parentLevel--) {
if (parentItems[parentLevel]) {
parentItem = parentItems[parentLevel];
break;
}
}
// 将当前列表项添加到父级列表的子列表中
if (parentItem) {
if (!parentItem.querySelector('ul')) {
parentItem.appendChild(document.createElement('ul'));
}
parentItem.querySelector('ul').appendChild(listItem);
} else {
// 如果不存在父级列表项,则将当前列表项直接添加到根列表中
tocList.appendChild(listItem);
}
// 更新当前级别的父列表项为当前列表项
parentItems[level] = listItem;
Object.keys(parentItems).forEach(function (key) {
if (parseInt(key) > level) {
delete parentItems[key];
}
});
});
$('body').addClass('toc-ready');
$('.toc_nav').attr('aria-hidden', 'false');
$('#listree-ol').show();
$(".listree-btn").click(function () {
"目录[+]" == $(".listree-btn").text() ? $(".listree-btn").attr("title", "收起").text("目录[-]").parent().next().show() : $(".listree-btn").attr("title", "展开").text("目录[+]").parent().next().hide();
return !1
});
$("a.toc-link").click(function (event) {
$('body').off('click.listreeLink', 'a.toc-link').on('click.listreeLink', 'a.toc-link', function (event) {
event.preventDefault();
var targetId = $(this).attr("href");
var $target = $(targetId);
if (!$target.length) return;
$("html, body").animate({
scrollTop: $(targetId).offset().top - 77
}, 800);
scrollTop: $target.offset().top - 77
}, 500);
if (window.innerWidth <= 768) {
setListreeOpen(false);
}
});
// 判断是否存在目录,设置显示或隐藏
if ($('#listree-ol').children().length > 0) {
$(".listree-box").css("display", "block");
} else {
$(".listree-box").css("display", "none");
}
})
jQuery(document).ready(function (f) {
var T = f(".listree-list");
@@ -1935,6 +1978,7 @@ function autotree() {
var b = [];
function Q() {
b = [];
T.each(function () {
var T = f(this).offset();
b.push(Math.floor(T.top))
@@ -1943,16 +1987,11 @@ function autotree() {
function a(T) {
var b = f("#listree-ol li");
var Q = f(".listree-list dt");
if (b.length < 1)
return;
var a = b.outerHeight();
if (!b.eq(T).hasClass("current")) {
b.removeClass("current");
b.eq(T).addClass("current");
Q.animate({
top: a * T + (b.outerHeight() - Q.outerHeight()) / 2 + 1
}, 50)
}
}
@@ -1980,7 +2019,10 @@ function autotree() {
Q();
setTimeout(X, 0);
f(window).on("scroll", X)
f(window).off('scroll.listree resize.listree').on('scroll.listree', X).on('resize.listree', function () {
Q();
X();
})
});
}
@@ -2420,7 +2462,7 @@ function initGreenDigitalClock() {
const COOKIE_EXPIRE_YEARS = 10;
const NOTICE_DETAIL_PATH = '/notice';
const RSS_URLS = [
'https://git.anian.cc/anian/halo-theme-pix/releases.rss',
'https://git.anian.net/anian/halo-theme-pix/releases.rss',
];
async function getAllLatestNoticeDatesFromRSS() {
@@ -2555,7 +2597,7 @@ function anianxSpeedFetchLuckWithTimeout(timeout) {
const controller = new AbortController();
const timer = setTimeout(() => controller.abort(), timeout);
return fetch("https://api.anian.cc/luck/api", {
return fetch("https://api.anian.net/luck/api", {
signal: controller.signal
}).then(response => {
if (!response.ok) {
@@ -2690,7 +2732,7 @@ function anianxSpeedFetchIpWithTimeout(timeout) {
const controller = new AbortController();
const timer = setTimeout(() => controller.abort(), timeout);
return fetch("https://api.anian.cc/ip/api", {
return fetch("https://api.anian.net/ip/api", {
signal: controller.signal
}).then(response => {
if (!response.ok) {
@@ -2732,7 +2774,7 @@ function anianxSpeedFetchXiehouyuWithTimeout(timeout) {
const controller = new AbortController();
const timer = setTimeout(() => controller.abort(), timeout);
return fetch("https://api.anian.cc/riddle/api", {
return fetch("https://api.anian.net/riddle/api", {
signal: controller.signal
}).then(response => {
if (!response.ok) {
@@ -2948,7 +2990,7 @@ async function handleSubscribe(event) {
try {
const res = await fetch(
"https://anian.cc/apis/api.flow.post.kunkunyu.com/v1alpha1/follows/-/submit",
"/apis/api.flow.post.kunkunyu.com/v1alpha1/follows/-/submit",
{
method: "POST",
headers: { "Content-Type": "application/json" },
@@ -3020,5 +3062,3 @@ $(document).ready(function () {
initjump();
});
+2 -2
View File
@@ -42,8 +42,8 @@ $('body').on('click', '.moment_card_type a', function () {
$('body').on('click', '.edit_content .push_card', function () {
var card_url = $('.edit_card_box .edit_content input').val();
var num = $('.card_sortble .moment_card_item').length;
if (num > 2) {
cocoMessage.error('最多插入3个卡片');
if (num > 4) {
cocoMessage.error('最多插入5个卡片');
$('.edit_card_box .edit_content input').val('');
return false;
}