MediaWiki:Common.js: Difference between revisions
Appearance
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
$(function () { | $(function () { | ||
// | // Wait until the header tools are available | ||
const checkInterval = setInterval(function () { | const checkInterval = setInterval(function () { | ||
const headerTools = document.querySelector('.vector-header-end'); | const headerTools = document.querySelector('.vector-header-end'); | ||
Line 6: | Line 6: | ||
clearInterval(checkInterval); | clearInterval(checkInterval); | ||
// | // Avoid adding the link multiple times | ||
if (document.querySelector('#report-abuse-link')) return; | if (document.querySelector('#report-abuse-link')) return; | ||
// Create link | // Create the link element | ||
const reportLink = document.createElement('a'); | const reportLink = document.createElement('a'); | ||
reportLink.id = 'report-abuse-link'; | reportLink.id = 'report-abuse-link'; | ||
reportLink.href = mw.util.getUrl('Report_Animal_Abuse'); // | reportLink.href = mw.util.getUrl('Report_Animal_Abuse'); // Update with your actual page | ||
reportLink.textContent = '🐾 Report Abuse'; | reportLink.textContent = '🐾 Report Abuse'; | ||
reportLink.style.marginLeft = '1em'; | reportLink.style.marginLeft = '1em'; | ||
reportLink.style.fontWeight = 'bold'; | reportLink.style.fontWeight = 'bold'; | ||
reportLink.style.color = '#d33'; // | reportLink.style.color = '#d33'; // Red color for visibility | ||
// Insert before login link if | // Insert the link before the login link if it exists | ||
const loginLink = headerTools.querySelector('a[href*="Special:UserLogin"]'); | const loginLink = headerTools.querySelector('a[href*="Special:UserLogin"]'); | ||
if (loginLink) { | if (loginLink) { |
Revision as of 05:13, 21 April 2025
$(function () { // Wait until the header tools are available const checkInterval = setInterval(function () { const headerTools = document.querySelector('.vector-header-end'); if (headerTools) { clearInterval(checkInterval); // Avoid adding the link multiple times if (document.querySelector('#report-abuse-link')) return; // Create the link element const reportLink = document.createElement('a'); reportLink.id = 'report-abuse-link'; reportLink.href = mw.util.getUrl('Report_Animal_Abuse'); // Update with your actual page reportLink.textContent = '🐾 Report Abuse'; reportLink.style.marginLeft = '1em'; reportLink.style.fontWeight = 'bold'; reportLink.style.color = '#d33'; // Red color for visibility // Insert the link before the login link if it exists const loginLink = headerTools.querySelector('a[href*="Special:UserLogin"]'); if (loginLink) { headerTools.insertBefore(reportLink, loginLink); } else { headerTools.appendChild(reportLink); } console.log('[ReportAbuseLink] Inserted into header'); } }, 100); });