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.
// Wait for the page elements to be ready $(function() { // Use mw.loader.using to ensure necessary MediaWiki JS utilities are loaded mw.loader.using( 'mediawiki.util' ).then( function () { console.log( '[ReportAbuseLink] Attempting to add link...' ); // Log message for console // Use the selector for the list containing personal tools based on inspection const personalToolsList = document.querySelector( '#p-personal ul.vector-menu-content-list' ); // Use the correct ID for the login list item based on inspection const loginItem = document.querySelector( '#pt-login-2' ); // Check if we found the list where links should go if ( !personalToolsList ) { console.log( '[ReportAbuseLink] Could not find personal tools list (#p-personal ul.vector-menu-content-list).' ); return; // Exit if list element is not found } console.log( '[ReportAbuseLink] Found personal tools list.' ); // --- Configuration --- const reportPageName = 'Report_Animal_Abuse'; // **CHANGE THIS** if your wiki page has a different name const linkText = 'Report Abuse'; // Text displayed for the link // --- End Configuration --- // Create the new list item (<li>) const li = document.createElement( 'li' ); li.id = 'pt-reportabuse'; // Set an ID for the new list item // Create the link element (<a>) const link = document.createElement( 'a' ); link.href = mw.util.getUrl( reportPageName ); // Generates correct URL for the wiki page link.textContent = linkText; // link.title = 'Report animal abuse'; // Optional: Add a tooltip title // Add the link inside the list item li.appendChild( link ); // Try to insert the new list item before the 'Log in' list item if ( loginItem && loginItem.parentNode === personalToolsList ) { console.log( '[ReportAbuseLink] Found login item (#pt-login-2), inserting link before it.' ); personalToolsList.insertBefore( li, loginItem ); } else { // Fallback if login item isn't found (e.g., user is logged in) or has unexpected parent // Try appending to the end of the list as a fallback console.log( '[ReportAbuseLink] Login item (#pt-login-2) not found or has wrong parent. Appending link to end.' ); personalToolsList.appendChild( li ); // Note: Inserting before 'Preferences' or after 'ULS' dynamically when logged in // requires finding those elements reliably too. Appending is a simpler fallback. } }); });