From 061b00fc052be3ecabb384c32f9fc54565c70beb Mon Sep 17 00:00:00 2001 From: anian Date: Wed, 6 May 2026 21:08:35 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84=E8=AF=BE=E5=A4=96=E4=B9=A6?= =?UTF-8?q?=EF=BC=9B=E6=9B=B4=E6=96=B0=E4=BE=A7=E8=BE=B9=E6=A0=8F=EF=BC=9B?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=A8=A1=E6=80=81=E6=A1=86=E3=80=81=E5=88=86?= =?UTF-8?q?=E4=BA=AB=E6=B5=B7=E6=8A=A5=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 5 + embed-code/page/navigator.html | 3 +- embed-code/sidebar/dao-hang.html | 16 +- embed-code/sidebar/nong-li.html | 2 +- embed-code/sidebar/xian-lu.html | 6 +- templates/assets/css/anian.css | 259 +++++++++++++++++- templates/assets/css/main.css | 2 +- templates/assets/js/anian.js | 425 ++++++++++++++++++++++++++++- templates/assets/js/app.js | 388 ++++++++++++++++++-------- templates/assets/js/moment-push.js | 76 +++--- templates/assets/js/poster.js | 98 +++++-- templates/douban.html | 55 ++-- templates/modules/footer.html | 24 +- templates/modules/head.html | 8 +- templates/modules/header.html | 29 +- theme.yaml | 2 +- 16 files changed, 1124 insertions(+), 274 deletions(-) diff --git a/README.md b/README.md index 9e1af02..de323bc 100755 --- a/README.md +++ b/README.md @@ -2,6 +2,11 @@ > 基于原作者v1.2.5代码修改 +#### v1.2.5-6 +1. 重构课外书页面 +2. 音乐、背景、侧边栏等适配新接口(基于API-Python) +3. 修复分享海报空白、模态框失效等异常 + #### v1.2.5-5 1. 朋友圈支持图片显示(需同步更新插件) 2. 手机端底部导航栏新增公告未读提示 diff --git a/embed-code/page/navigator.html b/embed-code/page/navigator.html index a120053..72606a8 100644 --- a/embed-code/page/navigator.html +++ b/embed-code/page/navigator.html @@ -207,7 +207,8 @@ const noticeLink = noticeCard.closest('a'); noticeLink.onclick = function() { - $.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 }); typeof markAsRead === 'function' && markAsRead(combinedDateStr); }; } diff --git a/embed-code/sidebar/dao-hang.html b/embed-code/sidebar/dao-hang.html index b76447a..25f678a 100644 --- a/embed-code/sidebar/dao-hang.html +++ b/embed-code/sidebar/dao-hang.html @@ -1,18 +1,18 @@ \ No newline at end of file diff --git a/embed-code/sidebar/nong-li.html b/embed-code/sidebar/nong-li.html index 90f065c..4590059 100644 --- a/embed-code/sidebar/nong-li.html +++ b/embed-code/sidebar/nong-li.html @@ -1,5 +1,5 @@
- 一日不见如隔三秋 + 一日不见 · 如隔三秋
\ No newline at end of file diff --git a/embed-code/sidebar/xian-lu.html b/embed-code/sidebar/xian-lu.html index 769a958..199e25d 100644 --- a/embed-code/sidebar/xian-lu.html +++ b/embed-code/sidebar/xian-lu.html @@ -1,8 +1,8 @@
- + - -
当前线路检测中
+ +
一日不见 · 如隔三秋
\ No newline at end of file diff --git a/templates/assets/css/anian.css b/templates/assets/css/anian.css index 685e2e2..4225d32 100644 --- a/templates/assets/css/anian.css +++ b/templates/assets/css/anian.css @@ -405,7 +405,7 @@ .moments-title-text { color: #111827; - font-size: 1.125rem; + font-size: 1.1rem; font-weight: 600; line-height: 1.5rem; display: block; @@ -415,7 +415,7 @@ margin-top: 0.5rem; margin-bottom: 0; color: #6b7280; - font-size: 0.875rem; + font-size: 0.9rem; line-height: 1.25rem; } @@ -423,7 +423,7 @@ margin-top: 1rem; display: flex; gap: 0.75rem; - flex-direction: row-reverse; + flex-direction: row; } .moments-btn-confirm { @@ -432,8 +432,8 @@ padding: 0.5rem 1rem; background-color: #dc2626; color: #ffffff; - font-size: 0.875rem; - line-height: 1.5rem; + font-size: 0.9rem; + line-height: 1.3rem; font-weight: 500; justify-content: center; border-radius: 0.375rem; @@ -455,8 +455,8 @@ padding: 0.5rem 1rem; background-color: #ffffff; color: #374151; - font-size: 0.875rem; - line-height: 1.5rem; + font-size: 0.9rem; + line-height: 1.3rem; font-weight: 500; justify-content: center; border-radius: 0.375rem; @@ -582,4 +582,249 @@ transform: translateY(-120px) rotate(-8deg) scale(0.6); filter: blur(3px); } +} + +/* 豆瓣页:默认不显示翻页按钮,避免初始化前出现蓝色链接文本 */ +#douban_pagination { + display: none; + padding: 30px; + text-align: center; + align-items: center; + justify-content: center; + border-top: 1px solid var(--pix-background); +} + +#douban_pagination .post-paging { + display: flex; + align-items: center; + justify-content: center; + min-height: 38px; +} + +#douban_pagination a { + padding: 10px 15px; + background: var(--pix-theme); + color: #fff; + border-radius: 8px; + display: inline-flex; + align-items: center; + justify-content: center; + flex: none; + width: auto; + text-align: center; +} + +#douban_pagination .douban-more-loading { + display: inline-flex; + align-items: center; + justify-content: center; +} + +/* 豆瓣页:内容区域左右间距与分类导航保持一致 */ +.douban_page #douban_item { + padding: 0; + display: grid; + grid-template-columns: repeat(2, minmax(0, 1fr)); + column-gap: 0; + row-gap: 0; + align-items: center; +} + +.douban_page #douban_item .loading_box { + text-align: center; + grid-column: 1 / -1; +} + +.douban_page #douban_item .douban_card_item { + width: 100%; + margin: 0; + padding: 0 40px; + border-right: 1px solid #e5e7eb; + display: flex; + align-items: flex-start; +} + +.douban_page #douban_item .douban_card_item:nth-child(2n) { + border-right: none; +} + +.douban_page #douban_item .douban_card_inner { + display: grid !important; + grid-template-columns: 100px 1fr; + grid-template-rows: auto auto 1fr; + column-gap: 16px; + row-gap: 3px; + padding: 20px 0; + background: transparent; + width: 100%; + align-items: start; +} + +.douban_page #douban_item .douban_media_col { + width: 100px; + display: flex; + flex-direction: column; + justify-content: flex-start; + align-items: center; + grid-column: 1; + grid-row: 2 / 4; +} + + +/* 强制网格单元同高并让卡片内部撑满单元,确保水平分割线对齐 */ +.douban_page #douban_item { + align-items: stretch !important; +} + +.douban_page #douban_item .douban_poster_link, +.douban_page #douban_item .douban_poster_img { + width: 100px; +} + +.douban_page #douban_item .douban_poster_img { + display: block; + height: 140px; + object-fit: cover; + border-radius: 8px; + box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15); + +} + +.douban_page #douban_item .douban_rating_wrap { + display: none; +} + +.douban_page #douban_item .douban_text_col { + display: contents; +} + +.douban_page #douban_item .douban_title_row { + grid-column: 1 / -1; + grid-row: 1; + margin-bottom: 6px; + text-align: left; +} + +.douban_page #douban_item .douban_title_text { + color: #111827; + font-size: 16px; + line-height: 1.35; + font-weight: 650; + text-decoration: none; +} + +.douban_page #douban_item .douban_title_text:hover { + color: var(--pix-theme); +} + +.douban_page #douban_item .douban_sub_meta { + display: flex; + align-items: center; + gap: 0px; + margin-bottom: 6px; + flex-wrap: wrap; + grid-column: 2; + grid-row: 2; + align-self: start; +} + +.douban_page #douban_item .douban_time_text { + display: inline-block; + padding: 3px 8px; + border-radius: 6px; + background: rgba(168, 85, 247, 0.12); + color: #a855f7; + font-size: 12px; + line-height: 1.4; + font-weight: 500; + margin-right: 7px; +} + +.douban_page #douban_item .douban_type_badge { + display: inline-block; + padding: 3px 8px; + border-radius: 6px; + background: rgba(56, 189, 248, 0.14); + color: #0369a1; + font-size: 12px; + line-height: 1.4; + vertical-align: middle; + font-weight: 500; + margin-right: 7px; +} + +.douban_page #douban_item .douban_score_badge { + display: inline-block; + padding: 3px 8px; + border-radius: 6px; + background: rgba(249, 115, 22, 0.14); + color: #ea580c; + font-size: 12px; + line-height: 1.4; + vertical-align: middle; + font-weight: 500; +} + +.douban_page #douban_item .douban_content_box { + color: #374151; + grid-column: 2; + grid-row: 3; + align-self: start; +} + +.douban_page #douban_item .douban_content_main { + margin: 0; + font-size: 14px; + line-height: 1.6; + color: #1f2937; + display: block; + overflow: hidden; + max-height: 89.6px; + transition: max-height 0.35s ease; + will-change: max-height; +} + +.douban_page #douban_item .douban_content_main.is-expanded { + max-height: 10000px; +} + +.douban_page #douban_item .douban_expand_btn { + display: inline-block; + padding: 0; + color: var(--pix-theme); + font-size: 14px; + font-weight: 500; + background: transparent; + border: none; + cursor: pointer; + text-decoration: none; + line-height: 1.6; +} + +.douban_page #douban_item .douban_content_meta { + margin: 8px 0 0; + font-size: 12px; + color: #6b7280; + line-height: 1.5; +} + +@media only screen and (max-width:1359px) { + .douban_page #douban_item { + grid-template-columns: 1fr; + } + + .douban_page #douban_item .douban_card_item { + border-right: none !important; + } +} + +@media only screen and (max-width:540px) { + .douban_page #douban_item .douban_card_item { + padding: 0 15px; + } + + .douban_page #douban_item .douban_card_inner { + column-gap: 11px; + row-gap: 0px; + } } \ No newline at end of file diff --git a/templates/assets/css/main.css b/templates/assets/css/main.css index 9e4a6cf..af876a4 100644 --- a/templates/assets/css/main.css +++ b/templates/assets/css/main.css @@ -6630,7 +6630,7 @@ a#listree-click.current, .anianx-bubble { position: absolute; - bottom: -60px; + top: 50px; left: 0; width: 100%; background: #F6FAF8; diff --git a/templates/assets/js/anian.js b/templates/assets/js/anian.js index bff9534..a647afb 100644 --- a/templates/assets/js/anian.js +++ b/templates/assets/js/anian.js @@ -106,6 +106,7 @@ async function open_login_box() { login_closeBtn.addEventListener('click', () => { closeLoading?.() login_modal.classList.remove('show'); + if (loginTimer) { clearInterval(loginTimer) } }); // 加密逻辑 @@ -159,8 +160,10 @@ login_loginBtn.addEventListener('click', async () => { cocoMessage.success('署名成功,正在跳转...'); login_loginBtn.textContent = '跳转中...'; const currentScrollTop = window.scrollY || document.documentElement.scrollTop; - $.cookie('scrollParam', currentScrollTop, { path: '/', domain: 'anian.cc' }); - $.cookie('load_type', 'login', { path: '/', domain: 'anian.cc' }); + // $.cookie('scrollParam', currentScrollTop, { path: '/', domain: 'anian.cc' }); + // $.cookie('load_type', 'login', { path: '/', domain: 'anian.cc' }); + $.cookie('scrollParam', currentScrollTop, { path: '/' }); + $.cookie('load_type', 'login', { path: '/' }); window.location.reload(); } else if (finalUrl.includes('error=invalid-credential')) { closeLoading?.() @@ -233,8 +236,10 @@ async function customLogout() { closeLoading(); cocoMessage.success('您已成功退出登录'); const currentScrollTop = window.scrollY || document.documentElement.scrollTop; - $.cookie('scrollParam', currentScrollTop, { path: '/', domain: 'anian.cc' }); - $.cookie('load_type', 'logout', { path: '/', domain: 'anian.cc' }); + // $.cookie('scrollParam', currentScrollTop, { path: '/', domain: 'anian.cc' }); + // $.cookie('load_type', 'logout', { path: '/', domain: 'anian.cc' }); + $.cookie('scrollParam', currentScrollTop, { path: '/' }); + $.cookie('load_type', 'logout', { path: '/' }); window.location.reload(); } else { closeLoading(); @@ -263,6 +268,415 @@ function confirmPixarAction() { customLogout(); } +// 豆瓣页:分类筛选 + AJAX加载(不依赖 finder API) +function init_douban_page() { + var $page = $('.douban_page'); + if ($page.length === 0) { + return; + } + + var $list = $('#douban_item'); + var $pagination = $('#douban_pagination'); + var $paginationBtn = $('#douban_pagination a'); + + if ($list.length === 0 || $paginationBtn.length === 0) { + return; + } + + var state = { + page: 1, + size: 10, + type: '', + loading: false + }; + + function escapeHtml(input) { + if (input === null || input === undefined) { + return ''; + } + return String(input) + .replace(/&/g, '&') + .replace(//g, '>') + .replace(/"/g, '"') + .replace(/'/g, '''); + } + + function formatTime(isoTime) { + if (!isoTime) { + return '--'; + } + var date = new Date(isoTime); + if (Number.isNaN(date.getTime())) { + return '--'; + } + var year = date.getFullYear(); + var month = String(date.getMonth() + 1).padStart(2, '0'); + var day = String(date.getDate()).padStart(2, '0'); + return year + '-' + month + '-' + day; + } + + function buildRequestUrl(page, type) { + var query = new URLSearchParams({ + page: String(page), + size: String(state.size) + }); + if (type) { + query.append('type', type); + } + return '/apis/api.douban.moony.la/v1alpha1/doubanmovies?' + query.toString(); + } + + function renderEmpty() { + return '
暂无内容
'; + } + + function parseScoreValue(rawScore) { + if (rawScore === null || rawScore === undefined || rawScore === '') { + return null; + } + var scoreText = String(rawScore); + var matched = scoreText.match(/(\d+(?:\.\d+)?)/); + if (!matched || !matched[1]) { + return null; + } + var scoreNumber = parseFloat(matched[1]); + if (Number.isNaN(scoreNumber)) { + return null; + } + // 豆瓣常见是 10 分制,这里统一转换为 5 星展示 + if (scoreNumber > 5) { + scoreNumber = scoreNumber / 2; + } + if (scoreNumber < 0) { + scoreNumber = 0; + } + if (scoreNumber > 5) { + scoreNumber = 5; + } + return scoreNumber; + } + + function getTypeNameCN(typeCode) { + var typeMap = { + 'music': '音乐', + 'drama': '演出', + 'book': '图书', + 'game': '游戏', + 'movie': '影视', + // 'test': '测试' + }; + return typeMap[typeCode] || typeCode; + } + + function renderScore(rawScore) { + var scoreValue = parseScoreValue(rawScore); + if (scoreValue === null) { + return '暂无评分'; + } + var formatted = scoreValue.toFixed(1); + return formatted + ' / 5.0'; + } + + function renderItem(item) { + var spec = item && item.spec ? item.spec : {}; + var faves = item && item.faves ? item.faves : {}; + var name = escapeHtml(spec.name || '未命名条目'); + var link = escapeHtml(spec.link || 'javascript:void(0);'); + var poster = escapeHtml(spec.poster || '/themes/theme-pix/assets/img/theme/banner.jpg'); + var rawScore = faves.score || spec.score || ''; + var createTime = escapeHtml(formatTime(faves.createTime)); + var dataType = getTypeNameCN(spec.type || '--'); + var contentText = escapeHtml(spec.cardSubtitle || '暂无内容简介'); + var pid = escapeHtml((item.metadata && item.metadata.name) || ('douban-' + Date.now())); + var scoreText = renderScore(rawScore); + + return '' + + '
' + + '
' + + '
' + + '
' + + ' ' + + ' ' + name + + ' ' + + '
' + + '
' + + ' ' + name + '' + + '
' + + '
' + + ' ' + + ' ' + dataType + '' + + ' ' + escapeHtml(scoreText) + '' + + '
' + + '
' + + '

' + contentText + '

' + + ' ' + + '
' + + '
' + + '
' + + '
'; + } + + function updatePagination(hasNext, nextPage) { + if (hasNext) { + $paginationBtn + .attr('data-next-page', String(nextPage)) + .attr('data', String(nextPage)) + .text((window.Theme && Theme.site_page) ? Theme.site_page : '翻阅更多') + .show(); + $pagination.removeClass('u-hide').css('display', 'flex'); + } else { + $paginationBtn.removeAttr('data-next-page').removeAttr('data'); + $paginationBtn.hide(); + $pagination.hide(); + } + } + + function renderList(data, isAppend) { + var items = (data && data.items) ? data.items : []; + if (!isAppend) { + $list.empty(); + } + if (items.length === 0 && !isAppend) { + $list.html(renderEmpty()); + updatePagination(false, 1); + return; + } + + var html = items.map(renderItem).join(''); + $list.append($(html).fadeIn(300)); + if (typeof lazyLoadInstance !== 'undefined') { + lazyLoadInstance.update(); + } + if (typeof initializeMomentFold === 'function') { + initializeMomentFold(); + } + initializeDoubanExpand(); + updatePagination(!!data.hasNext, (data.page || state.page) + 1); + } + + function initializeDoubanExpand() { + var collapsedHeight = 89.6; + $(document).off('click.doubanExpand', '.douban_expand_btn').on('click.doubanExpand', '.douban_expand_btn', function (e) { + e.preventDefault(); + var $btn = $(this); + var $content = $btn.prev('.douban_content_main'); + if ($content.length === 0) { + return; + } + if ($content.hasClass('is-expanded')) { + $content.removeClass('is-expanded'); + $content.css('max-height', collapsedHeight + 'px'); + $btn.text('展开'); + } else { + var contentEl = $content[0]; + var fullHeight = $content.data('fullHeight') || (contentEl ? contentEl.scrollHeight : 0); + $content.addClass('is-expanded'); + $content.css('max-height', fullHeight + 'px'); + $btn.text('收起'); + } + }); + + $('.douban_content_main').each(function () { + var $content = $(this); + var $btn = $content.next('.douban_expand_btn'); + if ($btn.length === 0) { + return; + } + var scrollHeight = this.scrollHeight; + var clientHeight = this.clientHeight; + if (scrollHeight > clientHeight) { + $btn.show(); + $content.data('fullHeight', scrollHeight); + $content.css('max-height', collapsedHeight + 'px'); + } + }); + } + + function requestList(page, type, isAppend, hooks) { + hooks = hooks || {}; + if (state.loading) { + return; + } + state.loading = true; + var appendStartIndex = isAppend ? $list.children('.p_item').length : 0; + var oldState = { + listHtml: $list.html(), + paginationVisible: $pagination.is(':visible'), + btnVisible: $paginationBtn.is(':visible'), + btnText: $paginationBtn.text(), + btnNextPage: $paginationBtn.attr('data-next-page') + }; + var apiUrl = buildRequestUrl(page, type); + + $.ajax({ + type: 'GET', + url: apiUrl, + dataType: 'json', + beforeSend: function () { + if (!isAppend) { + $list.html('
'); + $pagination.hide(); + } else { + $paginationBtn.hide(); + if ($('#douban_pagination .douban-more-loading').length === 0) { + $('#douban_pagination .post-paging').append('
'); + } + $pagination.css('display', 'flex'); + } + }, + success: function (data) { + state.page = page; + renderList(data || {}, !!isAppend); + if (typeof hooks.onSuccess === 'function') { + hooks.onSuccess(data || {}); + } + if (isAppend) { + var $newItems = $list.children('.p_item').slice(appendStartIndex); + if ($newItems.length > 0) { + var $scrollBody = (typeof $body !== 'undefined') ? $body : $('html,body'); + var targetTop = $newItems.first().offset().top - 58; + if (!window.scroll_param || (!window.loadMoreTimeout && window.scroll_param > targetTop)) { + $scrollBody.animate({ scrollTop: targetTop }, 500); + } else { + window.forceStopLoading = true; + } + } + } + }, + error: function () { + cocoMessage.error('数据获取失败'); + if (!isAppend) { + if ($.trim(oldState.listHtml || '') !== '') { + $list.html(oldState.listHtml); + } else { + $list.html(renderEmpty()); + } + } + if (oldState.paginationVisible) { + $pagination.css('display', 'flex'); + } else { + $pagination.hide(); + } + if (oldState.btnVisible) { + $paginationBtn.show(); + } else { + $paginationBtn.hide(); + } + if (oldState.btnText) { + $paginationBtn.text(oldState.btnText); + } + if (oldState.btnNextPage) { + $paginationBtn.attr('data-next-page', oldState.btnNextPage); + $paginationBtn.attr('data', oldState.btnNextPage); + } + if (typeof hooks.onError === 'function') { + hooks.onError(); + } + }, + complete: function () { + state.loading = false; + $('#douban_pagination .douban-more-loading').remove(); + $('.douban_cat_nav .cat-link').removeClass('disabled'); + $paginationBtn.text((window.Theme && Theme.site_page) ? Theme.site_page : '翻阅更多'); + } + }); + } + + $(document).off('click.doubanCat', '.douban_cat_nav .cat-link').on('click.doubanCat', '.douban_cat_nav .cat-link', function () { + var $this = $(this); + if ($this.hasClass('disabled')) { + return false; + } + if ($this.hasClass('active')) { + if (window._tagSwitchCallback) { + window._tagSwitchCallback.resolve(); + window._tagSwitchCallback = null; + } + return false; + } + + $('.douban_cat_nav .cat-link').addClass('disabled'); + + var $activeBefore = $('.douban_cat_nav .cat-link.active'); + var oldType = state.type; + var targetType = $this.attr('data-type') || ''; + var targetTag = $this.clone().find('span').remove().end().text().trim(); + + state.page = 1; + state.type = targetType; + + requestList(1, state.type, false, { + onSuccess: function () { + $this.addClass('active').parent().siblings().children('.cat-link').removeClass('active'); + + var currentUrl = new URL(window.location.href); + if (!targetTag || targetTag === '全部') { + currentUrl.searchParams.delete('tag'); + } else { + currentUrl.searchParams.set('tag', targetTag); + } + history.pushState({ url: currentUrl.pathname + currentUrl.search }, '', currentUrl.pathname + currentUrl.search); + + // 分类切换后重置分页记录,避免自动恢复加载旧分类页数 + $.removeCookie('page', { path: '/' }); + + if (window._tagSwitchCallback) { + window._tagSwitchCallback.resolve(); + window._tagSwitchCallback = null; + } + }, + onError: function () { + state.type = oldType; + if ($activeBefore.length > 0) { + $activeBefore.addClass('active').parent().siblings().children('.cat-link').removeClass('active'); + } + if (window._tagSwitchCallback) { + window._tagSwitchCallback.reject(); + window._tagSwitchCallback = null; + } + } + }); + return false; + }); + + $(document).off('click.doubanMore', '#douban_pagination a').on('click.doubanMore', '#douban_pagination a', function () { + if (state.loading) { + return false; + } + var pageAttr = $(this).attr('data-next-page') || $(this).attr('data'); + var nextPage = parseInt(pageAttr, 10); + if (!nextPage || Number.isNaN(nextPage)) { + return false; + } + requestList(nextPage, state.type, true, { + onSuccess: function () { + // 与 app.js 现有逻辑保持一致:记录当前已加载到的页码 + $.cookie('page', nextPage, { path: '/' }); + } + }); + return false; + }); + + var urlTag = new URLSearchParams(window.location.search).get('tag'); + if (urlTag && urlTag.trim() !== '') { + var $matchedTag = $('.douban_cat_nav .cat-link').filter(function () { + var tagText = $(this).clone().find('span').remove().end().text().trim(); + return tagText === urlTag; + }).first(); + if ($matchedTag.length > 0) { + $matchedTag.addClass('active').parent().siblings().children('.cat-link').removeClass('active'); + state.type = $matchedTag.attr('data-type') || ''; + } else { + state.type = $('.douban_cat_nav .cat-link.active').attr('data-type') || ''; + } + } else { + state.type = $('.douban_cat_nav .cat-link.active').attr('data-type') || ''; + } + + requestList(1, state.type, false); +} + // 打开确认模态框 function openModal(title, msg, type) { var modal = $('#momentsDeleteModal'); @@ -271,6 +685,8 @@ function openModal(title, msg, type) { modal.find('.moments-message-text').text(msg); card.removeClass('theme-red theme-yellow theme-green').addClass('theme-' + type); $('.moments-btn-cancel, .moments-btn-confirm').prop('disabled', false); + $('body').off('click', '#momentsCancelBtn'); + $('body').off('click', '#momentsConfirmBtn'); modal.fadeIn(200); } @@ -287,6 +703,7 @@ function openModal(title, msg, type) { // 集合:PJAX(初始化执行+PJAX执行) function init_anian_pjax() { // modify_moment_video_size(); + init_douban_page(); } // 集合:初始化(仅初始化执行一次) diff --git a/templates/assets/js/app.js b/templates/assets/js/app.js index 66e6149..55630fb 100644 --- a/templates/assets/js/app.js +++ b/templates/assets/js/app.js @@ -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?.()); } diff --git a/templates/assets/js/moment-push.js b/templates/assets/js/moment-push.js index 3bd051b..43729ea 100644 --- a/templates/assets/js/moment-push.js +++ b/templates/assets/js/moment-push.js @@ -280,47 +280,47 @@ window.currentDeletePid = null; // 删除片刻文章 - 打开弹窗 $('body').on('click', '.control_delete_post', function () { window.currentDeletePid = $(this).parent().attr('pid'); - openModal('删除确认', '确定删除瞬间?该条数据将被永久移除。', 'red'); -}); + openModal('删除确认', '确定删除瞬间?该条数据将被永久移除!', 'red'); -// 点击取消按钮 - 关闭弹窗 -$('body').on('click', '#momentsCancelDeleteBtn', function (e) { - $('#momentsDeleteModal').fadeOut(200); - window.currentDeletePid = null; -}); + // 点击取消按钮 - 关闭弹窗 + $('body').on('click', '#momentsCancelBtn', function (e) { + $('#momentsDeleteModal').fadeOut(200); + window.currentDeletePid = null; + }); -// 点击确认删除 - 执行 AJAX -$('body').on('click', '#momentsConfirmDeleteBtn', function () { - var pid = window.currentDeletePid; - if (!pid) return; - let closeLoading = cocoMessage.loading('正在删除...'); - $('.moments-btn-cancel, .moments-btn-confirm').prop('disabled', true); - $.ajax({ - type: 'DELETE', - dataType: 'json', - url: `/apis/${Theme.moments.api}/v1alpha1/moments/` + pid, - contentType: "application/json", - success: function (data) { - $('#momentsDeleteModal').fadeOut(200); - closeLoading?.() - cocoMessage.success('删除成功'); - window.currentDeletePid = null; - const $post = $(`#post-${pid}`); - if (!$post.length) return; - $post.addClass('moments-delete-disperse'); - setTimeout(() => $post.remove(), 800); - }, - error: function (request) { - if (request.status) { + // 点击确认删除 - 执行 AJAX + $('body').on('click', '#momentsConfirmBtn', function () { + var pid = window.currentDeletePid; + if (!pid) return; + let closeLoading = cocoMessage.loading('正在删除...'); + $('.moments-btn-cancel, .moments-btn-confirm').prop('disabled', true); + $.ajax({ + type: 'DELETE', + dataType: 'json', + url: `/apis/${Theme.moments.api}/v1alpha1/moments/` + pid, + contentType: "application/json", + success: function (data) { + $('#momentsDeleteModal').fadeOut(200); closeLoading?.() - cocoMessage.error('瞬间不存在或已删除'); - } else { - closeLoading?.() - cocoMessage.error('删除失败'); - } - console.log(request) - $('.moments-btn-cancel, .moments-btn-confirm').prop('disabled', false); - }, + cocoMessage.success('删除成功'); + window.currentDeletePid = null; + const $post = $(`#post-${pid}`); + if (!$post.length) return; + $post.addClass('moments-delete-disperse'); + setTimeout(() => $post.remove(), 800); + }, + error: function (request) { + if (request.status) { + closeLoading?.() + cocoMessage.error('瞬间不存在或已删除'); + } else { + closeLoading?.() + cocoMessage.error('删除失败'); + } + console.log(request) + $('.moments-btn-cancel, .moments-btn-confirm').prop('disabled', false); + }, + }); }); }); diff --git a/templates/assets/js/poster.js b/templates/assets/js/poster.js index fc064e7..dda80ce 100644 --- a/templates/assets/js/poster.js +++ b/templates/assets/js/poster.js @@ -27,7 +27,13 @@ const poster = (function() { * @param {object} config - 配置对象 */ function init(config) { - const $container = document.querySelector(config.selector) + const $container = config.container || document.querySelector(config.selector) + if (!$container) { + if (config.callback) { + config.callback(null) + } + return + } // ------------------ 【修复点 2:清理容器,避免PJAX残余】 ------------------ // 在重新绘制前,确保清空容器,移除旧的 img 和 wrapper $container.innerHTML = ''; @@ -121,7 +127,7 @@ const poster = (function() { // 3. 绘制覆盖层 ctx.fillStyle="rgba(0, 0, 0, 0.3)"; - ctx.fillRect(20, 20, $canvas.width - 40, $canvas.height / 1.2 - 40);         + ctx.fillRect(20, 20, $canvas.width - 40, $canvas.height / 1.2 - 40); // 4. 绘制时间 (使用预先绘制好的 Canvas) ctx.drawImage($day, -20, 50) @@ -157,7 +163,7 @@ const poster = (function() { // 移除旧的 wrapper 并添加最终海报图 $container.appendChild(img); // 必须先移除再调用 callback,以确保 DOM 结构干净 - $container.removeChild($wrapper) + $container.removeChild($wrapper) if (config.callback) { config.callback($container) @@ -165,7 +171,9 @@ const poster = (function() { }).catch(error => { console.error('海报图片加载失败:', error); // 可在此处添加错误处理,例如显示一个错误信息 - $container.removeChild($wrapper); + if ($wrapper.parentNode === $container) { + $container.removeChild($wrapper); + } if (config.callback) { // 即使失败也调用回调,传入 null 或错误信息,以便上层逻辑处理 config.callback(null); @@ -356,10 +364,26 @@ const poster = (function() { // ajax生成文章海报 // 此处调用部分需要确保在 PJAX 环境下,该事件监听器能够重新绑定(如果使用传统的 document.ready,在 PJAX 中需要改为监听 pjax:success 等事件) $('body').on('click', '.cr_poster', function () { + let closeLoading = null; + closeLoading = cocoMessage.loading('海报生成中...'); + var $trigger = $(this); var post_id = $(this).attr('poster-data'); var banner = $(this).attr('banner'); var single_content = $('.single-content'); var t_content = $('#post-'+post_id+' .t_content'); + var modal = '#share_modal_' + post_id; + var $modalList = $(modal); + var $modal = $trigger.closest(modal); + if ($modal.length === 0) { + $modal = $(modal + ':visible').first(); + } + if ($modal.length === 0) { + $modal = $modalList.first(); + } + + if ($modal.length === 0) { + return; + } // 确保 content 区域存在 var content_element = single_content.length > 0 ? single_content[0] : (t_content.length > 0 ? t_content[0] : null); @@ -392,43 +416,45 @@ $('body').on('click', '.cr_poster', function () { new QRious({ element: twoCodeCanvas, value: permalink, size: 260, }); - var poster_box_selector = '#share_modal_' + post_id + ' .poster_box'; + var $posterBoxAp = $modal.find('.poster_box_ap').first(); + if ($posterBoxAp.length === 0) { + return; + } // ------------------ 【修复点 2:清理容器】 ------------------ - // 先移除旧的 poster_box - $('.poster_box').remove(); + // 仅在当前弹窗作用域内移除旧容器,避免影响 PJAX 残留节点 + $posterBoxAp.find('.poster_box').remove(); // 重新创建并插入新的 poster_box - $('#share_modal_' + post_id + ' .poster_box_ap').append('
'); + var $posterBox = $('
'); + $posterBoxAp.append($posterBox); // ----------------------------------------------------------------------- if (content_length > 120) { content = content.substring(0, 80) + '...' } - // Posterdown 函数中不再需要移除 loading_box,因为 init 会清空容器 + // 海报生成回调 function Posterdown(e) { - var modal = '#share_modal_' + post_id; - // 检查海报是否成功生成 - if (e && $(modal + ' .poster_box img').length > 0) { - var url = $(modal + ' .poster_box img').attr('src'); - $(modal + ' .post_share_box').removeClass('hide'); - $(modal + ' .poster_download').attr('href', url).attr('download', 'poster_' + post_id + '.png'); + if (e && $posterBox.find('img').length > 0) { + closeLoading?.() + cocoMessage.success("海报生成成功!") // 图片加载完成后才触发 + var url = $posterBox.find('img').attr('src'); + var $shareBox = $modal.find('.post_share_box'); + + $shareBox.removeClass('hide'); + $modal.find('.poster_download').attr('href', url).attr('download', 'poster_' + post_id + '.png'); } else { // 错误处理,如果海报生成失败 - cocoMessage.error("海报生成失败,请检查图片链接!"); + closeLoading?. (); + cocoMessage.error("海报生成失败,请重试!") } } - // 移除 loading box 的时机提前,或者在 init 开始前完成 - // $('.loading_box').remove(); // 原始代码中这行在创建 loading_box 之后,但其作用是移除**所有** .loading_box,可能存在问题 - - // 重新添加 loading 状态,并在 init 中等待 - $(poster_box_selector).append('
'); - poster.init({ banner: banner, - selector: poster_box_selector, // 传入完整的选择器 + selector: modal + ' .poster_box', + container: $posterBox[0], title: title, content: content, logo: Theme.site_logo, @@ -436,9 +462,31 @@ $('body').on('click', '.cr_poster', function () { description: Theme.admin_des, callback: Posterdown }); +}); + +$(document).on('pjax:success', function (event) { + // 清理 PJAX 残留的 modal:只删除那些在当前页面没有对应按钮的 modal + var allModals = $('[id^="share_modal_"]'); + var currentPostIds = {}; - // 移除 loading 动画 - $(poster_box_selector + ' .loading_box').remove(); + // 收集当前页面所有的 post_id + $('.cr_poster').each(function() { + var pid = $(this).attr('poster-data'); + if (pid) { + currentPostIds[pid] = true; + } + }); + + // 只删除残留的 modal(不在当前页面按钮列表中的) + allModals.each(function() { + var $m = $(this); + var modalId = $m.attr('id'); + var postId = modalId ? modalId.replace('share_modal_', '') : null; + + if (postId && !currentPostIds[postId]) { + $m.remove(); + } + }); }); diff --git a/templates/douban.html b/templates/douban.html index 43961d9..e653052 100644 --- a/templates/douban.html +++ b/templates/douban.html @@ -10,46 +10,33 @@
-
+
+
-
+
+ +
-
-
-
- -

-
-
+
- -
-
- -
-
-
想看
-
在看
-
看过
-
-
- -
-
-
-
-
-
+
+
+
-
+
+ +
- -
+
diff --git a/templates/modules/footer.html b/templates/modules/footer.html index a647a9c..e6eaa51 100644 --- a/templates/modules/footer.html +++ b/templates/modules/footer.html @@ -1,5 +1,5 @@ - +
@@ -41,25 +41,25 @@

您确定要退出登录吗?
- 请注意!
+ 请注意:
未保存的内容将会被清空!

- - - + + +
@@ -85,15 +85,15 @@
- - + +
- + diff --git a/templates/modules/head.html b/templates/modules/head.html index da70b4c..adb9fe5 100644 --- a/templates/modules/head.html +++ b/templates/modules/head.html @@ -1,4 +1,4 @@ - + @@ -6,7 +6,7 @@ - diff --git a/templates/modules/header.html b/templates/modules/header.html index 67cfe3a..be57ddd 100644 --- a/templates/modules/header.html +++ b/templates/modules/header.html @@ -51,12 +51,12 @@ // -------------------------- const BANNER_CONFIG = { seasonal: { - '春季': '/upload/dingbu-chun.png', // 春季 Banner - '夏季': '/upload/dingbu-xia.png', // 夏季 Banner - '秋季': '/upload/dingbu-qiu.png', // 秋季 Banner - '冬季': '/upload/dingbu-dong.png' // 冬季 Banner + '春': '/upload/chun.jpg', + '夏': '/upload/xia.jpg', + '秋': '/upload/qiu.jpg', + '冬': '/upload/dong.jpg' }, - fallback: '/upload/dingbu-siji.png' // 兜底图 + fallback: '/upload/dingbu-siji.png' }; // -------------------------- @@ -66,7 +66,7 @@ function anian_setDailyCookie(name, value) { const now = new Date(); const china = new Date(now.getTime() + 8 * 3600 * 1000); const expires = new Date(Date.UTC(china.getUTCFullYear(), china.getUTCMonth(), china.getUTCDate(), 15, 59, 59)); - document.cookie = `${encodeURIComponent(name)}=${encodeURIComponent(value)}; expires=${expires.toUTCString()}; path=/; domain=anian.cc`; + document.cookie = `${encodeURIComponent(name)}=${encodeURIComponent(value)}; expires=${expires.toUTCString()}; path=/`; } function anian_getCookie(name) { @@ -102,7 +102,7 @@ function setBanner(lunarInfo) { // 初始化逻辑(优化版) // -------------------------- (function() { - const apiUrl = 'https://cn.apihz.cn/api/time/getday.php?id=10011724&key=0bdd2d8b3d97c0d476c98a41f108a96f'; + const apiUrl = 'https://api.anian.cc/lunar'; const cookieName = 'anian_lunar_info'; // 1. 优先尝试从 Cookie 读取 @@ -118,16 +118,15 @@ function setBanner(lunarInfo) { fetch(apiUrl) .then(res => res.json()) .then(data => { - if (data.code !== 200) throw new Error('API Error'); - - // 组装农历信息(保留原有逻辑) + // 组装农历信息,保持 cookie 字段名不变 const lunarInfo = { - ganzhiYear: data.ganzhinian || '', - lunarMonth: data.nyue || '', - lunarDay: data.nri || '', - jieqi: (data.JIEQICN || '').includes('第1天') ? data.jieqi : '', + ganzhiYear: data.nian || '', + lunarMonth: data.yue || '', + lunarDay: data.ri || '', + jieqi: data.jieqi || '', jijie: data.jijie || '', - traditionalFestival: data.YIFESTIVAL || '' + shengxiao: data.shengxiao || '', + traditionalFestival: data.jieri || '' }; // 存 Cookie 并设置 Banner diff --git a/theme.yaml b/theme.yaml index 85181c9..108bc73 100644 --- a/theme.yaml +++ b/theme.yaml @@ -17,7 +17,7 @@ spec: issues: "https://github.com/chengzhongxue/halo-theme-pix/issues" settingName: "theme-pix-setting" configMapName: "theme-pix-configMap" - version: "1.2.5-4" + version: "1.2.5-6" require: ">=2.20.0" customTemplates: page: