MediaWiki:Gadget-ShowAvatar.js
注意:这类代码页面在保存之后,您可能需要清除浏览器缓存才能看到所作出的变更的影响。
- 按住
CTRL+SHIFT+DEL 或 ⌘-Shift-R来清除缓存! - 或尝试在地址栏的地址最后添加代码
?_=1来访问最新页面。 - 你还可以在设置中勾选小工具在页面右上角添加清除缓存按钮!
$(function() {
var username = mw.config.get('wgUserName');
var pageName = mw.config.get("wgPageName").replace(/^user:/i, '');
// The new BlueSpice Avatar URL format
var avatarUrlBase = '/rest.php/mws/v1/dynamic-file-dispatcher/userprofileimage?username=';
// 1. Top right personal menu avatar
if ( username ) {
var img = $('<img>')
.attr('src', avatarUrlBase + encodeURIComponent(username))
.on('error', function() { img.attr('src', '/index.php/Special:FilePath/Moehime.jpg') })
.css({
width: '1.2em',
height: '1.2em',
'border-radius': '10px',
'vertical-align': 'middle',
'margin-right': '4px'
});
var link = $('<a>')
// BlueSpice Avatars uses the UserProfile page for uploads, not Special:上传头像
.attr('href', '/Special:UserProfile')
.append(img);
$('#pt-userpage').before($('<li id="pt-avatar"></li>').append(link));
}
// 2. Avatar next to the title on User pages
if (mw.config.get("wgNamespaceNumber") === 2 && !mw.config.get("wgPageName").includes("/")) {
$('.ns-2 #firstHeading').prepend(
$('<a>').attr({
href: '/Special:UserProfile/' + encodeURIComponent(pageName),
title: '查看头像'
}).prepend(
$('<img>')
.attr('src', avatarUrlBase + encodeURIComponent(pageName))
.css({
width: '1.2em',
height: '1.2em',
'border-radius': '10px',
padding: '4px'
})
)
);
}
});