Jump to content

User:Theki/clink.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
$(function() {
	const t = mw.Title.newFromText(mw.config.get("wgPageName"));
	if (t.exists && t.getNamespacePrefix() === "User:" || t.getNamespacePrefix() === "User_talk:") {
		const api = new mw.Api();
		api.get({
			action: "query",
			list: ["usercontribs", "users"],
			ucuser: [t.getMain()],
			uclimit: 1,
			usprop: ["editcount", "gender"],
			ususers: [t.getMain()]
		}).done(function(data) {
			const mrc = data.query.usercontribs[0]; // Most recent contribution
			const userinfo = data.query.users[0];
			const h = document.getElementById("firstHeading");
			const d = document.createElement("span");
			let article;
			switch (userinfo.gender) {
				case "male":
					article = "his";
					break;
				case "female":
					article = "her";
					break;
				default:
					article = "their";
			}
			
			
			d.innerHTML = `&nbsp;[<a href="/wiki/Special:Contributions/${t.getMain()}">${userinfo.editcount} edits</a>; ${article} last was on <em><a href="/wiki/${mrc.title}?oldid=${mrc.revid}&diff=prev">${mrc.title.replaceAll(/_/g, " ")}</a></em>]`;
			d.style.fontSize = "10pt";
			h.append(d);
		});
	}
});