MediaWiki:Common.js
Appearance
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.
$(function() { mw.loader.using( 'mediawiki.util' ).then( function () { console.log( '[ReportAbuseLink] Initializing link insertion...' ); const reportPageName = 'Report_Animal_Abuse'; // **CHANGE THIS** if needed const linkText = 'Report Abuse'; let attempts = 0; const maxAttempts = 50; // Try for 5 seconds (50 * 100ms) const interval = 100; // Check every 100ms const tryInsertLink = function() { attempts++; console.log( '[ReportAbuseLink] Attempt #' + attempts ); const personalToolsList = document.querySelector( '#p-personal ul.vector-menu-content-list' ); const loginItem = document.querySelector( '#pt-login-2' ); if ( personalToolsList && loginItem && loginItem.parentNode === personalToolsList ) { // Both list and login item found in correct place! console.log( '[ReportAbuseLink] Found list and #pt-login-2. Inserting link.' ); const reportPageTitle = mw.Title.newFromText( reportPageName ); // Use mw.Title if available if (!reportPageTitle) return true; // Stop if title invalid const li = document.createElement( 'li' ); li.id = 'pt-reportabuse'; const link = document.createElement( 'a' ); link.href = reportPageTitle.getUrl(); // Use mw object method link.textContent = linkText; li.appendChild( link ); personalToolsList.insertBefore( li, loginItem ); return true; // Indicate success } else if ( attempts >= maxAttempts ) { // Max attempts reached, fallback to appending if list found console.log( '[ReportAbuseLink] Max attempts reached. #pt-login-2 not found correctly. Appending to end if list exists.' ); if (personalToolsList) { const reportPageTitle = mw.Title.newFromText( reportPageName ); if (!reportPageTitle) return true; const li = document.createElement( 'li' ); li.id = 'pt-reportabuse'; const link = document.createElement( 'a' ); link.href = reportPageTitle.getUrl(); link.textContent = linkText; li.appendChild( link ); personalToolsList.appendChild(li); } else { console.log( '[ReportAbuseLink] Personal tools list not found even on fallback.' ); } return true; // Indicate fallback finished } return false; // Indicate insertion not yet successful }; // Start the interval timer const checkInterval = setInterval( function() { if ( tryInsertLink() ) { clearInterval( checkInterval ); // Stop checking once inserted or max attempts reached console.log( '[ReportAbuseLink] Link insertion process finished.' ); } }, interval ); }); });