Jump to content

MediaWiki:Common.js: Difference between revisions

From λ LUMENWARD
No edit summary
No edit summary
Tag: Reverted
Line 1: Line 1:
/* =========================================================
/* =========================================================
   Lumenward: Top-level header links (Vector 2022)
   Lumenward: GitHub link in top-right header (Vector 2022)
  - GitHub + Discord next to each other
   - Not in dropdown
   - Not in dropdown
  - Not near logo
   ========================================================= */
   ========================================================= */


mw.loader.using(['mediawiki.util'], function () {
mw.hook('wikipage.content').add(function () {
  var url = 'https://github.com/YOUR_GITHUB_ORG_OR_REPO'; // <-- CHANGE THIS
  var text = 'GitHub';


   // ====== CHANGE THESE ======
   // Remove any previously inserted link (from older scripts)
   var GITHUB_URL  = 'https://github.com/YOUR_GITHUB_ORG_OR_REPO';
   var old = document.getElementById('lumenward-github-link');
   var DISCORD_URL = 'https://discord.gg/YOUR_INVITE_CODE';
   if (old) old.remove();
  // ==========================


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


   if (!targets.length) return;
   if (!right) return;


   // Remove any existing injected links to avoid duplicates
   var a = document.createElement('a');
   ['lumenward-github-link', 'lumenward-discord-link'].forEach(function (id) {
   a.id = 'lumenward-github-link';
    var el = document.getElementById(id);
  a.href = url;
    if (el) el.remove();
  a.textContent = text;
   });
  a.target = '_blank';
   a.rel = 'noopener';


   function makeLink(id, href, label) {
   // Minimal styling; final color handled in CSS
    var a = document.createElement('a');
  a.style.marginRight = '12px';
    a.id = id;
  a.style.fontWeight = '600';
    a.href = href;
  a.style.whiteSpace = 'nowrap';
    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');
   // Insert as the FIRST item in the right-side header area
  var discord = makeLink('lumenward-discord-link', DISCORD_URL, 'Discord');
   right.insertBefore(a, right.firstChild);
 
   // 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);
});
});

Revision as of 11:28, 14 December 2025

/* =========================================================
   Lumenward: GitHub link in top-right header (Vector 2022)
   - Not in dropdown
   - Not near logo
   ========================================================= */

mw.hook('wikipage.content').add(function () {
  var url = 'https://github.com/YOUR_GITHUB_ORG_OR_REPO'; // <-- CHANGE THIS
  var text = 'GitHub';

  // Remove any previously inserted link (from older scripts)
  var old = document.getElementById('lumenward-github-link');
  if (old) old.remove();

  // Vector 2022 right-side header container (user icons live here)
  var right =
    document.querySelector('.mw-header .vector-header-end') ||
    document.querySelector('.mw-header .mw-header-user') ||
    document.querySelector('.mw-header .vector-user-links');

  if (!right) return;

  var a = document.createElement('a');
  a.id = 'lumenward-github-link';
  a.href = url;
  a.textContent = text;
  a.target = '_blank';
  a.rel = 'noopener';

  // Minimal styling; final color handled in CSS
  a.style.marginRight = '12px';
  a.style.fontWeight = '600';
  a.style.whiteSpace = 'nowrap';

  // Insert as the FIRST item in the right-side header area
  right.insertBefore(a, right.firstChild);
});