MediaWiki:Common.js:修订间差异
来自勿忘草与永远的少女
跳到导航跳到搜索
无编辑摘要 标签:手工回退 |
无编辑摘要 标签:已被回退 |
||
| 第1行: | 第1行: | ||
/* 这里的任何JavaScript将为所有用户在每次页面加载时加载。 */ | /* 这里的任何JavaScript将为所有用户在每次页面加载时加载。 */ | ||
// ===== 导航栏 ===== | |||
$(function() { | $(function() { | ||
if ($('.fixed-top-nav').length === 0) { | if ($('.fixed-top-nav').length === 0) { | ||
var navHtml = ` | var navHtml = ` | ||
<div class="fixed-top-nav"> | <div class="fixed-top-nav"> | ||
| 第12行: | 第11行: | ||
</a> | </a> | ||
<div class="nav-links"> | <div class="nav-links"> | ||
<a href="首页" class="nav-link"> | <a href="首页" class="nav-link">📚 首页</a> | ||
<a href="游戏攻略" class="nav-link">📖 游戏攻略</a> | |||
<a href="棋子" class="nav-link">⚔️ 棋子图鉴</a> | |||
<a href="游戏攻略" class="nav-link"> | <a href="天赋图鉴" class="nav-link">🗺️ 天赋图鉴</a> | ||
<a href="装备图鉴" class="nav-link">📊 装备图鉴</a> | |||
<a href="https://www.war3whj.top/war3wiki/moniqi/moniqi.html" class="nav-link">📊 阵容模拟器</a> | |||
<a href="棋子" class="nav-link"> | |||
<a href="天赋图鉴" class="nav-link"> | |||
<a href="装备图鉴" class="nav-link"> | |||
<a href="https://www.war3whj.top/war3wiki/moniqi/moniqi.html" class="nav-link"> | |||
</div> | </div> | ||
</div> | </div> | ||
`; | `; | ||
$('body').prepend(navHtml); | $('body').prepend(navHtml); | ||
$(window).scroll(function() { | $(window).scroll(function() { | ||
if ($(window).scrollTop() > 50) { | if ($(window).scrollTop() > 50) { | ||
| 第48行: | 第31行: | ||
}); | }); | ||
// ===== 页脚 ===== | |||
$(function() { | $(function() { | ||
var footer = $('#footer, .mw-footer'); | var footer = $('#footer, .mw-footer'); | ||
if (footer.length > 0) { | if (footer.length > 0) { | ||
var footerHeight = footer.outerHeight(); | var footerHeight = footer.outerHeight(); | ||
$('body').css('padding-bottom', footerHeight + 20 + 'px'); | $('body').css('padding-bottom', footerHeight + 20 + 'px'); | ||
$(window).resize(function() { | $(window).resize(function() { | ||
var newHeight = footer.outerHeight(); | var newHeight = footer.outerHeight(); | ||
| 第66行: | 第44行: | ||
}); | }); | ||
// ===== 角色卡片 ===== | |||
$(function() { | $(function() { | ||
$('.character-card').hover( | $('.character-card').hover( | ||
function() { $(this).addClass('hover'); }, | function() { $(this).addClass('hover'); }, | ||
function() { $(this).removeClass('hover'); } | function() { $(this).removeClass('hover'); } | ||
); | ); | ||
function adjustSidebarHeight() { | function adjustSidebarHeight() { | ||
var leftHeight = $('.custom-homepage .left-column').outerHeight(); | var leftHeight = $('.custom-homepage .left-column').outerHeight(); | ||
| 第81行: | 第57行: | ||
} | } | ||
} | } | ||
setTimeout(adjustSidebarHeight, 500); | setTimeout(adjustSidebarHeight, 500); | ||
$(window).resize(adjustSidebarHeight); | $(window).resize(adjustSidebarHeight); | ||
}); | }); | ||
/* ========== | /* ========== 棋子图鉴:改造 Cargo 自带羁绊下拉(固定选项) ========== */ | ||
$(function() { | $(function() { | ||
// | // 只有页面上有 id="chess-table" 时才生效,避免干扰其他页面 | ||
if ($('#chess-table').length === 0) return; | |||
// | // 固定的羁绊列表(按你的游戏修改) | ||
var | var BOND_LIST = ['全部', '法师', '狂战士', '水之女神', '木灵使', '快枪手', '冰之魔女']; | ||
var $table = $('#chess-table table.cargoDynamicTable'); | |||
if (!$table.length) return; | |||
// 找到表头中 data-field="羁绊" 的 <select> | |||
var $targetTh = $table.find('thead th[data-field="羁绊"]'); | |||
if (!$targetTh.length) return; | |||
var $targetSelect = $targetTh.find('select'); | |||
if (!$targetSelect.length) return; | |||
// 替换下拉选项为固定羁绊 | |||
var html = ''; | |||
$.each(BOND_LIST, function(i, bond) { | |||
html += '<option value="' + bond + '">' + bond + '</option>'; | |||
}); | |||
$targetSelect.html(html).val('全部'); | |||
// 移除 Cargo 原有的筛选事件(通过克隆实现) | |||
var $newSelect = $targetSelect.clone(true); | |||
$targetSelect.replaceWith($newSelect); | |||
$targetSelect = $targetTh.find('select'); | |||
var $rows = $table.find('tbody tr'); | |||
var | // 绑定新筛选:包含所选羁绊即显示 | ||
var | $targetSelect.on('change', function() { | ||
var selected = $(this).val(); | |||
$rows.each(function() { | |||
var $cells = $(this).find('td'); | |||
var colIndex = $targetTh.index(); | |||
var bondText = $cells.eq(colIndex).text().trim(); | |||
if (selected === '全部') { | |||
$(this).show(); | |||
return; | |||
} | |||
// 拆分羁绊字符串(支持逗号、顿号) | |||
var bonds = bondText.split(/[,,、]/).map(function(s) { return s.trim(); }); | |||
if ($.inArray(selected, bonds) !== -1) { | |||
$(this).show(); | |||
} else { | } else { | ||
$ | $(this).hide(); | ||
} | } | ||
}); | }); | ||
}); | |||
}); | }); | ||
/* ========== | /* ========== 装备图鉴筛选(类型、获取方式) ========== */ | ||
$(function() { | $(function() { | ||
var pageTitle = mw.config.get('wgTitle'); | var pageTitle = mw.config.get('wgTitle'); | ||
if (pageTitle !== '装备图鉴') return; | if (pageTitle !== '装备图鉴') return; | ||
var maxAttempts = 50; | var maxAttempts = 50; | ||
var attempt = 0; | var attempt = 0; | ||
| 第276行: | 第136行: | ||
var $rows = $table.find('tbody tr'); | var $rows = $table.find('tbody tr'); | ||
if ($rows.length === 0) return; | if ($rows.length === 0) return; | ||
if ($('#equipment-filter-container').length) return; | if ($('#equipment-filter-container').length) return; | ||
var headerCells = $table.find('thead tr th'); | var headerCells = $table.find('thead tr th'); | ||
var colMap = {}; | var colMap = {}; | ||
| 第289行: | 第146行: | ||
}); | }); | ||
var COL_TYPE = colMap.type !== undefined ? colMap.type : 4; | |||
var COL_TYPE = colMap.type !== undefined ? colMap.type : 4; | var COL_SOURCE = colMap.source !== undefined ? colMap.source : 5; | ||
var COL_SOURCE = colMap.source !== undefined ? colMap.source : 5; | |||
function getUniqueValues(colIndex) { | function getUniqueValues(colIndex) { | ||
var set = new Set(); | var set = new Set(); | ||
| 第308行: | 第163行: | ||
var sourceOpts = getUniqueValues(COL_SOURCE); | var sourceOpts = getUniqueValues(COL_SOURCE); | ||
var $filterDiv = $('<div id="equipment-filter-container" style="margin:20px 0;padding:15px;background:rgba(255,255,255,0.9);border-radius:12px;box-shadow:0 2px 8px rgba(0,0,0,0.1);"></div>'); | var $filterDiv = $('<div id="equipment-filter-container" style="margin:20px 0;padding:15px;background:rgba(255,255,255,0.9);border-radius:12px;box-shadow:0 2px 8px rgba(0,0,0,0.1);"></div>'); | ||
var $rowDiv = $('<div style="display:flex;flex-wrap:wrap;gap:15px;align-items:flex-end;"></div>'); | var $rowDiv = $('<div style="display:flex;flex-wrap:wrap;gap:15px;align-items:flex-end;"></div>'); | ||
function createSelect(labelText, id, optionsArray) { | function createSelect(labelText, id, optionsArray) { | ||
var $wrapper = $('<div style="min-width:160px;"></div>'); | var $wrapper = $('<div style="min-width:160px;"></div>'); | ||
| 第335行: | 第188行: | ||
var $stats = $('<div id="equipment-filter-stats" style="margin-top:10px;font-size:14px;color:#555;"></div>'); | var $stats = $('<div id="equipment-filter-stats" style="margin-top:10px;font-size:14px;color:#555;"></div>'); | ||
$filterDiv.append($rowDiv).append($stats); | $filterDiv.append($rowDiv).append($stats); | ||
$table.before($filterDiv); | $table.before($filterDiv); | ||
var $typeSelect = $('#filter-type'); | var $typeSelect = $('#filter-type'); | ||
var $sourceSelect = $('#filter-source'); | var $sourceSelect = $('#filter-source'); | ||
| 第346行: | 第196行: | ||
var type = $typeSelect.val() || ''; | var type = $typeSelect.val() || ''; | ||
var source = $sourceSelect.val() || ''; | var source = $sourceSelect.val() || ''; | ||
var visibleCount = 0; | var visibleCount = 0; | ||
$rows.each(function() { | $rows.each(function() { | ||
| 第352行: | 第201行: | ||
var rowType = $tds.eq(COL_TYPE).text().trim(); | var rowType = $tds.eq(COL_TYPE).text().trim(); | ||
var rowSource = $tds.eq(COL_SOURCE).text().trim(); | var rowSource = $tds.eq(COL_SOURCE).text().trim(); | ||
var match = true; | var match = true; | ||
if (type && rowType !== type) match = false; | if (type && rowType !== type) match = false; | ||
if (source && rowSource !== source) match = false; | if (source && rowSource !== source) match = false; | ||
if (match) { | if (match) { | ||
$(this).show(); | $(this).show(); | ||
| 第364行: | 第211行: | ||
} | } | ||
}); | }); | ||
$stats.text('当前显示 ' + visibleCount + ' 件装备(共 ' + $rows.length + ' 件)'); | $stats.text('当前显示 ' + visibleCount + ' 件装备(共 ' + $rows.length + ' 件)'); | ||
var $noRow = $table.find('.no-results-row'); | var $noRow = $table.find('.no-results-row'); | ||
if (visibleCount === 0) { | if (visibleCount === 0) { | ||
| 第394行: | 第238行: | ||
applyFilters(); | applyFilters(); | ||
}); | }); | ||
applyFilters(); | applyFilters(); | ||
} | } | ||
}); | }); | ||
2026年5月10日 (日) 08:35的版本
/* 这里的任何JavaScript将为所有用户在每次页面加载时加载。 */
// ===== 导航栏 =====
$(function() {
if ($('.fixed-top-nav').length === 0) {
var navHtml = `
<div class="fixed-top-nav">
<a href="首页" class="nav-logo">
<img src="/wikibg/logo.jpg" alt="网站Logo">
<span>万华镜</span>
</a>
<div class="nav-links">
<a href="首页" class="nav-link">📚 首页</a>
<a href="游戏攻略" class="nav-link">📖 游戏攻略</a>
<a href="棋子" class="nav-link">⚔️ 棋子图鉴</a>
<a href="天赋图鉴" class="nav-link">🗺️ 天赋图鉴</a>
<a href="装备图鉴" class="nav-link">📊 装备图鉴</a>
<a href="https://www.war3whj.top/war3wiki/moniqi/moniqi.html" class="nav-link">📊 阵容模拟器</a>
</div>
</div>
`;
$('body').prepend(navHtml);
$(window).scroll(function() {
if ($(window).scrollTop() > 50) {
$('.fixed-top-nav').addClass('scrolled');
} else {
$('.fixed-top-nav').removeClass('scrolled');
}
});
}
});
// ===== 页脚 =====
$(function() {
var footer = $('#footer, .mw-footer');
if (footer.length > 0) {
var footerHeight = footer.outerHeight();
$('body').css('padding-bottom', footerHeight + 20 + 'px');
$(window).resize(function() {
var newHeight = footer.outerHeight();
$('body').css('padding-bottom', newHeight + 20 + 'px');
});
}
});
// ===== 角色卡片 =====
$(function() {
$('.character-card').hover(
function() { $(this).addClass('hover'); },
function() { $(this).removeClass('hover'); }
);
function adjustSidebarHeight() {
var leftHeight = $('.custom-homepage .left-column').outerHeight();
var rightHeight = $('.custom-homepage .right-column').outerHeight();
if (rightHeight < leftHeight && $(window).width() > 768) {
$('.custom-homepage .right-column').css('min-height', leftHeight);
}
}
setTimeout(adjustSidebarHeight, 500);
$(window).resize(adjustSidebarHeight);
});
/* ========== 棋子图鉴:改造 Cargo 自带羁绊下拉(固定选项) ========== */
$(function() {
// 只有页面上有 id="chess-table" 时才生效,避免干扰其他页面
if ($('#chess-table').length === 0) return;
// 固定的羁绊列表(按你的游戏修改)
var BOND_LIST = ['全部', '法师', '狂战士', '水之女神', '木灵使', '快枪手', '冰之魔女'];
var $table = $('#chess-table table.cargoDynamicTable');
if (!$table.length) return;
// 找到表头中 data-field="羁绊" 的 <select>
var $targetTh = $table.find('thead th[data-field="羁绊"]');
if (!$targetTh.length) return;
var $targetSelect = $targetTh.find('select');
if (!$targetSelect.length) return;
// 替换下拉选项为固定羁绊
var html = '';
$.each(BOND_LIST, function(i, bond) {
html += '<option value="' + bond + '">' + bond + '</option>';
});
$targetSelect.html(html).val('全部');
// 移除 Cargo 原有的筛选事件(通过克隆实现)
var $newSelect = $targetSelect.clone(true);
$targetSelect.replaceWith($newSelect);
$targetSelect = $targetTh.find('select');
var $rows = $table.find('tbody tr');
// 绑定新筛选:包含所选羁绊即显示
$targetSelect.on('change', function() {
var selected = $(this).val();
$rows.each(function() {
var $cells = $(this).find('td');
var colIndex = $targetTh.index();
var bondText = $cells.eq(colIndex).text().trim();
if (selected === '全部') {
$(this).show();
return;
}
// 拆分羁绊字符串(支持逗号、顿号)
var bonds = bondText.split(/[,,、]/).map(function(s) { return s.trim(); });
if ($.inArray(selected, bonds) !== -1) {
$(this).show();
} else {
$(this).hide();
}
});
});
});
/* ========== 装备图鉴筛选(类型、获取方式) ========== */
$(function() {
var pageTitle = mw.config.get('wgTitle');
if (pageTitle !== '装备图鉴') return;
var maxAttempts = 50;
var attempt = 0;
var interval = setInterval(function() {
var $table = $('table.cargoDynamicTable, table.cargoTable');
if ($table.length > 0) {
clearInterval(interval);
initEquipmentFilters($table);
} else if (++attempt >= maxAttempts) {
clearInterval(interval);
console.warn('装备图鉴筛选器:未找到 Cargo 表格');
}
}, 200);
function initEquipmentFilters($table) {
var $rows = $table.find('tbody tr');
if ($rows.length === 0) return;
if ($('#equipment-filter-container').length) return;
var headerCells = $table.find('thead tr th');
var colMap = {};
headerCells.each(function(index) {
var text = $(this).text().trim();
if (text.includes('类型')) colMap.type = index;
else if (text.includes('获取方式')) colMap.source = index;
});
var COL_TYPE = colMap.type !== undefined ? colMap.type : 4;
var COL_SOURCE = colMap.source !== undefined ? colMap.source : 5;
function getUniqueValues(colIndex) {
var set = new Set();
$rows.each(function() {
var text = $(this).find('td').eq(colIndex).text().trim();
if (text) set.add(text);
});
return Array.from(set).sort(function(a, b) {
return a.localeCompare(b, 'zh-CN');
});
}
var typeOpts = getUniqueValues(COL_TYPE);
var sourceOpts = getUniqueValues(COL_SOURCE);
var $filterDiv = $('<div id="equipment-filter-container" style="margin:20px 0;padding:15px;background:rgba(255,255,255,0.9);border-radius:12px;box-shadow:0 2px 8px rgba(0,0,0,0.1);"></div>');
var $rowDiv = $('<div style="display:flex;flex-wrap:wrap;gap:15px;align-items:flex-end;"></div>');
function createSelect(labelText, id, optionsArray) {
var $wrapper = $('<div style="min-width:160px;"></div>');
$wrapper.append($('<label style="display:block;font-weight:bold;margin-bottom:5px;color:#2c3e50;">').text(labelText));
var $select = $('<select style="width:100%;padding:6px;border-radius:6px;border:1px solid #ccc;">').attr('id', id);
$select.append($('<option value="">').text('全部'));
optionsArray.forEach(function(val) {
$select.append($('<option>').attr('value', val).text(val));
});
$wrapper.append($select);
return $wrapper;
}
$rowDiv.append(createSelect('📦 类型', 'filter-type', typeOpts));
$rowDiv.append(createSelect('🔍 获取方式', 'filter-source', sourceOpts));
var $btnWrapper = $('<div></div>');
var $resetBtn = $('<button id="reset-equipment-filters" style="padding:6px 20px;background:#2c3e50;color:#fff;border:none;border-radius:20px;cursor:pointer;font-weight:bold;">重置筛选</button>');
$btnWrapper.append($resetBtn);
$rowDiv.append($btnWrapper);
var $stats = $('<div id="equipment-filter-stats" style="margin-top:10px;font-size:14px;color:#555;"></div>');
$filterDiv.append($rowDiv).append($stats);
$table.before($filterDiv);
var $typeSelect = $('#filter-type');
var $sourceSelect = $('#filter-source');
function applyFilters() {
var type = $typeSelect.val() || '';
var source = $sourceSelect.val() || '';
var visibleCount = 0;
$rows.each(function() {
var $tds = $(this).find('td');
var rowType = $tds.eq(COL_TYPE).text().trim();
var rowSource = $tds.eq(COL_SOURCE).text().trim();
var match = true;
if (type && rowType !== type) match = false;
if (source && rowSource !== source) match = false;
if (match) {
$(this).show();
visibleCount++;
} else {
$(this).hide();
}
});
$stats.text('当前显示 ' + visibleCount + ' 件装备(共 ' + $rows.length + ' 件)');
var $noRow = $table.find('.no-results-row');
if (visibleCount === 0) {
if ($noRow.length === 0) {
var colSpan = $table.find('thead tr th').length;
$table.find('tbody').append(
$('<tr class="no-results-row">').append(
$('<td>').attr('colspan', colSpan).css({
'text-align': 'center',
'padding': '20px',
'color': '#999'
}).text('没有符合条件的装备')
)
);
}
} else {
$noRow.remove();
}
}
$typeSelect.on('change', applyFilters);
$sourceSelect.on('change', applyFilters);
$('#reset-equipment-filters').on('click', function() {
$typeSelect.val('');
$sourceSelect.val('');
applyFilters();
});
applyFilters();
}
});