/**
 * Theme: theme-Serenity
 * Author: Serenity
 * Build: 2026-04-12 21:46:28
 * Fingerprint: 3d12f6e686831ac7
 * Copyright © 2026 Serenity. All rights reserved.
 * Unauthorized copying or distribution is prohibited.
 */
var PAGE_SIZE=10;var currentPage=1;var totalPages=1;function escapeHtml(text){if(text===null||text===undefined)return '';return String(text).replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;').replace(/"/g,'&quot;').replace(/'/g,'&#39;');}function sanitizeUrl(url,fallback='#'){if(typeof url !=='string')return fallback;var trimmed=url.trim();if(!trimmed)return fallback;var lower=trimmed.toLowerCase();if(lower.startsWith('http://')||lower.startsWith('https://')||trimmed.startsWith('//')||trimmed.startsWith('/'))return trimmed;return fallback;}function init(){const allFriends=window.allFriends||[];if(allFriends.length===0){var emptyEl=document.getElementById('emptyState');emptyEl.style.display='flex';emptyEl.classList.remove('aos-animate');void emptyEl.offsetHeight;if(typeof AOS !=='undefined')AOS.refresh();return;}totalPages=Math.ceil(allFriends.length / PAGE_SIZE);document.getElementById('totalCount').textContent=allFriends.length;document.getElementById('totalPages').textContent=totalPages;document.getElementById('pagination').style.display='flex';renderPage(1);}function renderPage(page){const allFriends=window.allFriends||[];currentPage=page;const start=(page-1)*PAGE_SIZE;const end=start+PAGE_SIZE;const pageData=allFriends.slice(start,end);const grid=document.getElementById('friendsCircleGrid');grid.innerHTML='';const fragment=document.createDocumentFragment();pageData.forEach((friend,index)=>{const spec=friend.spec;const card=createCard(spec,start+index);fragment.appendChild(card);});grid.appendChild(fragment);updatePagination();window.scrollTo({top:0,behavior:'smooth'});if(window.__lenis){window.__lenis.scrollTo(0,{duration:1.2});}}function createCard(spec,index){const card=document.createElement('div');card.className='friend-post-card';card.setAttribute('data-aos','fade-up');card.setAttribute('data-aos-delay',(index % PAGE_SIZE)*50);const date=spec&&spec.pubDate?new Date(spec.pubDate):null;const isValidDate=date&&!isNaN(date.getTime());const formattedDate=isValidDate?date.getFullYear()+'-'+String(date.getMonth()+1).padStart(2,'0')+'-'+String(date.getDate()).padStart(2,'0')+' '+String(date.getHours()).padStart(2,'0')+':'+String(date.getMinutes()).padStart(2,'0'):'--';const authorUrl=sanitizeUrl(spec&&spec.authorUrl,'#');const postLink=sanitizeUrl(spec&&spec.postLink,'#');const logoUrl=sanitizeUrl(spec&&spec.logo,'');const authorName=(spec&&spec.author)||'未知作者';const fallbackAvatar=`https://api.dicebear.com/7.x/avataaars/svg?seed=${encodeURIComponent(authorName)}`;const avatarSrc=logoUrl||fallbackAvatar;const safeAuthor=escapeHtml(authorName);const safeTitle=escapeHtml((spec&&spec.title)||'无标题');const safeDescription=escapeHtml((spec&&spec.description)||'暂无描述');const safeFormattedDate=escapeHtml(formattedDate);const safeAvatarSrc=escapeHtml(avatarSrc);const safeFallbackAvatar=escapeHtml(fallbackAvatar);card.innerHTML=`<div class="friend-post-author"><a href="${authorUrl}" target="_blank" rel="noopener noreferrer" class="friend-author-link"><img src="${safeAvatarSrc}"data-fallback="${safeFallbackAvatar}"alt="${safeAuthor}"class="friend-author-avatar"loading="lazy"referrerpolicy="no-referrer"onerror="if(this.dataset.fallback){this.src=this.dataset.fallback;this.dataset.fallback='';}else{this.style.display='none';}"><div class="friend-author-info"><span class="friend-author-name">${safeAuthor}</span><time class="friend-post-time">${safeFormattedDate}</time></div></a></div><div class="friend-post-content"><h3 class="friend-post-title">${safeTitle}</h3><p class="friend-post-desc">${safeDescription}</p></div><a href="${postLink}" target="_blank" rel="noopener noreferrer" class="friend-post-arrow"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5"><path d="M9 18l6-6-6-6"/></svg></a>`;return card;}function updatePagination(){document.getElementById('currentPage').textContent=currentPage;const prevBtn=document.getElementById('prevBtn');const nextBtn=document.getElementById('nextBtn');if(currentPage<=1){prevBtn.classList.add('pagination-arrow-disabled');prevBtn.disabled=true;}else{prevBtn.classList.remove('pagination-arrow-disabled');prevBtn.disabled=false;}if(currentPage>=totalPages){nextBtn.classList.add('pagination-arrow-disabled');nextBtn.disabled=true;}else{nextBtn.classList.remove('pagination-arrow-disabled');nextBtn.disabled=false;}}function prevPage(){if(currentPage>1){renderPage(currentPage-1);}}function nextPage(){if(currentPage<totalPages){renderPage(currentPage+1);}}document.addEventListener('DOMContentLoaded',init);