MediaWiki:Common.js: Difference between revisions
From Starlight wiki
Created page with "→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;..." |
(No difference)
|
Latest revision as of 20:58, 12 January 2025
/* 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>`);
}
}
});
});
