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 () {
   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;


     // Target the dropdown container (the blue guy menu)
     // Look for the user menu (the "blue guy") dropdown
     const personalToolsList = $('.cmln-personal-tools ul');
     const $menu = $('.cmln-personal-tools ul');


     if (personalToolsList.length) {
     if ($menu.length === 0) {
       // Define custom links
       // If not found, try again in 100ms
      const links = [
      setTimeout(addUserMenuLinks, 100);
        {
      return;
          href: '/index.php?title=Special:Upload',
    }
          label: 'Upload a File'
 
        },
    // Avoid adding duplicates if already present
        {
    if ($menu.data('custom-links-added')) return;
          href: '/index.php?title=Special:ListFiles',
 
          label: 'All Files'
    const links = [
        },
      {
        {
        href: '/index.php?title=Special:Upload',
          href: '/index.php?title=Help:Contents',
        label: 'Upload a File'
          label: 'Help'
      },
        },
      {
        {
        href: '/index.php?title=Special:ListFiles',
          href: '/index.php?title=Special:SpecialPages',
        label: 'All Files'
          label: 'Special pages'
      },
         }
      {
       ];
        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);
    });


      // Inject each link into the dropdown
    // Mark as populated to prevent duplication
      links.forEach(link => {
    $menu.data('custom-links-added', true);
        const li = $('<li>')
  }
          .addClass('mw-list-item')
 
          .append(
   $(addUserMenuLinks);
            $('<a>')
              .attr('href', link.href)
              .text(link.label)
          );
        personalToolsList.append(li);
      });
    }
   });
});
});

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);
});