MediaWiki:Common.js
From Starlight wiki
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)
- Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
/* Any JavaScript here will be loaded for all users on every page load. */
$(document).ready(function () {
const username = mw.config.get('wgTitle');
$.getJSON(`/w/api.php?action=query&list=users&ususers=${encodeURIComponent(username)}&usprop=groups&format=json`, function (data) {
if (data && data.query && data.query.users && data.query.users.length > 0) {
const user = data.query.users[0];
const groups = user.groups;
const groupsString = groups.join(", ");
const displayElement = $("#user-rights-display");
if (displayElement.length > 0) {
displayElement.text(groupsString);
} else {
$("body").prepend(`<div id="user-rights-display">User rights: ${groupsString}</div>`);
}
}
});
});
