Jump to content

MediaWiki:Common.js: Difference between revisions

From Artemis Archive
No edit summary
No edit summary
Line 1: Line 1:
$(function () {
$(function () {
     mw.loader.using('mediawiki.util').then(function () {
     // Only run once everything is loaded
         console.log('[ReportAbuseLink] Starting...');
    const checkInterval = setInterval(function () {
         const headerTools = document.querySelector('.vector-header-end');
        if (headerTools) {
            clearInterval(checkInterval);


        const reportLinkText = '🐾 Report Abuse';
            // Don't insert the link twice
        const reportPageURL = mw.util.getUrl('Report_Animal_Abuse'); // Update if needed
            if (document.querySelector('#report-abuse-link')) return;


        let attempts = 0;
            // Create link
        const maxAttempts = 50;
            const reportLink = document.createElement('a');
            reportLink.id = 'report-abuse-link';
            reportLink.href = mw.util.getUrl('Report_Animal_Abuse'); // Change to your actual target page
            reportLink.textContent = '🐾 Report Abuse';
            reportLink.style.marginLeft = '1em';
            reportLink.style.fontWeight = 'bold';
            reportLink.style.color = '#d33'; // red color for attention


        const tryInsert = function () {
            // Insert before login link if present
             const personalMenu = document.querySelector('#p-personal ul.vector-menu-content-list');
             const loginLink = headerTools.querySelector('a[href*="Special:UserLogin"]');
 
             if (loginLink) {
             if (personalMenu) {
                 headerTools.insertBefore(reportLink, loginLink);
                 if (!document.getElementById('pt-reportabuse')) {
             } else {
                    const li = document.createElement('li');
                 headerTools.appendChild(reportLink);
                    li.id = 'pt-reportabuse';
 
                    const a = document.createElement('a');
                    a.href = reportPageURL;
                    a.textContent = reportLinkText;
                    a.title = 'Report animal abuse to authorities or NGOs';
 
                    li.appendChild(a);
                    personalMenu.appendChild(li);
 
                    console.log('[ReportAbuseLink] Link inserted at the end of personal menu.');
                }
                return true;
             }
 
            if (attempts >= maxAttempts) {
                 console.warn('[ReportAbuseLink] Failed to find personal menu after max attempts.');
                return true;
             }
             }


             return false;
             console.log('[ReportAbuseLink] Inserted into header');
        };
        }
 
    }, 100);
        const interval = setInterval(function () {
            attempts++;
            if (tryInsert()) {
                clearInterval(interval);
                console.log('[ReportAbuseLink] Done.');
            }
        }, 100);
    });
});
});

Revision as of 05:06, 21 April 2025

$(function () {
    // Only run once everything is loaded
    const checkInterval = setInterval(function () {
        const headerTools = document.querySelector('.vector-header-end');
        if (headerTools) {
            clearInterval(checkInterval);

            // Don't insert the link twice
            if (document.querySelector('#report-abuse-link')) return;

            // Create link
            const reportLink = document.createElement('a');
            reportLink.id = 'report-abuse-link';
            reportLink.href = mw.util.getUrl('Report_Animal_Abuse'); // Change to your actual target page
            reportLink.textContent = '🐾 Report Abuse';
            reportLink.style.marginLeft = '1em';
            reportLink.style.fontWeight = 'bold';
            reportLink.style.color = '#d33'; // red color for attention

            // Insert before login link if present
            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);
});