MediaWiki:Minerva.js: Difference between revisions
Jump to navigation
Jump to search
Chinaenglish (talk | contribs) No edit summary |
Chinaenglish (talk | contribs) No edit summary |
||
| (12 intermediate revisions by the same user not shown) | |||
| Line 41: | Line 41: | ||
var group1 = [ | var group1 = [ | ||
{ text: '3500Word', url: 'http://www.chinaenglish.com/index.php?title=3500Word' }, | { text: '3500Word', url: 'http://www.chinaenglish.com/index.php?title=3500Word' }, | ||
{ text: ' | { text: 'Coined Words', url: 'https://www.chinaenglish.com/index.php?title=Category:Coined_Words' }, | ||
{ text: ' | { text: 'China Travel Phrases', url: 'https://www.chinaenglish.com/index.php?title=Category:China_Travel_Phrases' }, | ||
{ text: 'Africa Work Phrases', url: 'https://www.chinaenglish.com/index.php?title=Category:Africa_Work_Phrases' } | |||
]; | ]; | ||
var group2 = [ | var group2 = [ | ||
{ text: ' | { text: 'ZH Pros/Cons', url: 'http://www.chinaenglish.com/index.php?title=Category:ZH_Pros/Cons' }, | ||
{ text: 'EN Pros/Cons', url: 'http://www.chinaenglish.com/index.php?title=Category: | { text: 'EN Pros/Cons', url: 'http://www.chinaenglish.com/index.php?title=Category:EN_Pros/Cons' }, | ||
{ text: ' | { text: 'Articles', url: 'http://www.chinaenglish.com/index.php?title=Category:Articles' } | ||
]; | ]; | ||
Latest revision as of 23:33, 21 November 2026
/* All JavaScript here will be loaded for users of the MinervaNeue skin */
//viesz88开始端
/* 完美融入 Minerva 原生样式的菜单注入脚本(全站生效) */
( function ( $, mw ) {
'use strict';
mw.loader.using( ['mediawiki.util', 'mediawiki.page.ready'] ).then( function () {
var timer = setInterval( function () {
// 定位到包含 Random 链接的 <a>
var $randomLink = $( '#mw-mf-page-left a[href*="Special:Random"]' ).first();
if ( !$randomLink.length ) return;
// 定位到包含 Settings 链接的 <a>
var $settingsLink = $( '#mw-mf-page-left a[href*="MobileOptions"], #mw-mf-page-left a[href*="Preferences"]' ).first();
if ( !$settingsLink.length ) return;
clearInterval( timer );
var $randomLi = $randomLink.closest( 'li' );
var $settingsLi = $settingsLink.closest( 'li' );
// --- 核心技巧:克隆现有的 <li> 作为模板 ---
// 这样自动继承了 font-size, color, padding, 甚至 border-bottom (细黑线)
var $template = $randomLi.clone();
// 清理模板中的旧图标和旧文字,并加上我们自己的类名以便 CSS 控制
$template.find( 'a' )
.removeClass( function ( index, className ) {
// 移除类似 mw-ui-icon-minerva-xxx 的具体图标类,避免显示骰子图标
return ( className.match( /(^|\s)mw-ui-icon-[^\s]+/g ) || [] ).join( ' ' );
})
.addClass( 'custom-custom-menu-item' )
.attr( 'href', '#' )
.find( 'span' ).text( '' );
// --- 定义你要添加的链接数据 ---
var group1 = [
{ text: '3500Word', url: 'http://www.chinaenglish.com/index.php?title=3500Word' },
{ text: 'Coined Words', url: 'https://www.chinaenglish.com/index.php?title=Category:Coined_Words' },
{ text: 'China Travel Phrases', url: 'https://www.chinaenglish.com/index.php?title=Category:China_Travel_Phrases' },
{ text: 'Africa Work Phrases', url: 'https://www.chinaenglish.com/index.php?title=Category:Africa_Work_Phrases' }
];
var group2 = [
{ text: 'ZH Pros/Cons', url: 'http://www.chinaenglish.com/index.php?title=Category:ZH_Pros/Cons' },
{ text: 'EN Pros/Cons', url: 'http://www.chinaenglish.com/index.php?title=Category:EN_Pros/Cons' },
{ text: 'Articles', url: 'http://www.chinaenglish.com/index.php?title=Category:Articles' }
];
// 生成节点的辅助函数
function buildItem( data ) {
var $newLi = $template.clone();
$newLi.find( 'a' ).attr( 'href', data.url ).find( 'span' ).text( data.text );
return $newLi;
}
// --- 插入第一组:viesz1, 2, 3 ---
// 插在 Random 后面。因为是在同一个 <ul> 里,原生的细黑线会自动应用。
var $current = $randomLi;
group1.forEach( function ( data ) {
var $newLi = buildItem( data );
$current.after( $newLi );
$current = $newLi; // 更新游标,保证顺序是 1, 2, 3
});
// --- 插入第二组:unooo1, 2, 3 ---
// 插在 Settings 前面。
// 因为 Settings 通常在另一个新的 <ul> 里,插在它前面相当于插入了新的列表组,
// Minerva 会自动在两组 <ul> 之间渲染出 3毫米的粗灰线。
group2.reverse().forEach( function ( data ) {
var $newLi = buildItem( data );
$settingsLi.before( $newLi );
});
}, 100 );
});
} )( jQuery, mediaWiki );
//viesz88结束端