跳转到内容
打开/关闭菜单
打开/关闭外观设置菜单
打开/关闭个人菜单
未登录
未登录用户的IP地址会在进行任意编辑后公开展示。

MediaWiki:Common.js

MediaWiki界面页面
Admin留言 | 贡献2026年8月19日 (三) 17:06的版本 (注入顶栏横向导航)
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)

注意:在发布之后,您可能需要清除浏览器缓存才能看到所作出的更改的影响。

  • Firefox或Safari:按住Shift的同时单击刷新,或按Ctrl-F5Ctrl-R(Mac为⌘-R
  • Google Chrome:Ctrl-Shift-R(Mac为⌘-Shift-R
  • Edge:按住Ctrl的同时单击刷新,或按Ctrl-F5
/* 在 Citizen 顶栏注入横向导航(主页 / 全部条目 / 分类 / 最近更改 / 工具箱) */
( function () {
	'use strict';

	var LINKS = [
		{ text: '主页', href: mw.util.getUrl( '首页' ), match: /^(首页|Main_Page)$/ },
		{ text: '全部条目', href: mw.util.getUrl( 'Special:AllPages' ), match: /^Special:AllPages$/i },
		{ text: '分类', href: mw.util.getUrl( 'Special:Categories' ), match: /^Special:Categories$/i },
		{ text: '最近更改', href: mw.util.getUrl( 'Special:RecentChanges' ), match: /^Special:RecentChanges$/i },
		{ text: '工具箱', href: mw.util.getUrl( 'Special:SpecialPages' ), match: /^Special:SpecialPages$/i }
	];

	function build() {
		var header = document.querySelector( '.citizen-header' );
		if ( !header || header.querySelector( '.kuke-topnav' ) ) {
			return;
		}

		var page = mw.config.get( 'wgPageName' );
		var nav = document.createElement( 'nav' );
		nav.className = 'kuke-topnav citizen-header__item';
		nav.setAttribute( 'aria-label', '主导航' );

		LINKS.forEach( function ( item ) {
			var a = document.createElement( 'a' );
			a.className = 'kuke-topnav__link';
			a.href = item.href;
			a.textContent = item.text;
			if ( item.match.test( page ) ) {
				a.classList.add( 'kuke-topnav__link--active' );
				a.setAttribute( 'aria-current', 'page' );
			}
			nav.appendChild( a );
		} );

		var logo = header.querySelector( '.citizen-header__logo' );
		if ( logo && logo.nextSibling ) {
			header.insertBefore( nav, logo.nextSibling );
		} else {
			header.appendChild( nav );
		}
	}

	if ( document.readyState === 'loading' ) {
		document.addEventListener( 'DOMContentLoaded', build );
	} else {
		build();
	}
}() );