MediaWiki:Gadget-ShowAvatar.js
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Press Ctrl-F5.
"use strict";
// <pre>
$(() => {
const commonsUrl = new mw.Uri(`${mw.config.get("wgServer")}${mw.config.get("wgScriptPath")}/`);
commonsUrl.query.user = mw.config.get("wgPageName").replace(/^user:/i, "");
commonsUrl.path = "/extensions/Avatar/avatar.php";
const imgUrl = new mw.Uri(commonsUrl);
imgUrl.query.user = mw.config.get("wgUserName");
const img = $("<img>").attr("src", imgUrl);
const link = $("<a>").attr("href", `${mw.config.get("wgServer")}/Special:UploadAvatar`).append(img);
$("#pt-userpage").before($('<li id="pt-avatar"></li>').append(link));
if (mw.config.get("wgNamespaceNumber") === 2 && !mw.config.get("wgPageName").includes("/")) {
const hrefUrl = new mw.Uri(commonsUrl);
hrefUrl.path = "/Special:Viewavatar";
const srcUrl = new mw.Uri(commonsUrl);
$(".ns-2 #firstHeading").prepend($("<a/>").attr({
href: hrefUrl,
title: "查看头像",
}).prepend($("<img/>").attr("src", srcUrl).css({
width: "1.2em",
height: "1.2em",
"border-radius": "10px",
padding: "4px",
})));
}
});
// </pre>