LLWiki正在建设中,欢迎加入我们

“MediaWiki:Gadget-custommenu.js”的版本间差异

来自LLWiki
跳转到导航 跳转到搜索
(// 使用Wikiplus小工具快速编辑)
标签移动版网页编辑 移动版编辑
 
(未显示同一用户的9个中间版本)
第1行: 第1行:
// 由ResourceLoader直接调用,不可使用ES6语法
(function($, mw) {
"use strict";
if( (mw.config.get('skin') == 'vector' && window.customMenuMode == 'mobile') ||
/*global mw, $, wgULS*/
(mw.config.get('skin') == 'minerva' && window.customMenuMode == 'desktop') ) {
const gadgets = mw.gadgets || {},
return;
setting = gadgets.custommenu || {},
}
skin = mw.config.get('skin');
$(function () {
$(function () {
var api = new mw.Api();
if (skin == 'vector' && setting.mode == 'mobile' || skin == 'minerva' && setting.mode == 'desktop') { return; }
api.get( {
const username = mw.config.get( 'wgUserName' ),
'action':'parse',
'page': (window.customMenuSrc || 'user:' + mw.config.get('wgUserName') + '/Sidebar'),
src = setting.src || 'user:' + username + '/Sidebar.json',
menu = $('<div>', {class: 'body', html: $('<ul>')});
'uselang':mw.config.get('wgUserLanguage')
$.get({
} ).then(function(data) {
dataType: 'json',
var navlist = data.parse.text["*"].replace(/\n<!--[\s\S]*-->/g,'');
url: mw.util.getUrl(src, {action: 'raw', ctype: 'application/json'}),
if(mw.config.get('skin') == 'vector') {
cache: setting.cache !== false
$('<div id="p-diy" class="portal" role="navigation" aria-labelledby="p-diy-label">').append('<h3 id="p-diy-label">' + wgULS('自定义', '自定義') + '</h3>').appendTo("#mw-panel");
}).then(function(data) {
$("#p-diy").append('<div class="body">' + navlist + '</div>');
const api = new mw.Api(),
}
dynamicList = data.dynamic ? data.dynamic.map(function(query) {
else {
if (query.type == 'prefixindex') {
navlist = navlist.replace(/<a href(((?!>).)*)>(((?!<\/i>).)*?)<\/a>/g,'<a href$1><i class="fa fa-arrow-circle-right"></i><span>$3</span></a>');
return mw.timedQuery(api, {list: 'allpages', apprefix: query.prefix, apnamespace: query.ns})
var timer = setInterval(function() {
.then(function(res) {
if($('.menu > .hlist').length) {
return res.query.allpages.map(function(page) {
clearInterval(timer);
return {text: page.title, title: page.title};
$(navlist).insertBefore(".menu > .hlist");
});
}
});
}, 100);
}
}
}) : [];
});
if (skin == 'vector') {
});
menu.children().append( data.static.map(function(entry) {
}) (jQuery, mediaWiki);
return $('<li>', {html: $('<a>', {
text: entry.text,
href: entry.title ? mw.util.getUrl( entry.title ) : entry.href
})});
}) );
Promise.allSettled( dynamicList ).then(function(lists) {
menu.append( lists.filter(function(ele) { return ele.status == 'fulfilled'; }).map(function(ele) {
return $('<ul>', {html: ele.value.map(function(entry) {
return $('<li>', {html: $('<a>', {text: entry.text, href: mw.util.getUrl( entry.title )})});
})});
}) );
$('<div>', {class: "portal", role: "navigation"}).append( $('<h3>', {text: wgULS('自定义', '定製')}) )
.append(menu).appendTo( "#mw-panel" );
});
}
else {
menu.children().append( data.static.map(function(entry) {
return $('<li>', {html: $('<a>', {
href: entry.title ? mw.util.getUrl( entry.title ) : entry.href,
class: entry.icon || 'fa fa-arrow-circle-right',
html: $('<span>', {text: entry.text})
})});
}) );
Promise.allSettled( dynamicList ).then(function(lists) {
menu.append( lists.filter(function(ele) { return ele.status == 'fulfilled'; }).map(function(ele) {
return $('<ul>', {html: ele.value.map(function(entry) {
return $('<li>', {html: $('<a>', {
href: mw.util.getUrl( entry.title ),
class: 'fa fa-arrow-circle-right',
html: $('<span>', {text: entry.text})
})});
})});
}) );
$('#mw-mf-page-left').find( ".hlist" ).before( menu.children() );
});
}
});
});
// [[category:编辑工具]] [[category:需要用户权限的小工具]] [[category:桌面版小工具]] [[category:手机版小工具]] [[category:作为模块的小工具]]
// {{DEFAULTSORT:custommenu.js}}

2023年3月17日 (五) 13:23的最新版本

// 由ResourceLoader直接调用,不可使用ES6语法
"use strict";
/*global mw, $, wgULS*/
const gadgets = mw.gadgets || {},
	setting = gadgets.custommenu || {},
	skin = mw.config.get('skin');
$(function () {
	if (skin == 'vector' && setting.mode == 'mobile' || skin == 'minerva' && setting.mode == 'desktop') { return; }
	const username = mw.config.get( 'wgUserName' ),
		src = setting.src || 'user:' + username + '/Sidebar.json',
		menu = $('<div>', {class: 'body', html: $('<ul>')});
	$.get({
		dataType: 'json',
		url: mw.util.getUrl(src, {action: 'raw', ctype: 'application/json'}),
		cache: setting.cache !== false
	}).then(function(data) {
		const api = new mw.Api(),
			dynamicList = data.dynamic ? data.dynamic.map(function(query) {
			if (query.type == 'prefixindex') {
				return mw.timedQuery(api, {list: 'allpages', apprefix: query.prefix, apnamespace: query.ns})
					.then(function(res) {
					return res.query.allpages.map(function(page) {
						return {text: page.title, title: page.title};
					});
				});
			}
		}) : [];
		if (skin == 'vector') {
			menu.children().append( data.static.map(function(entry) {
				return $('<li>', {html: $('<a>', {
					text: entry.text,
					href: entry.title ? mw.util.getUrl( entry.title ) : entry.href
				})});
			}) );
			Promise.allSettled( dynamicList ).then(function(lists) {
				menu.append( lists.filter(function(ele) { return ele.status == 'fulfilled'; }).map(function(ele) {
					return $('<ul>', {html: ele.value.map(function(entry) {
						return $('<li>', {html: $('<a>', {text: entry.text, href: mw.util.getUrl( entry.title )})});
					})});
				}) );
				$('<div>', {class: "portal", role: "navigation"}).append( $('<h3>', {text: wgULS('自定义', '定製')}) )
					.append(menu).appendTo( "#mw-panel" );
			});
		}
		else {
			menu.children().append( data.static.map(function(entry) {
				return $('<li>', {html: $('<a>', {
					href: entry.title ? mw.util.getUrl( entry.title ) : entry.href,
					class: entry.icon || 'fa fa-arrow-circle-right',
					html: $('<span>', {text: entry.text})
				})});
			}) );
			Promise.allSettled( dynamicList ).then(function(lists) {
				menu.append( lists.filter(function(ele) { return ele.status == 'fulfilled'; }).map(function(ele) {
					return $('<ul>', {html: ele.value.map(function(entry) {
						return $('<li>', {html: $('<a>', {
							href: mw.util.getUrl( entry.title ),
							class: 'fa fa-arrow-circle-right',
							html: $('<span>', {text: entry.text})
						})});
					})});
				}) );
				$('#mw-mf-page-left').find( ".hlist" ).before( menu.children() );
			});
		}
	});
});
// [[category:编辑工具]] [[category:需要用户权限的小工具]] [[category:桌面版小工具]] [[category:手机版小工具]] [[category:作为模块的小工具]]
// {{DEFAULTSORT:custommenu.js}}