MediaWiki:Common.js: Difference between revisions
From Artifacts of Capitalism
Created page with "mw.loader.using('mediawiki.util', function () { $(function () { // Only proceed if user is logged in if (!mw.config.get('wgUserName')) return; // Target the dropdown container (the blue guy menu) const personalToolsList = $('.cmln-personal-tools ul'); if (personalToolsList.length) { // Define custom links const links = [ { href: '/index.php?title=Special:Upload', label: 'Upload a File' }, {..." |
No edit summary |
||
| Line 1: | Line 1: | ||
mw.loader.using('mediawiki.util', function () { | mw.loader.using('mediawiki.util', function () { | ||
function addUserMenuLinks() { | |||
// Only proceed if user is logged in | // Only proceed if the user is logged in | ||
if (!mw.config.get('wgUserName')) return; | if (!mw.config.get('wgUserName')) return; | ||
// | // Look for the user menu (the "blue guy") dropdown | ||
const | const $menu = $('.cmln-personal-tools ul'); | ||
if ( | if ($menu.length === 0) { | ||
// | // If not found, try again in 100ms | ||
setTimeout(addUserMenuLinks, 100); | |||
return; | |||
} | |||
// Avoid adding duplicates if already present | |||
if ($menu.data('custom-links-added')) return; | |||
const links = [ | |||
{ | |||
href: '/index.php?title=Special:Upload', | |||
label: 'Upload a File' | |||
}, | |||
{ | |||
href: '/index.php?title=Special:ListFiles', | |||
label: 'All Files' | |||
}, | |||
{ | |||
href: '/index.php?title=Help:Contents', | |||
label: 'Help' | |||
}, | |||
{ | |||
href: '/index.php?title=Special:SpecialPages', | |||
label: 'Special pages' | |||
} | |||
]; | |||
links.forEach(link => { | |||
const $li = $('<li>') | |||
.addClass('mw-list-item') | |||
.append($('<a>').attr('href', link.href).text(link.label)); | |||
$menu.append($li); | |||
}); | |||
// Mark as populated to prevent duplication | |||
$menu.data('custom-links-added', true); | |||
} | |||
$(addUserMenuLinks); | |||
}); | }); | ||
Revision as of 20:29, 14 July 2025
mw.loader.using('mediawiki.util', function () {
function addUserMenuLinks() {
// Only proceed if the user is logged in
if (!mw.config.get('wgUserName')) return;
// Look for the user menu (the "blue guy") dropdown
const $menu = $('.cmln-personal-tools ul');
if ($menu.length === 0) {
// If not found, try again in 100ms
setTimeout(addUserMenuLinks, 100);
return;
}
// Avoid adding duplicates if already present
if ($menu.data('custom-links-added')) return;
const links = [
{
href: '/index.php?title=Special:Upload',
label: 'Upload a File'
},
{
href: '/index.php?title=Special:ListFiles',
label: 'All Files'
},
{
href: '/index.php?title=Help:Contents',
label: 'Help'
},
{
href: '/index.php?title=Special:SpecialPages',
label: 'Special pages'
}
];
links.forEach(link => {
const $li = $('<li>')
.addClass('mw-list-item')
.append($('<a>').attr('href', link.href).text(link.label));
$menu.append($li);
});
// Mark as populated to prevent duplication
$menu.data('custom-links-added', true);
}
$(addUserMenuLinks);
});