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.
// <nowiki>
mw.loader.using([ 'mediawiki.api', 'mediawiki.jqueryMsg' ], function() {
mw.loader.load(`${window.location.origin + mw.config.get("wgScriptPath")}/index.php?title=User:Awesome_Aasim/usergroups.css&action=raw&ctype=text/css`, "text/css");
mw.loader.load(`${window.location.origin + mw.config.get("wgScriptPath")}/index.php?title=MediaWiki:Usergroups.css&action=raw&ctype=text/css`, "text/css");
if (!window.userGroupsLoaded) {
window.userGroupsLoaded = true;
$(document).ready(async function() {
let user;
if (mw.config.get("wgNamespaceNumber") == 2 || mw.config.get("wgNamespaceNumber") == 3) {
user = mw.config.get("wgTitle").split("/")[0];
} else if (mw.config.get("wgNamespaceNumber") == -1) {
user = mw.config.get("wgTitle").split("/")[1] ? mw.config.get("wgTitle").split("/")[1] : null;
}
if (user) {
$.get(mw.config.get('wgScriptPath') + '/api.php', {
action: "query",
list: "users",
ususers: user,
usprop: "groups|blockinfo",
format: "json"
}).done(async function(res) {
if (!res.error) {
var userdata = res.query.users[0];
var usergroups = "";
var messagesArray = [];
var linksArray = [];
for (let group of userdata.groups) {
messagesArray.push(`group-${group}-member`);
linksArray.push(`grouppage-${group}`);
}
messagesArray.push('blockedtitle');
await new mw.Api().loadMessagesIfMissing(messagesArray);
await new mw.Api().loadMessagesIfMissing(linksArray, {amlang: mw.config.get("wgContentLanguage")});
$("#siteSub").text("");
$("#siteSub").css("display", "block");
$("#siteSub").append($('<div style="font-family:sans-serif;font-style: normal;" id="usergroups"></div>'));
if (userdata.blockid) {
// readd block ID
$("#firstHeading").append(` (<b><a href="${mw.config.get("wgScriptPath")}/index.php?title=Special:BlockList&wpTarget=%23${userdata.blockid}">${mw.message(`blockedtitle`)}</a></b>)`);
}
for (let group of userdata.groups) {
if (group == "*" || group == "user") continue;
$("#usergroups").append(`<span class="usergroup usergroup-${group}"><a href="${mw.config.get("wgArticlePath").replace(/\$1/g, mw.message(`grouppage-${group}`))}">${mw.message(`group-${group}-member`).parse()}</a></span> `);
}
}
});
}
window.userGroupsCache = {};
$(".mw-userlink").each(async function() {
let that = this;
let user = $(this).text();
if (window.userGroupsCache[user]) {
return;
} else {
window.userGroupsCache[user] = true;
}
let res = typeof window.userGroupsCache[user] == "object" ? window.userGroupsCache[user] : await $.get(mw.config.get('wgScriptPath') + '/api.php', {
action: "query",
list: "users",
ususers: user,
usprop: "groups|blockinfo",
format: "json"
});
if (res.error) {
delete window.userGroupsCache[user];
} else {
window.userGroupsCache[user] = res;
var userdata = res.query.users[0];
var classString = "";
classString += 'usergroup ';
if (userdata.blockid) {
classString += "usergroup-blocked ";
}
for (let group of userdata.groups) {
if (group == "*" || group == "user") continue;
classString += `usergroup-${group} `;
}
$(`.mw-userlink:contains(${user})`).each(function() {
if ($(this).text() != user) return;
let $enclosure = $('<span></span>');
$(this).before($enclosure);
$enclosure.append($(this));
$enclosure.addClass(classString);
})
}
});
});
}
});
// </nowiki>
You must be logged in to post a comment.