MediaWiki:Common.js:修订间差异
MediaWiki界面页面
更多操作
导航注入目标改为 .citizen-header__start |
顶部导航接入百科主线栏目 |
||
| 第7行: | 第7行: | ||
var LINKS = [ | var LINKS = [ | ||
{ text: '首页', page: '首页', match: /^(首页|Main_Page)$/ }, | { text: '首页', page: '首页', match: /^(首页|Main_Page)$/ }, | ||
{ text: '子服一览', page: '子服一览', match: /^(子服一览|趣味生存|粘液空岛|纯净生存|机械动力|职业战争|起床战争|僵尸末日|避暑山庄)(\/|$)/ }, | |||
{ text: '总规章', page: 'KukeMC群组服总规章', match: /^KukeMC群组服总规章(\/|$)/ }, | |||
{ text: '常见问题', page: '服务器常见问题', match: /^服务器常见问题(\/|$)/ }, | |||
{ text: '历史资料', page: '历史资料展览馆', match: /^历史资料展览馆(\/|$)/ }, | |||
{ text: '全部条目', page: 'Special:AllPages', match: /^Special:AllPages$/i }, | { text: '全部条目', page: 'Special:AllPages', match: /^Special:AllPages$/i }, | ||
{ text: '分类', page: 'Special:Categories', match: /^Special:Categories$/i }, | { text: '分类', page: 'Special:Categories', match: /^Special:Categories$/i }, | ||
{ text: '最近更改', page: 'Special:RecentChanges', match: /^Special:RecentChanges | { text: '最近更改', page: 'Special:RecentChanges', match: /^Special:RecentChanges$/i } | ||
]; | ]; | ||
2026年8月19日 (三) 21:58的版本
/* 在 Citizen 顶栏的官方预留槽位 .citizen-header__start 内注入横向主导航。
注意:不要插到 .citizen-header 根节点上——那里是 logo / 搜索 / 抽屉的 flex 行,
插进去会跟它们抢空间导致错位。__start 是皮肤留空的导航槽。 */
( function () {
'use strict';
var LINKS = [
{ text: '首页', page: '首页', match: /^(首页|Main_Page)$/ },
{ text: '子服一览', page: '子服一览', match: /^(子服一览|趣味生存|粘液空岛|纯净生存|机械动力|职业战争|起床战争|僵尸末日|避暑山庄)(\/|$)/ },
{ text: '总规章', page: 'KukeMC群组服总规章', match: /^KukeMC群组服总规章(\/|$)/ },
{ text: '常见问题', page: '服务器常见问题', match: /^服务器常见问题(\/|$)/ },
{ text: '历史资料', page: '历史资料展览馆', match: /^历史资料展览馆(\/|$)/ },
{ text: '全部条目', page: 'Special:AllPages', match: /^Special:AllPages$/i },
{ text: '分类', page: 'Special:Categories', match: /^Special:Categories$/i },
{ text: '最近更改', page: 'Special:RecentChanges', match: /^Special:RecentChanges$/i }
];
function build() {
var slot = document.querySelector( '.citizen-header__start' );
if ( !slot || slot.querySelector( '.kuke-nav' ) ) {
return;
}
var page = mw.config.get( 'wgPageName' );
var nav = document.createElement( 'nav' );
nav.className = 'kuke-nav';
nav.setAttribute( 'aria-label', '主导航' );
LINKS.forEach( function ( item ) {
var a = document.createElement( 'a' );
a.className = 'kuke-nav__link';
a.href = mw.util.getUrl( item.page );
a.textContent = item.text;
if ( item.match.test( page ) ) {
a.classList.add( 'kuke-nav__link--active' );
a.setAttribute( 'aria-current', 'page' );
}
nav.appendChild( a );
} );
slot.appendChild( nav );
}
if ( document.readyState === 'loading' ) {
document.addEventListener( 'DOMContentLoaded', build );
} else {
build();
}
}() );