MediaWiki:Common.js: Difference between revisions
Appearance
Created page with "→Any JavaScript here will be loaded for all users on every page load.: →========================================================= Lumenward: Add GitHub link to personal tools (top right) =========================================================: mw.loader.using('mediawiki.util', function () { var link = mw.util.addPortletLink( 'p-personal', // personal tools portlet 'https://github.com/YOUR_GITHUB_ORG', // <-- C..." |
No edit summary |
||
| Line 1: | Line 1: | ||
/* ========================================================= | /* ========================================================= | ||
Lumenward: Add GitHub link | Lumenward: Add a top-level GitHub link in the header (Vector 2022) | ||
========================================================= */ | ========================================================= */ | ||
mw.loader.using('mediawiki.util', function () { | mw.loader.using(['mediawiki.util'], function () { | ||
var | var url = 'https://github.com/YOUR_GITHUB_ORG_OR_REPO'; // <-- CHANGE THIS | ||
var text = 'GitHub'; | |||
// Vector 2022 header right area (try a few known containers) | |||
' | 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; | |||
// Avoid duplicates if cache reloads | |||
if (document.getElementById('lumenward-github-link')) return; | |||
var a = document.createElement('a'); | |||
a.id = 'lumenward-github-link'; | |||
a.href = url; | |||
a.textContent = text; | |||
a.target = '_blank'; | |||
a.rel = 'noopener'; | |||
a.style.marginRight = '12px'; | |||
a.style.fontWeight = '600'; | |||
a.style.textDecoration = 'none'; | |||
if | // Insert before the user menu area if possible; otherwise append to header end | ||
targets[0].insertBefore(a, targets[0].firstChild); | |||
}); | }); | ||
Revision as of 09:56, 14 December 2025
/* =========================================================
Lumenward: Add a top-level GitHub link in the header (Vector 2022)
========================================================= */
mw.loader.using(['mediawiki.util'], function () {
var url = 'https://github.com/YOUR_GITHUB_ORG_OR_REPO'; // <-- CHANGE THIS
var text = 'GitHub';
// Vector 2022 header right area (try a few known containers)
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;
// Avoid duplicates if cache reloads
if (document.getElementById('lumenward-github-link')) return;
var a = document.createElement('a');
a.id = 'lumenward-github-link';
a.href = url;
a.textContent = text;
a.target = '_blank';
a.rel = 'noopener';
a.style.marginRight = '12px';
a.style.fontWeight = '600';
a.style.textDecoration = 'none';
// Insert before the user menu area if possible; otherwise append to header end
targets[0].insertBefore(a, targets[0].firstChild);
});