MediaWiki:Citizen.js:修订间差异
MediaWiki界面页面
更多操作
更新日志移动端Tab切换JS |
更新日志移动端Tab切换JS(href选择器) |
||
| 第131行: | 第131行: | ||
/* 更新日志 - 移动端Tab切换 */ | /* 更新日志 - 移动端Tab切换 */ | ||
(function() { | (function() { | ||
var | var logLink = document.querySelector('a[href="#tab-log"]'); | ||
var todoLink = document.querySelector('a[href="#tab-todo"]'); | |||
var | var logDiv = document.getElementById('tab-log'); | ||
var | var todoDiv = document.getElementById('tab-todo'); | ||
var | if (!logLink || !todoLink) return; | ||
function switchTab(tab) { | function switchTab(tab) { | ||
logLink.classList.remove('lts-tab-active'); | |||
if ( | todoLink.classList.remove('lts-tab-active'); | ||
if ( | if (logDiv) logDiv.classList.remove('lts-tab-active'); | ||
if (todoDiv) todoDiv.classList.remove('lts-tab-active'); | |||
if (tab === 'log') { | if (tab === 'log') { | ||
logLink.classList.add('lts-tab-active'); | |||
if ( | if (logDiv) logDiv.classList.add('lts-tab-active'); | ||
} else { | } else { | ||
todoLink.classList.add('lts-tab-active'); | |||
if ( | if (todoDiv) todoDiv.classList.add('lts-tab-active'); | ||
} | } | ||
} | } | ||
logLink.addEventListener('click', function(e) { | |||
e.preventDefault(); | |||
switchTab('log'); | |||
}); | }); | ||
// | todoLink.addEventListener('click', function(e) { | ||
e.preventDefault(); | |||
switchTab('todo'); | |||
}); | |||
// 默认显示更新日志 | |||
switchTab('log'); | switchTab('log'); | ||
})(); | })(); | ||
2026年5月18日 (一) 23:41的版本
/* 服务器状态查询 - 柠檬树服务器 */
console.log('[LTS] 状态查询脚本已加载');
(function() {
var STARTED = false;
var servers = [
{ id: 'lts-status-platform', address: 'platform.lts.ink', title: '月台', subtitle: '重度机械症 · 1服 · 离线正版都可进' },
{ id: 'lts-status-journey', address: 'journey.lts.ink', title: '启程', subtitle: '重度机械症 · 2服 · 已开启正版验证' },
{ id: 'lts-status-promised', address: 'promised.lts.ink', title: '应许', subtitle: '创造/体验服 · 已开启正版验证' },
{ id: 'lts-status-voyage', address: '45.125.45.195', title: '远行', subtitle: '你好!新蒸程·远行服·已开启正版验证', port: '25565' }
];
var API = 'https://wiki.suanlemon.cc/api/server-status/';
var allData = {};
var timer = null;
function buildCard(server, data) {
var color = data.online ? '#3a971e' : '#bf3c2c';
var statusText = data.online ? '在线' : '离线';
var html = '<div style="padding:6px 0;border-bottom:1px solid #eee;display:flex;align-items:center;gap:8px;flex-wrap:wrap;">';
html += '<b>' + server.title + '</b>';
html += '<span style="font-size:0.8em;color:#888;">' + server.subtitle + '</span>';
html += '<span style="margin-left:auto;font-weight:bold;color:' + color + ';font-size:0.85em;">' + statusText + '</span>';
html += '</div>';
if (data.online && data.players) {
html += '<div style="padding:4px 0 0;display:flex;align-items:center;gap:12px;flex-wrap:wrap;">';
html += '<span style="font-size:0.85em;">' + data.players.online + ' / ' + data.players.max + ' 人</span>';
html += '<span style="font-size:0.8em;color:#888;">' + (data.latency || '?') + 'ms</span>';
if (data.version) html += '<span style="font-size:0.8em;color:#888;">' + data.version + '</span>';
html += '</div>';
if (data.players.list && data.players.list.length > 0) {
html += '<div style="margin-top:4px;display:flex;flex-wrap:wrap;gap:4px;align-items:center;">';
data.players.list.forEach(function(name) {
html += '<span style="font-size:0.75em;background:#f0f0f0;padding:1px 5px;display:inline-flex;align-items:center;gap:2px;">';
html += '<img src="https://mineskin.eu/helm/' + name + '/24" width="14" height="14" style="image-rendering:pixelated;" onerror="this.style.display=\'none\'">';
html += name;
html += '</span>';
});
html += '</div>';
}
}
return html;
}
function updateSummary() {
var el = document.getElementById('lts-status-summary');
if (!el) return;
var onlineCount = 0, totalPlayers = 0;
servers.forEach(function(s) {
var d = allData[s.id];
if (d && d.online) {
onlineCount++;
if (d.players) totalPlayers += d.players.online || 0;
}
});
el.innerHTML = '<div style="display:flex;align-items:center;gap:12px;flex-wrap:wrap;">' +
'<span style="font-size:1.1em;font-weight:bold;color:#3a971e;">' + onlineCount + ' / ' + servers.length + ' 台在线</span>' +
'<span style="font-size:0.95em;">共 ' + totalPlayers + ' 人在线</span>' +
'<span style="margin-left:auto;font-size:0.8em;"><a href="/index.php/服务器信息">查看详情</a></span>' +
'</div>';
}
function doFetch() {
var firstEl = document.getElementById('lts-status-platform');
if (!firstEl) return;
servers.forEach(function(server) {
var el = document.getElementById(server.id);
if (!el) return;
var addr = server.port ? server.address + ':' + server.port : server.address;
fetch(API + addr)
.then(function(r) { return r.json(); })
.then(function(data) {
allData[server.id] = data;
el.innerHTML = buildCard(server, data);
updateSummary();
})
.catch(function() {
allData[server.id] = { online: false };
el.innerHTML = '<div style="color:#bf3c2c;padding:4px 0;">查询失败</div>';
updateSummary();
});
});
}
function start() {
if (STARTED) return;
var firstEl = document.getElementById('lts-status-platform');
if (!firstEl) return;
STARTED = true;
console.log('[LTS] 找到容器,开始查询');
doFetch();
timer = setInterval(doFetch, 15000);
}
if (document.readyState === 'complete' || document.readyState === 'interactive') {
start();
} else {
document.addEventListener('DOMContentLoaded', start);
}
mw.hook('wikipage.content').add(start);
})();
/* === 售票亭统计 === */
$(function() {
if (mw.config.get('wgPageName') !== '售票亭') return;
var $stats = $('#ticket-stats');
if (!$stats.length) return;
var p = 0, f = 0, d = '';
$('#mw-content-text h3, #mw-content-text h4').each(function() {
var m = $(this).text().match(/(\d+月\d+日)\s*发车/);
if (!m) return;
if (!d) d = m[1];
var $tbl = $(this).nextAll('table').first();
if (!$tbl.length) $tbl = $(this).parent().nextAll('table').first();
if (!$tbl.length) return;
var txt = $tbl.text();
p += (txt.match(/\[.+?\]/g) || []).length;
f += (txt.match(/未能登车/g) || []).length;
});
$stats.html('🎫 已发放车票 <strong>' + p + '</strong> 张 | ✗ 未能登车 <strong>' + f + '</strong> 人 | 📅 最近更新 <strong>' + d + '</strong>');
});
/* 更新日志 - 移动端Tab切换 */
(function() {
var logLink = document.querySelector('a[href="#tab-log"]');
var todoLink = document.querySelector('a[href="#tab-todo"]');
var logDiv = document.getElementById('tab-log');
var todoDiv = document.getElementById('tab-todo');
if (!logLink || !todoLink) return;
function switchTab(tab) {
logLink.classList.remove('lts-tab-active');
todoLink.classList.remove('lts-tab-active');
if (logDiv) logDiv.classList.remove('lts-tab-active');
if (todoDiv) todoDiv.classList.remove('lts-tab-active');
if (tab === 'log') {
logLink.classList.add('lts-tab-active');
if (logDiv) logDiv.classList.add('lts-tab-active');
} else {
todoLink.classList.add('lts-tab-active');
if (todoDiv) todoDiv.classList.add('lts-tab-active');
}
}
logLink.addEventListener('click', function(e) {
e.preventDefault();
switchTab('log');
});
todoLink.addEventListener('click', function(e) {
e.preventDefault();
switchTab('todo');
});
// 默认显示更新日志
switchTab('log');
})();