Jump to content

MediaWiki:Common.js

From λ LUMENWARD
Revision as of 10:11, 14 December 2025 by Kauku (talk | contribs)

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.
/* =========================================================
   Lumenward: Top-level header links (Vector 2022)
   - GitHub + Discord next to each other
   - Not in dropdown
   ========================================================= */

mw.loader.using(['mediawiki.util'], function () {

  // ====== CHANGE THESE ======
  var GITHUB_URL  = 'https://github.com/YOUR_GITHUB_ORG_OR_REPO';
  var DISCORD_URL = 'https://discord.gg/YOUR_INVITE_CODE';
  // ==========================

  // Find a stable header container (prefer right side, fallback to header)
  var targets = [
    document.querySelector('.mw-header .vector-header-end'),
    document.querySelector('.mw-header .mw-header-user'),
    document.querySelector('.mw-header .vector-user-links'),
    document.querySelector('.mw-header')
  ].filter(Boolean);

  if (!targets.length) return;

  // Remove any existing injected links to avoid duplicates
  ['lumenward-github-link', 'lumenward-discord-link'].forEach(function (id) {
    var el = document.getElementById(id);
    if (el) el.remove();
  });

  function makeLink(id, href, label) {
    var a = document.createElement('a');
    a.id = id;
    a.href = href;
    a.textContent = label;
    a.target = '_blank';
    a.rel = 'noopener';
    a.style.marginRight = '12px';
    a.style.fontWeight = '600';
    a.style.textDecoration = 'none';
    a.style.whiteSpace = 'nowrap';
    return a;
  }

  var github = makeLink('lumenward-github-link', GITHUB_URL, 'GitHub');
  var discord = makeLink('lumenward-discord-link', DISCORD_URL, 'Discord');

  // Insert both at the beginning of the chosen header container
  // (discord first-child, github before it so order becomes GitHub then Discord)
  targets[0].insertBefore(discord, targets[0].firstChild);
  targets[0].insertBefore(github, discord);
});