Jump to content

MediaWiki:Common.js: Difference between revisions

From Artemis Archive
No edit summary
No edit summary
Line 4: Line 4:


         const reportLinkText = '🐾 Report Abuse';
         const reportLinkText = '🐾 Report Abuse';
         const reportPageURL = mw.util.getUrl('Report_Animal_Abuse'); // Change if your page name differs
         const reportPageURL = mw.util.getUrl('Report_Animal_Abuse'); // Update if needed


         let attempts = 0;
         let attempts = 0;
Line 11: Line 11:
         const tryInsert = function () {
         const tryInsert = function () {
             const personalMenu = document.querySelector('#p-personal ul.vector-menu-content-list');
             const personalMenu = document.querySelector('#p-personal ul.vector-menu-content-list');
            const loginItem = document.querySelector('#pt-login-2');


             if (personalMenu && loginItem) {
             if (personalMenu) {
                 console.log('[ReportAbuseLink] Found login item. Inserting before it.');
                 if (!document.getElementById('pt-reportabuse')) {
                const li = document.createElement('li');
                    const li = document.createElement('li');
                li.id = 'pt-reportabuse';
                    li.id = 'pt-reportabuse';


                const a = document.createElement('a');
                    const a = document.createElement('a');
                a.href = reportPageURL;
                    a.href = reportPageURL;
                a.textContent = reportLinkText;
                    a.textContent = reportLinkText;
                a.title = 'Report animal abuse to authorities or NGOs';
                    a.title = 'Report animal abuse to authorities or NGOs';


                li.appendChild(a);
                    li.appendChild(a);
                personalMenu.insertBefore(li, loginItem);
                    personalMenu.appendChild(li);
 
                    console.log('[ReportAbuseLink] Link inserted at the end of personal menu.');
                }
                 return true;
                 return true;
             } else if (personalMenu && attempts >= maxAttempts) {
             }
                console.log('[ReportAbuseLink] Login item not found after max attempts. Appending to end.');
                const li = document.createElement('li');
                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);
            if (attempts >= maxAttempts) {
                 personalMenu.appendChild(li);
                 console.warn('[ReportAbuseLink] Failed to find personal menu after max attempts.');
                 return true;
                 return true;
             }
             }
Line 46: Line 40:
         const interval = setInterval(function () {
         const interval = setInterval(function () {
             attempts++;
             attempts++;
             if (tryInsert() || attempts >= maxAttempts) {
             if (tryInsert()) {
                 clearInterval(interval);
                 clearInterval(interval);
                 console.log('[ReportAbuseLink] Done.');
                 console.log('[ReportAbuseLink] Done.');

Revision as of 04:56, 21 April 2025

$(function () {
    mw.loader.using('mediawiki.util').then(function () {
        console.log('[ReportAbuseLink] Starting...');

        const reportLinkText = '🐾 Report Abuse';
        const reportPageURL = mw.util.getUrl('Report_Animal_Abuse'); // Update if needed

        let attempts = 0;
        const maxAttempts = 50;

        const tryInsert = function () {
            const personalMenu = document.querySelector('#p-personal ul.vector-menu-content-list');

            if (personalMenu) {
                if (!document.getElementById('pt-reportabuse')) {
                    const li = document.createElement('li');
                    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;
        };

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