Jump to content

MediaWiki:Common.js

From Artemis Archive
Revision as of 04:56, 21 April 2025 by Bxuwd (talk | contribs)

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] 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);
    });
});