Page MenuHomePhabricator
Paste P96473

User script to add links for Service Catalog
ActivePublic

Authored by MLechvien-WMF on Fri, Sep 18, 4:07 PM.
Project Tags
None
Referenced Files
F103588431: User script to add links for Service Catalog
Fri, Sep 18, 4:07 PM
Subscribers
None
// ==UserScript==
// @name MediaWiki Service Catalog Row Anchors
// @namespace https://www.mediawiki.org/
// @version 1.0
// @description Adds a direct anchor link to each row with an ID in the Wikimedia Service Catalog table.
// @match https://www.mediawiki.org/wiki/Wikimedia_Production/Service_Catalog*
// @grant none
// ==/UserScript==
(function() {
'use strict';
// Find all table rows containing an ID attribute
const rows = document.querySelectorAll('tr[id]');
rows.forEach(row => {
const id = row.id;
const firstCell = row.querySelector('th, td');
if (!firstCell) return;
// Create the anchor link element
const anchor = document.createElement('a');
anchor.href = '#' + id;
anchor.textContent = ' 🔗';
anchor.title = 'Direct link to ' + id;
anchor.style.fontSize = '0.85em';
anchor.style.textDecoration = 'none';
anchor.style.opacity = '0.5';
anchor.style.marginLeft = '6px';
// Hover visibility effect
anchor.addEventListener('mouseenter', () => anchor.style.opacity = '1');
anchor.addEventListener('mouseleave', () => anchor.style.opacity = '0.5');
// Append the anchor link to the end of the first column cell
firstCell.appendChild(anchor);
});
})();