added 文章一篇

This commit is contained in:
Vaica committed 2026-01-30 23:07:58 +08:00
1 parent 558020036f
commit f1865dca6c
9 files changed
+478 -151

No files matched your search

+102
View File
@@ -905,3 +905,105 @@ function initSearchFunctionality() {
document.addEventListener('DOMContentLoaded', initSearchFunctionality);
// Re-init on Pjax complete
document.addEventListener('pjax:complete', initSearchFunctionality);
// Call on ready
$(document).ready(function() {
window.initLinkStatus();
});
// Link Status Check
window.initLinkStatus = function() {
console.log('initLinkStatus called');
// Selectors for both Card View (.links-item) and List View (.links li)
var $cardLinks = $('.links-item a');
var $listLinks = $('.links ul > li > a');
console.log('Found card links:', $cardLinks.length);
console.log('Found list links:', $listLinks.length);
// Only run if there are any links to check
if ($cardLinks.length === 0 && $listLinks.length === 0) return;
console.log('Fetching /link_status.json...');
fetch('/link_status.json?t=' + new Date().getTime())
.then(response => {
console.log('Fetch response status:', response.status);
if (!response.ok) throw new Error('Status file not found');
return response.json();
})
.then(data => {
console.log('Link status data loaded, keys:', Object.keys(data).length);
let activeCount = 0;
let deadCount = 0;
// Helper function to check URL status
const getUrlStatus = (url) => {
if (!url) return 'unknown';
var cleanUrl = url.replace(/\/$/, '');
var httpsUrl = cleanUrl.replace(/^http:/, 'https:');
var httpUrl = cleanUrl.replace(/^https:/, 'http:');
const keys = [
url,
cleanUrl,
cleanUrl + '/',
httpsUrl,
httpUrl,
httpsUrl + '/',
httpUrl + '/'
];
let isDead = false;
for (const key of keys) {
if (data[key] === true) return 'alive';
if (data[key] === false) isDead = true;
}
return isDead ? 'dead' : 'unknown';
};
// Process Card View Links
$cardLinks.each(function() {
var $link = $(this);
var url = $link.attr('href');
var status = getUrlStatus(url);
if (status === 'alive') {
var $item = $link.closest('.links-item');
if ($item.find('.link-active-badge').length === 0) {
$item.append('<span class="link-active-badge" title="可访问"></span>');
activeCount++;
}
} else if (status === 'dead') {
var $item = $link.closest('.links-item');
if ($item.find('.link-dead-badge').length === 0) {
$item.append('<span class="link-dead-badge" title="无法访问"></span>');
deadCount++;
}
}
});
// Process List View Links
$listLinks.each(function() {
var $link = $(this);
var url = $link.attr('href');
var status = getUrlStatus(url);
if (status === 'alive') {
var $li = $link.closest('li');
$li.addClass('link-active-li');
$li.attr('title', '可访问');
activeCount++;
} else if (status === 'dead') {
var $li = $link.closest('li');
$li.addClass('link-dead-li');
$li.attr('title', '无法访问');
deadCount++;
}
});
console.log('Link status updated. Active:', activeCount, 'Dead:', deadCount);
})
.catch(err => console.error('Link status check failed:', err));
};
+4
View File
@@ -177,6 +177,10 @@ document.addEventListener("pjax:complete", function () {
initCodeCopy()
// 初始化代码折叠
initCodeFold()
// 初始化友链状态
if (typeof window.initLinkStatus === 'function') {
window.initLinkStatus();
}
// 重载评论
if (typeof window.initArtalk === 'function') {
window.initArtalk();